Skip to content

Commit 3c56ab4

Browse files
committed
Add inference check
1 parent cc65daa commit 3c56ab4

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

src/common.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ function __init_u0_from_Ab(A, b)
124124
fill!(u0, false)
125125
return u0
126126
end
127-
function __init_u0_from_Ab(A::SMatrix{S1, S2}, b) where {S1, S2}
128-
return zeros(SVector{S2, eltype(b)})
129-
end
127+
__init_u0_from_Ab(::SMatrix{S1, S2}, b) where {S1, S2} = zeros(SVector{S2, eltype(b)})
130128

131129
function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
132130
args...;

src/factorization.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ end
215215
function init_cacheval(alg::CholeskyFactorization, A::SMatrix{S1, S2}, b, u, Pl, Pr,
216216
maxiters::Int, abstol, reltol, verbose::Bool,
217217
assumptions::OperatorAssumptions) where {S1, S2}
218-
# StaticArrays doesn't have the pivot argument. Prevent generic fallback.
219-
# CholeskyFactorization is part of DefaultLinearSolver, so it is possible that `A` is
220-
# not Hermitian.
221-
(!issquare(A) || !ishermitian(A)) && return nothing
222218
cholesky(A)
223219
end
224220

src/iterative_wrappers.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,10 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
284284

285285
# Copy the solution to the allocated output vector
286286
cacheval = @get_cacheval(cache, :KrylovJL_GMRES)
287-
if cache.u !== cacheval.x
287+
if cache.u !== cacheval.x && ArrayInterface.can_setindex(cache.u)
288288
cache.u .= cacheval.x
289+
else
290+
cache.u = convert(typeof(cache.u), cacheval.x)
289291
end
290292

291293
return SciMLBase.build_linear_solution(alg, cache.u, resid, cache;

test/static_arrays.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ b = SVector{5}(rand(5))
66
for alg in (nothing, LUFactorization(), SVDFactorization(), CholeskyFactorization(),
77
KrylovJL_GMRES())
88
sol = solve(LinearProblem(A, b), alg)
9+
@inferred solve(LinearProblem(A, b), alg)
910
@test norm(A * sol .- b) < 1e-10
1011
end
1112

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

1516
for alg in (nothing, SVDFactorization(), KrylovJL_LSMR())
17+
@inferred solve(LinearProblem(A, b), alg)
1618
@test_nowarn solve(LinearProblem(A, b), alg)
1719
end
1820

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

2224
for alg in (nothing, SVDFactorization(), KrylovJL_LSMR())
25+
@inferred solve(LinearProblem(A, b), alg)
2326
@test_nowarn solve(LinearProblem(A, b), alg)
2427
end

0 commit comments

Comments
 (0)