Skip to content

Commit 3260599

Browse files
committed
Add tests for StaticArrays
1 parent 12fbcef commit 3260599

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/default.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function defaultalg(A, b, assump::OperatorAssumptions)
192192
DefaultAlgorithmChoice.NormalCholeskyFactorization
193193
elseif A isa StaticArray
194194
# Static Array doesn't have QR() \ b defined
195-
return DefaultAlgorithmChoice.SVDFactorization
195+
DefaultAlgorithmChoice.SVDFactorization
196196
elseif assump.condition === OperatorCondition.IllConditioned
197197
if is_underdetermined(A)
198198
# Underdetermined

src/factorization.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ _ldiv!(x, A, b) = ldiv!(x, A, b)
1212

1313
_ldiv!(x, A, b::SVector) = (x .= A \ b)
1414
_ldiv!(::SVector, A, b::SVector) = (A \ b)
15+
_ldiv!(::SVector, A, b) = (A \ b)
1516

1617
function _ldiv!(x::Vector, A::Factorization, b::Vector)
1718
# workaround https://github.com/JuliaLang/julia/issues/43507
@@ -288,7 +289,7 @@ end
288289
function init_cacheval(alg::CholeskyFactorization, A::SMatrix, b, u, Pl, Pr,
289290
maxiters::Int, abstol, reltol, verbose::Bool,
290291
assumptions::OperatorAssumptions)
291-
cholesky(A) # StaticArrays doesn't have the pivot argument. Prevent generic fallback.
292+
cholesky(SMatrix{1, 1}(one(eltype(A)))) # StaticArrays doesn't have the pivot argument. Prevent generic fallback.
292293
end
293294

294295
function init_cacheval(alg::CholeskyFactorization, A, b, u, Pl, Pr,
@@ -1060,7 +1061,8 @@ end
10601061
function init_cacheval(alg::NormalCholeskyFactorization, A, b, u, Pl, Pr,
10611062
maxiters::Int, abstol, reltol, verbose::Bool,
10621063
assumptions::OperatorAssumptions)
1063-
ArrayInterface.cholesky_instance(convert(AbstractMatrix, A), alg.pivot)
1064+
A_ = convert(AbstractMatrix, A)
1065+
ArrayInterface.cholesky_instance(Symmetric((A)' * A, :L), alg.pivot)
10641066
end
10651067

10661068
function init_cacheval(alg::NormalCholeskyFactorization,

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if GROUP == "All" || GROUP == "Core"
1717
VERSION >= v"1.9" && @time @safetestset "Enzyme Derivative Rules" include("enzyme.jl")
1818
@time @safetestset "Traits" include("traits.jl")
1919
VERSION >= v"1.9" && @time @safetestset "BandedMatrices" include("banded.jl")
20+
@time @safetestset "Static Arrays" include("static_arrays.jl")
2021
end
2122

2223
if GROUP == "LinearSolveCUDA"

test/static_arrays.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using LinearSolve, StaticArrays, LinearAlgebra
2+
3+
A = SMatrix{5, 5}(Hermitian(rand(5, 5) + I))
4+
b = SVector{5}(rand(5))
5+
6+
for alg in (nothing, LUFactorization(), SVDFactorization(), CholeskyFactorization(),
7+
KrylovJL_GMRES())
8+
sol = solve(LinearProblem(A, b), alg)
9+
@show norm(A * sol .- b)
10+
@test norm(A * sol .- b) < 1e-10
11+
end
12+
13+
A = SMatrix{7, 5}(rand(7, 5))
14+
b = SVector{7}(rand(7))
15+
16+
for alg in (nothing, SVDFactorization(), KrylovJL_LSMR())
17+
@test_nowarn solve(LinearProblem(A, b), alg)
18+
end
19+
20+
A = SMatrix{5, 7}(rand(5, 7))
21+
b = SVector{5}(rand(5))
22+
23+
for alg in (nothing, SVDFactorization(), KrylovJL_LSMR())
24+
@test_nowarn solve(LinearProblem(A, b), alg)
25+
end

0 commit comments

Comments
 (0)