-
Notifications
You must be signed in to change notification settings - Fork 2
Approximator Abstract Type: Selector #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nathanielpritchard
wants to merge
12
commits into
main
Choose a base branch
from
v0.2-selector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
30b1dd2
added abstract types for CUR
nathanielpritchard 006379a
added selector abstract types
nathanielpritchard 9a00dad
adding forgotten selectors markdown
nathanielpritchard 99b004e
added code for an LU with partial pivoting selector
nathanielpritchard fb81e89
fastforwarded with main
nathanielpritchard 0a55ffb
Merge branch 'v0.2-null_compressor' into v0.2-selector
nathanielpritchard 94ffc2f
modified compressor to allow for sketched LU
nathanielpritchard 7c1757c
appropriately named selector directory
nathanielpritchard 30b0a3a
corrected misspecified link
nathanielpritchard 7edf267
corrected terminology in documentation
nathanielpritchard c7e27a0
merged with main
nathanielpritchard 2ec0fd6
corrected typos and added update_compressor test
nathanielpritchard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Selectors | ||
| ```@contents | ||
| Pages = ["selectors.md"] | ||
| ``` | ||
|
|
||
| ## Abstract Types | ||
| ```@docs | ||
| Selector | ||
|
|
||
| SelectorRecipe | ||
| ``` | ||
|
|
||
| ## Selector Structures | ||
| ```@docs | ||
| RLinearAlgebra.LUPP | ||
|
|
||
| LUPPRecipe | ||
|
|
||
| ``` | ||
|
|
||
| ## Exported Functions | ||
| ```@docs | ||
| complete_selector | ||
|
|
||
| update_selector! | ||
|
|
||
| select_indices! | ||
| ``` | ||
|
|
||
| ## Internal Functions | ||
| ```@docs | ||
|
|
||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| ################################### | ||
| # Abstract Types | ||
| ################################### | ||
| """ | ||
| Selector | ||
| An abstract type containing user controlled parameters for a technique that select indices | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from a matrix. | ||
| """ | ||
| abstract type Selector end | ||
|
|
||
| """ | ||
| SelectorRecipe | ||
| An abstract type containing user controlled parameters and preallocated memory for a | ||
| technique that selects indices from matrix. | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| abstract type SelectorRecipe end | ||
|
|
||
| select_arg_list = Dict{Symbol,String}( | ||
| :selector => "`selector::Selector`, a data structure containing the user-defined | ||
| parameters associated with a particular selection method.", | ||
| :selector_recipe => "`selector_recipe::SelectorRecipe`, a fully initialized realization | ||
| for a selector method for a particular matrix.", | ||
| :idx => "`idx::vector`, a vector where selected indices will be placed.", | ||
| :n_idx => "`n_idx::Int64`, the number of indices to be selected.", | ||
| :start_idx => "`start_idx::Int64`. the starting location in `idx` where the indices | ||
| will be placed.", | ||
| :A => "`A::AbstractMatrix`, a target matrix for approximation.", | ||
| ) | ||
| select_output_list = Dict{Symbol,String}( | ||
| :selector_recipe => "A `SelectorRecipe` object.", | ||
| ) | ||
| select_method_description = Dict{Symbol,String}( | ||
| :update_selector => "A function that updates the `SelectorRecipe` in place given the | ||
| arguments.", | ||
| :complete_selector => "A function that generates a `SelectorRecipe` given | ||
| arguments.", | ||
| :select_indices => "A function that selects indices from a matrix `A` using a specific | ||
| `SelectorRecipe`. It updates the vector `idx` in place with `n_idx` new indices starting | ||
| at index `start_idx`." | ||
| ) | ||
| ################################## | ||
| # Complete Selector Interface | ||
| ################################## | ||
| """ | ||
| complete_selector(selector::Selector, A::AbstractMatrix) | ||
| $(select_method_description[:complete_selector]) | ||
| # Arguments | ||
| - $(select_arg_list[:selector]) | ||
| - $(select_arg_list[:A]) | ||
| # Outputs | ||
| - $(select_output_list[:selector_recipe]) | ||
| """ | ||
| function complete_selector(selector::Selector, A::AbstractMatrix) | ||
| return throw( | ||
| ArgumentError( | ||
| "No method `complete_selector` exists for selector of type\ | ||
| $(typeof(selector)) and matrix of type $(typeof(A))." | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| ################################## | ||
| # update_selector! | ||
| ################################## | ||
| """ | ||
| update_selector!(selector::SelectorRecipe) | ||
| $(select_method_description[:update_selector]) | ||
| # Arguments | ||
| - $(select_arg_list[:selector_recipe]) | ||
| # Outputs | ||
| - $(select_output_list[:selector_recipe]) | ||
| """ | ||
| function update_selector!(selector::SelectorRecipe) | ||
| return throw( | ||
| ArgumentError( | ||
| "No method `update_selector!` exists for selector of type\ | ||
| $(typeof(selector))." | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| """ | ||
| update_selector!(selector::SelectorRecipe, A::AbstractMatrix) | ||
| $(select_method_description[:update_selector]) | ||
| # Arguments | ||
| - $(select_arg_list[:selector_recipe]) | ||
| - $(select_arg_list[:A]) | ||
| # Outputs | ||
| - $(select_output_list[:selector_recipe]) | ||
| """ | ||
| function update_selector!(selector::SelectorRecipe, A::AbstractMatrix) | ||
| return update_selector!(selector) | ||
| end | ||
|
|
||
| #################################### | ||
| # select_indices! | ||
| #################################### | ||
| """ | ||
| select_indices!( | ||
| selector::SelectorRecipe, | ||
| A::AbstractMatrix, | ||
| idx::AbstractVector, | ||
| n_idx::Int64, | ||
| start_idx::Int64 | ||
| ) | ||
| $(select_method_description[:select_indices]) | ||
| # Arguments | ||
| - $(select_arg_list[:selector_recipe]) | ||
| - $(select_arg_list[:A]) | ||
| - $(select_arg_list[:idx]) | ||
| - $(select_arg_list[:n_idx]) | ||
| - $(select_arg_list[:start_idx]) | ||
nathanielpritchard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Outputs | ||
| - Returns `nothing` | ||
| """ | ||
| function select_indices!( | ||
| idx::AbstractVector, | ||
| selector::SelectorRecipe, | ||
| A::AbstractMatrix, | ||
| n_idx::Int64, | ||
| start_idx::Int64 | ||
| ) | ||
| return throw( | ||
| ArgumentError( | ||
| "No method `select_indices` exists for selector of type $(typeof(selector)),\ | ||
| matrix of type $(typeof(A)), idx of type $(typeof(idx)), n_idx of type \ | ||
| $(typeof(n_idx)), and start_idx of type $(typeof(start_idx))." | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| # Include the selector files | ||
| include("Selectors/lupp.jl") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| """ | ||
| LUPP <: Selector | ||
| A `Selector` that implements LU with partial pivoting for selecting column indices from a | ||
| matrix. | ||
| # Fields | ||
| - `compressor::Compressor`, the compression technique that will applied to the matrix, | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| before selecting indices. | ||
| # Constructor | ||
| LUPP(;compressor = Identity()) | ||
| ## Keywords | ||
| - `compressor::Compressor`, the compression technique that will applied to the matrix, | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| before selecting indices. Defaults the `Identity` compressor. | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Returns | ||
| - Will return a `LUPP` object. | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| mutable struct LUPP <: Selector | ||
| compressor::Compressor | ||
| end | ||
|
|
||
| function LUPP(;compressor = Identity()) | ||
| LUPP(compressor) | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| """ | ||
| LUPPRecipe <: SelectorRecipe | ||
| A `SelectorRecipe` that contains all the necessary preallocations for selecting column | ||
| indices from a matrix using LU with partial pivoting. | ||
nathanielpritchard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Fields | ||
| - `compressor::Compressor`, the compression technique that will applied to the matrix, | ||
nathanielpritchard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| before selecting indices. | ||
| - `SA::AbstractMatrix`, a buffer matrix for storing the sketched matrix. | ||
| """ | ||
| mutable struct LUPPRecipe <: SelectorRecipe | ||
| compressor::CompressorRecipe | ||
| SA::AbstractMatrix | ||
| end | ||
|
|
||
| function complete_selector(ingredients::LUPP, A::AbstractMatrix) | ||
| compressor = complete_compressor(ingredients.compressor, A) | ||
| n_rows, n_cols = size(compressor) | ||
| SA = Matrix{eltype(A)}(undef, n_rows, n_cols) | ||
| return LUPPRecipe(compressor, SA) | ||
| end | ||
|
|
||
| function update_selector!(selector::LUPPRecipe) | ||
| update_compressor!(selector.compressor) | ||
| return nothing | ||
| end | ||
|
|
||
| function select_indices!( | ||
| idx::AbstractVector, | ||
| selector::LUPPRecipe, | ||
| A::AbstractMatrix, | ||
| n_idx::Int64, | ||
| start_idx::Int64 | ||
| ) | ||
| if n_idx > size(A, 2) | ||
| throw( | ||
| DimensionMismatch( | ||
| "`n_idx` cannot be larger than the number of columns in `A`." | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| if start_idx + n_idx - 1 > size(idx, 1) | ||
| throw( | ||
| DimensionMismatch( | ||
| "`start_idx` + `n_idx` - 1 cannot be larger than the lenght of `idx`." | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| if n_idx > selector.compressor.n_rows | ||
| throw( | ||
| DimensionMismatch( | ||
| "Must select fewer indices then the `compression_dim`." | ||
| ) | ||
| ) | ||
|
|
||
| end | ||
|
|
||
| mul!(selector.SA, selector.compressor, A) | ||
| # because LUPP selects rows and selectors select columns we need to pivot on A' | ||
| p = lu!(selector.SA').p | ||
| idx[start_idx:start_idx + n_idx - 1] = p[1:n_idx] | ||
| return nothing | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.