Skip to content

Commit

Permalink
Merge pull request #508 from termi-official/do/retcodes
Browse files Browse the repository at this point in the history
Fix returncodes and stats for iterative solvers
  • Loading branch information
ChrisRackauckas authored Jun 6, 2024
2 parents 175a74f + 2e44544 commit 765985d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
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

0 comments on commit 765985d

Please sign in to comment.