-
Notifications
You must be signed in to change notification settings - Fork 6
Refactor algorithm selection logic #23
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
Changes from 5 commits
f878a6f
df79819
c019191
fc04a1b
cabd897
430e91b
0b96418
3b47ceb
3073fa2
7dff266
df4b2b8
73922e6
44bd9f1
c6a85ef
81185a4
a44245e
92abea3
36725dd
fb94ad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,17 +56,54 @@ | |
| @doc """ | ||
| select_algorithm(f, A; kwargs...) | ||
|
|
||
| Given some keyword arguments and an input `A`, decide on an algrithm to use for | ||
| Given some keyword arguments and an input `A`, decide on an algorithm to use for | ||
| implementing the function `f` on inputs of type `A`. | ||
|
|
||
| In general, if an algorithm is specified explicitly through the `alg` keyword argument | ||
| (either as an algorithm type, an algorithm name as a Symbol, or as an algorithm object), | ||
| that algorithm will be used instead of selecting it automatically. However, that | ||
| behavior may be modified for factorization functions and/or matrix types. | ||
|
|
||
| In general, if the algorithm is not specified, a default algorithm specified by | ||
|
mtfishman marked this conversation as resolved.
Outdated
|
||
| [`default_algorithm`](@ref) will be used. | ||
| """ | ||
| function select_algorithm end | ||
|
|
||
| function _select_algorithm(f, A::AbstractMatrix, alg::AbstractAlgorithm) | ||
| function select_algorithm(f, A; alg=nothing, kwargs...) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure using multiple dispatch via function select_algorithm(f, A; alg=nothing, kwargs...)
if isnothing(alg)
return default_algorithm(f, A; kwargs...)
elseif alg isa AbstractAlgorithm
isempty(kwargs) ||
throw(ArgumentError("Additional keyword arguments are not allowed when an algorithm is specified."))
return alg
elseif
...
end
endshould work. Or does the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm totally fine with that, using dispatch was a bit arbitrary. I generally like using dispatch rather than if-statements purely as a style thing, but if you and the compiler prefer if-statements I can switch to that.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying this out locally, an unfortunate side affect of this is that functions like I'll investigate that more. But maybe it would be better to just change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the |
||
| return _select_algorithm(f, A, alg; kwargs...) | ||
| end | ||
|
|
||
| function _select_algorithm(f, A, alg::Nothing; kwargs...) | ||
| return default_algorithm(f, A; kwargs...) | ||
| end | ||
| function _select_algorithm(f, A, alg::AbstractAlgorithm; kwargs...) | ||
| isempty(kwargs) || | ||
| throw(ArgumentError("Additional keyword arguments are not allowed when an algorithm is specified.")) | ||
| return alg | ||
| end | ||
| function _select_algorithm(f, A::AbstractMatrix, alg::NamedTuple) | ||
| function _select_algorithm(f, A, alg::Symbol; kwargs...) | ||
| return _select_algorithm(f, A, Algorithm{alg}; kwargs...) | ||
|
mtfishman marked this conversation as resolved.
Outdated
|
||
| end | ||
| function _select_algorithm(f, A, alg::Type; kwargs...) | ||
| return _select_algorithm(f, A, alg(; kwargs...)) | ||
| end | ||
| function _select_algorithm(f, A::AbstractMatrix, alg::NamedTuple; kwargs...) | ||
| isempty(kwargs) || | ||
| throw(ArgumentError("Additional keyword arguments are not allowed when algorithm parameters are specified.")) | ||
| return select_algorithm(f, A; alg...) | ||
| end | ||
| function _select_algorithm(f, A, alg; kwargs...) | ||
| return throw(ArgumentError("Unknown alg $alg")) | ||
| end | ||
|
|
||
| @doc """ | ||
| default_algorithm(f, A; kwargs...) | ||
|
|
||
| Select the default algorithm for a given factorization function `f` and input `A`. | ||
| In general, this is called by [`select_algorithm`](@ref) if no algorithm is specified | ||
| explicitly. | ||
| """ | ||
| function default_algorithm end | ||
|
|
||
| @doc """ | ||
| copy_input(f, A) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.