-
-
Notifications
You must be signed in to change notification settings - Fork 72
Fix successful return codes for factorization methods #631
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 all 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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -150,7 +150,7 @@ function SciMLBase.solve!(cache::LinearCache, alg::LUFactorization; kwargs...) | |||||||
|
||||||||
F = @get_cacheval(cache, :LUFactorization) | ||||||||
y = _ldiv!(cache.u, F, cache.b) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache; retcode = ReturnCode.Success) | ||||||||
end | ||||||||
|
||||||||
function do_factorization(alg::LUFactorization, A, b, u) | ||||||||
|
@@ -203,7 +203,7 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::GenericLUFactoriz | |||||||
cache.isfresh = false | ||||||||
end | ||||||||
y = ldiv!(cache.u, LinearSolve.@get_cacheval(cache, :GenericLUFactorization)[1], cache.b) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache; retcode = ReturnCode.Success) | ||||||||
end | ||||||||
|
||||||||
function init_cacheval( | ||||||||
|
@@ -953,6 +953,12 @@ A fast factorization which uses a Cholesky factorization on A * A'. Can be much | |||||||
faster than LU factorization, but is not as numerically stable and thus should only | ||||||||
be applied to well-conditioned matrices. | ||||||||
|
||||||||
!!! warn | ||||||||
`NormalCholeskyFactorization` should only be applied to well-conditioned matrices. As a | ||||||||
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. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
method it is not able to easily identify possible numerical issues. As a check it is | ||||||||
recommended that the user checks `A*u-b` is approximately zero, as this may be untrue | ||||||||
even if `sol.retcode === ReturnCode.Success` due to numerical stability issues. | ||||||||
|
||||||||
## Positional Arguments | ||||||||
|
||||||||
- pivot: Defaults to RowMaximum(), but can be NoPivot() | ||||||||
|
@@ -1010,6 +1016,12 @@ function SciMLBase.solve!(cache::LinearCache, alg::NormalCholeskyFactorization; | |||||||
fact = cholesky(Symmetric((A)' * A), alg.pivot; check = false) | ||||||||
end | ||||||||
cache.cacheval = fact | ||||||||
|
||||||||
if hasmethod(LinearAlgebra.issuccess, Tuple{typeof(fact)}) && !LinearAlgebra.issuccess(fact) | ||||||||
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. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||
return SciMLBase.build_linear_solution( | ||||||||
alg, cache.u, nothing, cache; retcode = ReturnCode.Failure) | ||||||||
end | ||||||||
|
||||||||
cache.isfresh = false | ||||||||
end | ||||||||
if issparsematrixcsc(A) | ||||||||
|
@@ -1021,7 +1033,7 @@ function SciMLBase.solve!(cache::LinearCache, alg::NormalCholeskyFactorization; | |||||||
else | ||||||||
y = ldiv!(cache.u, @get_cacheval(cache, :NormalCholeskyFactorization), A' * cache.b) | ||||||||
end | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache) | ||||||||
SciMLBase.build_linear_solution(alg, y, nothing, cache; retcode = ReturnCode.Success) | ||||||||
end | ||||||||
|
||||||||
## NormalBunchKaufmanFactorization | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||
using LinearSolve, LinearAlgebra, RecursiveFactorization | ||||||||||
using LinearSolve, LinearAlgebra, RecursiveFactorization, Test | ||||||||||
|
||||||||||
alglist = ( | ||||||||||
LUFactorization, | ||||||||||
|
@@ -19,7 +19,7 @@ alglist = ( | |||||||||
prob = LinearProblem(A, b) | ||||||||||
linsolve = init(prob, alg()) | ||||||||||
sol = solve!(linsolve) | ||||||||||
@test SciMLBase.successful_retcode(sol.retcode) || sol.retcode == ReturnCode.Default # The latter seems off... | ||||||||||
@test SciMLBase.successful_retcode(sol.retcode) | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
|
@@ -39,7 +39,13 @@ lualgs = ( | |||||||||
prob = LinearProblem(A, b) | ||||||||||
linsolve = init(prob, alg) | ||||||||||
sol = solve!(linsolve) | ||||||||||
@test !SciMLBase.successful_retcode(sol.retcode) | ||||||||||
if alg isa NormalCholeskyFactorization | ||||||||||
# This is a known and documented incorrectness in NormalCholeskyFactorization | ||||||||||
# due to numerical instability in its method that is fundamental. | ||||||||||
@test SciMLBase.successful_retcode(sol.retcode) | ||||||||||
Comment on lines
+43
to
+44
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. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
else | ||||||||||
@test !SciMLBase.successful_retcode(sol.retcode) | ||||||||||
end | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
|
@@ -62,4 +68,4 @@ rankdeficientalgs = ( | |||||||||
sol = solve!(linsolve) | ||||||||||
@test SciMLBase.successful_retcode(sol.retcode) | ||||||||||
end | ||||||||||
end | ||||||||||
end |
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.
[JuliaFormatter] reported by reviewdog 🐶