Skip to content

Fix retcodes on staticarray overloads #634

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

Merged
merged 2 commits into from
Jul 15, 2025
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
22 changes: 3 additions & 19 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,24 +309,8 @@ end

function SciMLBase.solve(prob::StaticLinearProblem,
alg::Nothing, args...; kwargs...)
if alg === nothing || alg isa DirectLdiv!
u = prob.A \ prob.b
elseif alg isa LUFactorization
u = lu(prob.A) \ prob.b
elseif alg isa QRFactorization
u = qr(prob.A) \ prob.b
elseif alg isa CholeskyFactorization
u = cholesky(prob.A) \ prob.b
elseif alg isa NormalCholeskyFactorization
u = cholesky(Symmetric(prob.A' * prob.A)) \ (prob.A' * prob.b)
elseif alg isa SVDFactorization
u = svd(prob.A) \ prob.b
else
# Slower Path but handles all cases
cache = init(prob, alg, args...; kwargs...)
return solve!(cache)
end
return SciMLBase.build_linear_solution(alg, u, nothing, prob)
u = prob.A \ prob.b
return SciMLBase.build_linear_solution(alg, u, nothing, prob; retcode = ReturnCode.Success)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return SciMLBase.build_linear_solution(alg, u, nothing, prob; retcode = ReturnCode.Success)
return SciMLBase.build_linear_solution(
alg, u, nothing, prob; retcode = ReturnCode.Success)

end

function SciMLBase.solve(prob::StaticLinearProblem,
Expand All @@ -348,5 +332,5 @@ function SciMLBase.solve(prob::StaticLinearProblem,
cache = init(prob, alg, args...; kwargs...)
return solve!(cache)
end
return SciMLBase.build_linear_solution(alg, u, nothing, prob)
return SciMLBase.build_linear_solution(alg, u, nothing, prob; retcode = ReturnCode.Success)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return SciMLBase.build_linear_solution(alg, u, nothing, prob; retcode = ReturnCode.Success)
return SciMLBase.build_linear_solution(
alg, u, nothing, prob; retcode = ReturnCode.Success)

end
25 changes: 24 additions & 1 deletion test/retcodes.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LinearSolve, LinearAlgebra, RecursiveFactorization, Test
using LinearSolve, LinearAlgebra, RecursiveFactorization, StaticArrays, Test

alglist = (
LUFactorization,
Expand Down Expand Up @@ -69,3 +69,26 @@ rankdeficientalgs = (
@test SciMLBase.successful_retcode(sol.retcode)
end
end

staticarrayalgs = (
DirectLdiv!(),
LUFactorization(),
CholeskyFactorization(),
NormalCholeskyFactorization(),
SVDFactorization()
)
@testset "StaticArray Success" begin
A = Float64[1 2 3; 4 3.5 1.7; 5.2 1.8 9.7]
A = A*A'
b = Float64[2, 5, 8]
prob1 = LinearProblem(SMatrix{3, 3}(A), SVector{3}(b))
sol = solve(prob1)
@test SciMLBase.successful_retcode(sol.retcode)

for alg in staticarrayalgs
sol = solve(prob1, alg)
@test SciMLBase.successful_retcode(sol.retcode)
end

@test_broken sol = solve(prob1, QRFactorization()) # Needs StaticArrays `qr` fix
end
Loading