Skip to content

Commit a6fce54

Browse files
committed
Condense algorithm selection
1 parent 2c1b114 commit a6fce54

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

src/algorithms.jl

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,26 @@ function select_algorithm(f::F, A, alg::Alg=nothing; kwargs...) where {F,Alg}
8080
return select_algorithm(f, typeof(A), alg; kwargs...)
8181
end
8282
function select_algorithm(f::F, ::Type{A}, alg::Alg=nothing; kwargs...) where {F,A,Alg}
83-
return _select_algorithm(f, A, alg; kwargs...)
84-
end
83+
if isnothing(alg)
84+
return default_algorithm(f, A; kwargs...)
85+
elseif alg isa Symbol
86+
return Algorithm{alg}(; kwargs...)
87+
elseif alg isa Type
88+
return alg(; kwargs...)
89+
elseif alg isa NamedTuple
90+
isempty(kwargs) ||
91+
throw(ArgumentError("Additional keyword arguments are not allowed when algorithm parameters are specified."))
92+
return default_algorithm(f, A; alg...)
93+
elseif alg isa AbstractAlgorithm
94+
isempty(kwargs) ||
95+
throw(ArgumentError("Additional keyword arguments are not allowed when algorithm parameters are specified."))
96+
return alg
97+
end
8598

86-
function _select_algorithm(f::F, ::Type{A}, alg::Nothing; kwargs...) where {F,A}
87-
return default_algorithm(f, A; kwargs...)
88-
end
89-
function _select_algorithm(f::F, ::Type{A}, alg::Symbol; kwargs...) where {F,A}
90-
return Algorithm{alg}(; kwargs...)
91-
end
92-
function _select_algorithm(f::F, ::Type{A}, ::Type{Alg}; kwargs...) where {F,A,Alg}
93-
return Alg(; kwargs...)
94-
end
95-
function _select_algorithm(f::F, ::Type{A}, alg::NamedTuple; kwargs...) where {F,A}
96-
isempty(kwargs) ||
97-
throw(ArgumentError("Additional keyword arguments are not allowed when algorithm parameters are specified."))
98-
return default_algorithm(f, A; alg...)
99-
end
100-
function _select_algorithm(f::F, ::Type{A}, alg::AbstractAlgorithm; kwargs...) where {F,A}
101-
isempty(kwargs) ||
102-
throw(ArgumentError("Additional keyword arguments are not allowed when an algorithm is specified."))
103-
return alg
104-
end
105-
function _select_algorithm(f::F, ::Type{A}, alg; kwargs...) where {F,A}
106-
return throw(ArgumentError("Unknown alg $alg"))
99+
throw(ArgumentError("Unknown alg $alg"))
107100
end
108101

102+
109103
@doc """
110104
MatrixAlgebraKit.default_algorithm(f, A; kwargs...)
111105
MatrixAlgebraKit.default_algorithm(f, ::Type{TA}; kwargs...) where {TA}

0 commit comments

Comments
 (0)