Skip to content
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

Fix returncodes and stats for iterative solvers #508

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/iterative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,5 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
end

return SciMLBase.build_linear_solution(alg, cache.u, resid, cache;
iters = stats.niter)
iters = stats.niter, retcode, stats)
end
46 changes: 46 additions & 0 deletions test/retcodes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using LinearSolve

alglist = (
LUFactorization,
QRFactorization,
DiagonalFactorization,
DirectLdiv!,
SparspakFactorization,
KLUFactorization,
UMFPACKFactorization,
KrylovJL_GMRES,
GenericLUFactorization,
RFLUFactorization,
LDLtFactorization,
BunchKaufmanFactorization,
CHOLMODFactorization,
SVDFactorization,
CholeskyFactorization,
NormalCholeskyFactorization,
AppleAccelerateLUFactorization,
MKLLUFactorization,
KrylovJL_CRAIGMR,
KrylovJL_LSMR,
)

@testset "Success" begin
for alg in alglist
A = [2.0 1.0; -1.0 1.0]
b = [-1.0, 1.0]
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...
end
end

@testset "Failure" begin
for alg in alglist
A = [1.0 1.0; 1.0 1.0]
b = [-1.0, 1.0]
prob = LinearProblem(A, b)
linsolve = init(prob, alg)
sol = solve!(linsolve)
@test !SciMLBase.successful_retcode(sol.retcode)
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const HAS_EXTENSIONS = isdefined(Base, :get_extension)
if GROUP == "All" || GROUP == "Core"
@time @safetestset "Quality Assurance" include("qa.jl")
@time @safetestset "Basic Tests" include("basictests.jl")
@time @safetestset "Return codes" include("retcodes.jl")
@time @safetestset "Re-solve" include("resolve.jl")
@time @safetestset "Zero Initialization Tests" include("zeroinittests.jl")
@time @safetestset "Non-Square Tests" include("nonsquare.jl")
Expand Down
Loading