Skip to content

Commit ae5c68d

Browse files
Fix retcodes on staticarray overloads
Fixes #633
1 parent 47c4060 commit ae5c68d

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/common.jl

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,8 @@ end
309309

310310
function SciMLBase.solve(prob::StaticLinearProblem,
311311
alg::Nothing, args...; kwargs...)
312-
if alg === nothing || alg isa DirectLdiv!
313-
u = prob.A \ prob.b
314-
elseif alg isa LUFactorization
315-
u = lu(prob.A) \ prob.b
316-
elseif alg isa QRFactorization
317-
u = qr(prob.A) \ prob.b
318-
elseif alg isa CholeskyFactorization
319-
u = cholesky(prob.A) \ prob.b
320-
elseif alg isa NormalCholeskyFactorization
321-
u = cholesky(Symmetric(prob.A' * prob.A)) \ (prob.A' * prob.b)
322-
elseif alg isa SVDFactorization
323-
u = svd(prob.A) \ prob.b
324-
else
325-
# Slower Path but handles all cases
326-
cache = init(prob, alg, args...; kwargs...)
327-
return solve!(cache)
328-
end
329-
return SciMLBase.build_linear_solution(alg, u, nothing, prob)
312+
u = prob.A \ prob.b
313+
return SciMLBase.build_linear_solution(alg, u, nothing, prob; retcode = ReturnCode.Success)
330314
end
331315

332316
function SciMLBase.solve(prob::StaticLinearProblem,
@@ -348,5 +332,5 @@ function SciMLBase.solve(prob::StaticLinearProblem,
348332
cache = init(prob, alg, args...; kwargs...)
349333
return solve!(cache)
350334
end
351-
return SciMLBase.build_linear_solution(alg, u, nothing, prob)
335+
return SciMLBase.build_linear_solution(alg, u, nothing, prob; retcode = ReturnCode.Success)
352336
end

test/retcodes.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,26 @@ rankdeficientalgs = (
6969
@test SciMLBase.successful_retcode(sol.retcode)
7070
end
7171
end
72+
73+
staticarrayalgs = (
74+
DirectLdiv!(),
75+
LUFactorization(),
76+
CholeskyFactorization(),
77+
NormalCholeskyFactorization(),
78+
SVDFactorization()
79+
)
80+
@testset "StaticArray Success" begin
81+
A = Float64[1 2 3; 4 3.5 1.7; 5.2 1.8 9.7]
82+
A = A*A'
83+
b = Float64[2, 5, 8]
84+
prob1 = LinearProblem(SMatrix{3, 3}(A), SVector{3}(b))
85+
sol = solve(prob1)
86+
@test SciMLBase.successful_retcode(sol.retcode)
87+
88+
for alg in staticarrayalgs
89+
sol = solve(prob1, alg)
90+
@test SciMLBase.successful_retcode(sol.retcode)
91+
end
92+
93+
@test_broken sol = solve(prob1, QRFactorization()) # Needs StaticArrays `qr` fix
94+
end

0 commit comments

Comments
 (0)