Skip to content

Commit

Permalink
Add inference check
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Dec 11, 2023
1 parent cc65daa commit 3c56ab4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ function __init_u0_from_Ab(A, b)
fill!(u0, false)
return u0
end
function __init_u0_from_Ab(A::SMatrix{S1, S2}, b) where {S1, S2}
return zeros(SVector{S2, eltype(b)})
end
__init_u0_from_Ab(::SMatrix{S1, S2}, b) where {S1, S2} = zeros(SVector{S2, eltype(b)})

Check warning on line 127 in src/common.jl

View check run for this annotation

Codecov / codecov/patch

src/common.jl#L127

Added line #L127 was not covered by tests

function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
args...;
Expand Down
4 changes: 0 additions & 4 deletions src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ end
function init_cacheval(alg::CholeskyFactorization, A::SMatrix{S1, S2}, b, u, Pl, Pr,
maxiters::Int, abstol, reltol, verbose::Bool,
assumptions::OperatorAssumptions) where {S1, S2}
# StaticArrays doesn't have the pivot argument. Prevent generic fallback.
# CholeskyFactorization is part of DefaultLinearSolver, so it is possible that `A` is
# not Hermitian.
(!issquare(A) || !ishermitian(A)) && return nothing
cholesky(A)
end

Expand Down
4 changes: 3 additions & 1 deletion src/iterative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)

# Copy the solution to the allocated output vector
cacheval = @get_cacheval(cache, :KrylovJL_GMRES)
if cache.u !== cacheval.x
if cache.u !== cacheval.x && ArrayInterface.can_setindex(cache.u)
cache.u .= cacheval.x
else
cache.u = convert(typeof(cache.u), cacheval.x)
end

return SciMLBase.build_linear_solution(alg, cache.u, resid, cache;
Expand Down
3 changes: 3 additions & 0 deletions test/static_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ b = SVector{5}(rand(5))
for alg in (nothing, LUFactorization(), SVDFactorization(), CholeskyFactorization(),
KrylovJL_GMRES())
sol = solve(LinearProblem(A, b), alg)
@inferred solve(LinearProblem(A, b), alg)
@test norm(A * sol .- b) < 1e-10
end

A = SMatrix{7, 5}(rand(7, 5))
b = SVector{7}(rand(7))

for alg in (nothing, SVDFactorization(), KrylovJL_LSMR())
@inferred solve(LinearProblem(A, b), alg)
@test_nowarn solve(LinearProblem(A, b), alg)
end

A = SMatrix{5, 7}(rand(5, 7))
b = SVector{5}(rand(5))

for alg in (nothing, SVDFactorization(), KrylovJL_LSMR())
@inferred solve(LinearProblem(A, b), alg)
@test_nowarn solve(LinearProblem(A, b), alg)
end

0 comments on commit 3c56ab4

Please sign in to comment.