Skip to content

Commit 8ac858d

Browse files
Fix returncodes and stats for iterative solvers and add test coverage.
1 parent 175a74f commit 8ac858d

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/iterative_wrappers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,5 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
306306
end
307307

308308
return SciMLBase.build_linear_solution(alg, cache.u, resid, cache;
309-
iters = stats.niter)
309+
iters = stats.niter, retcode, stats)
310310
end

test/retcodes.jl

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@testset "Return codes" begin
2+
alglist = (
3+
LUFactorization,
4+
QRFactorization,
5+
DiagonalFactorization,
6+
DirectLdiv!,
7+
SparspakFactorization,
8+
KLUFactorization,
9+
UMFPACKFactorization,
10+
KrylovJL_GMRES,
11+
GenericLUFactorization,
12+
RFLUFactorization,
13+
LDLtFactorization,
14+
BunchKaufmanFactorization,
15+
CHOLMODFactorization,
16+
SVDFactorization,
17+
CholeskyFactorization,
18+
NormalCholeskyFactorization,
19+
AppleAccelerateLUFactorization,
20+
MKLLUFactorization,
21+
KrylovJL_CRAIGMR,
22+
KrylovJL_LSMR,
23+
)
24+
25+
@testset "Success" begin
26+
for alg in alglist
27+
A = [2.0 1.0; -1.0 1.0]
28+
b = [-1.0, 1.0]
29+
prob = LinearProblem(A, b)
30+
linsolve = init(prob, alg)
31+
sol = solve!(linsolve)
32+
@test SciMLBase.successful_retcode(sol.retcode) || sol.retcode == ReturnCode.Default # The latter seems off...
33+
end
34+
end
35+
36+
@testset "Failure" begin
37+
for alg in alglist
38+
A = [1.0 1.0; 1.0 1.0]
39+
b = [-1.0, 1.0]
40+
prob = LinearProblem(A, b)
41+
linsolve = init(prob, alg)
42+
sol = solve!(linsolve)
43+
@test !SciMLBase.successful_retcode(sol.retcode)
44+
end
45+
end
46+
end

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const HAS_EXTENSIONS = isdefined(Base, :get_extension)
99
if GROUP == "All" || GROUP == "Core"
1010
@time @safetestset "Quality Assurance" include("qa.jl")
1111
@time @safetestset "Basic Tests" include("basictests.jl")
12+
@time @safetestset "Return codes" include("retcodes.jl")
1213
@time @safetestset "Re-solve" include("resolve.jl")
1314
@time @safetestset "Zero Initialization Tests" include("zeroinittests.jl")
1415
@time @safetestset "Non-Square Tests" include("nonsquare.jl")

0 commit comments

Comments
 (0)