-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add needs_square_A
trait
#400
Changes from 2 commits
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
needs_concrete_A(alg::DefaultLinearSolver) = true | ||
mutable struct DefaultLinearSolverInit{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, | ||
T13, T14, T15, T16, T17, T18} | ||
T13, T14, T15, T16, T17, T18, T19} | ||
LUFactorization::T1 | ||
QRFactorization::T2 | ||
DiagonalFactorization::T3 | ||
|
@@ -19,6 +19,7 @@ mutable struct DefaultLinearSolverInit{T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, | |
NormalCholeskyFactorization::T16 | ||
AppleAccelerateLUFactorization::T17 | ||
MKLLUFactorization::T18 | ||
QRFactorizationPivoted::T19 | ||
end | ||
|
||
# Legacy fallback | ||
|
@@ -168,8 +169,8 @@ function defaultalg(A, b, assump::OperatorAssumptions) | |
(A === nothing ? eltype(b) <: Union{Float32, Float64} : | ||
eltype(A) <: Union{Float32, Float64}) | ||
DefaultAlgorithmChoice.RFLUFactorization | ||
#elseif A === nothing || A isa Matrix | ||
# alg = FastLUFactorization() | ||
#elseif A === nothing || A isa Matrix | ||
# alg = FastLUFactorization() | ||
elseif usemkl && (A === nothing ? eltype(b) <: Union{Float32, Float64} : | ||
eltype(A) <: Union{Float32, Float64}) | ||
DefaultAlgorithmChoice.MKLLUFactorization | ||
|
@@ -199,9 +200,19 @@ function defaultalg(A, b, assump::OperatorAssumptions) | |
elseif assump.condition === OperatorCondition.WellConditioned | ||
DefaultAlgorithmChoice.NormalCholeskyFactorization | ||
elseif assump.condition === OperatorCondition.IllConditioned | ||
DefaultAlgorithmChoice.QRFactorization | ||
if is_underdetermined(A) | ||
# Underdetermined | ||
DefaultAlgorithmChoice.QRFactorizationPivoted | ||
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. QRFactorization is already pivoted? 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. oh I see. @YingboMa what do you think of just always defaulting to pivoted QR? 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. Yeah, pivoted QR handles degenerate systems too. 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. But it's quite a bit slower though. |
||
else | ||
DefaultAlgorithmChoice.QRFactorization | ||
end | ||
elseif assump.condition === OperatorCondition.VeryIllConditioned | ||
DefaultAlgorithmChoice.QRFactorization | ||
if is_underdetermined(A) | ||
# Underdetermined | ||
DefaultAlgorithmChoice.QRFactorizationPivoted | ||
else | ||
DefaultAlgorithmChoice.QRFactorization | ||
end | ||
elseif assump.condition === OperatorCondition.SuperIllConditioned | ||
DefaultAlgorithmChoice.SVDFactorization | ||
else | ||
|
@@ -247,6 +258,12 @@ function algchoice_to_alg(alg::Symbol) | |
NormalCholeskyFactorization() | ||
elseif alg === :AppleAccelerateLUFactorization | ||
AppleAccelerateLUFactorization() | ||
elseif alg === :QRFactorizationPivoted | ||
@static if VERSION ≥ v"1.7beta" | ||
QRFactorization(ColumnNorm()) | ||
else | ||
QRFactorization(Val(true)) | ||
end | ||
else | ||
error("Algorithm choice symbol $alg not allowed in the default") | ||
end | ||
|
@@ -310,6 +327,7 @@ function defaultalg_symbol(::Type{T}) where {T} | |
Symbol(split(string(SciMLBase.parameterless_type(T)), ".")[end]) | ||
end | ||
defaultalg_symbol(::Type{<:GenericFactorization{typeof(ldlt!)}}) = :LDLtFactorization | ||
defaultalg_symbol(::Type{<:QRFactorization{ColumnNorm}}) = :QRFactorizationPivoted | ||
|
||
""" | ||
if alg.alg === DefaultAlgorithmChoice.LUFactorization | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remove the fallback please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or rather, the fallback is true. That's a safe fallback, methods can opt-in to supporting non-square, but anything that supports non-square supports square so that's a safe assumption.