|
10 | 10 |
|
11 | 11 | _ldiv!(x, A, b) = ldiv!(x, A, b)
|
12 | 12 |
|
| 13 | +_ldiv!(x, A, b::SVector) = (x .= A \ b) |
| 14 | +_ldiv!(::SVector, A, b::SVector) = (A \ b) |
| 15 | +_ldiv!(::SVector, A, b) = (A \ b) |
| 16 | + |
13 | 17 | function _ldiv!(x::Vector, A::Factorization, b::Vector)
|
14 | 18 | # workaround https://github.com/JuliaLang/julia/issues/43507
|
15 | 19 | # Fallback if working with non-square matrices
|
@@ -74,6 +78,8 @@ function do_factorization(alg::LUFactorization, A, b, u)
|
74 | 78 | if A isa AbstractSparseMatrixCSC
|
75 | 79 | return lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)),
|
76 | 80 | check = false)
|
| 81 | + elseif !ArrayInterface.can_setindex(typeof(A)) |
| 82 | + fact = lu(A, alg.pivot, check = false) |
77 | 83 | else
|
78 | 84 | fact = lu!(A, alg.pivot, check = false)
|
79 | 85 | end
|
@@ -136,10 +142,14 @@ end
|
136 | 142 |
|
137 | 143 | function do_factorization(alg::QRFactorization, A, b, u)
|
138 | 144 | A = convert(AbstractMatrix, A)
|
139 |
| - if alg.inplace && !(A isa SparseMatrixCSC) && !(A isa GPUArraysCore.AbstractGPUArray) |
140 |
| - fact = qr!(A, alg.pivot) |
| 145 | + if ArrayInterface.can_setindex(typeof(A)) |
| 146 | + if alg.inplace && !(A isa SparseMatrixCSC) && !(A isa GPUArraysCore.AbstractGPUArray) |
| 147 | + fact = qr!(A, alg.pivot) |
| 148 | + else |
| 149 | + fact = qr(A) # CUDA.jl does not allow other args! |
| 150 | + end |
141 | 151 | else
|
142 |
| - fact = qr(A) # CUDA.jl does not allow other args! |
| 152 | + fact = qr(A, alg.pivot) |
143 | 153 | end
|
144 | 154 | return fact
|
145 | 155 | end
|
@@ -202,6 +212,16 @@ function do_factorization(alg::CholeskyFactorization, A, b, u)
|
202 | 212 | return fact
|
203 | 213 | end
|
204 | 214 |
|
| 215 | +function init_cacheval(alg::CholeskyFactorization, A::SMatrix{S1, S2}, b, u, Pl, Pr, |
| 216 | + maxiters::Int, abstol, reltol, verbose::Bool, |
| 217 | + 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 |
| 222 | + cholesky(A) |
| 223 | +end |
| 224 | + |
205 | 225 | function init_cacheval(alg::CholeskyFactorization, A, b, u, Pl, Pr,
|
206 | 226 | maxiters::Int, abstol, reltol, verbose::Bool,
|
207 | 227 | assumptions::OperatorAssumptions)
|
@@ -276,11 +296,15 @@ SVDFactorization() = SVDFactorization(false, LinearAlgebra.DivideAndConquer())
|
276 | 296 |
|
277 | 297 | function do_factorization(alg::SVDFactorization, A, b, u)
|
278 | 298 | A = convert(AbstractMatrix, A)
|
279 |
| - fact = svd!(A; full = alg.full, alg = alg.alg) |
| 299 | + if ArrayInterface.can_setindex(typeof(A)) |
| 300 | + fact = svd!(A; alg.full, alg.alg) |
| 301 | + else |
| 302 | + fact = svd(A; alg.full) |
| 303 | + end |
280 | 304 | return fact
|
281 | 305 | end
|
282 | 306 |
|
283 |
| -function init_cacheval(alg::SVDFactorization, A::Matrix, b, u, Pl, Pr, |
| 307 | +function init_cacheval(alg::SVDFactorization, A::Union{Matrix, SMatrix}, b, u, Pl, Pr, |
284 | 308 | maxiters::Int, abstol, reltol, verbose::Bool,
|
285 | 309 | assumptions::OperatorAssumptions)
|
286 | 310 | ArrayInterface.svd_instance(convert(AbstractMatrix, A))
|
|
882 | 906 | function init_cacheval(alg::NormalCholeskyFactorization, A, b, u, Pl, Pr,
|
883 | 907 | maxiters::Int, abstol, reltol, verbose::Bool,
|
884 | 908 | assumptions::OperatorAssumptions)
|
885 |
| - ArrayInterface.cholesky_instance(convert(AbstractMatrix, A), alg.pivot) |
| 909 | + A_ = convert(AbstractMatrix, A) |
| 910 | + ArrayInterface.cholesky_instance(Symmetric((A)' * A, :L), alg.pivot) |
886 | 911 | end
|
887 | 912 |
|
888 | 913 | function init_cacheval(alg::NormalCholeskyFactorization,
|
@@ -1128,6 +1153,11 @@ function init_cacheval(::SparspakFactorization, A, b, u, Pl, Pr, maxiters::Int,
|
1128 | 1153 | end
|
1129 | 1154 | end
|
1130 | 1155 |
|
| 1156 | +function init_cacheval(::SparspakFactorization, ::StaticArray, b, u, Pl, Pr, |
| 1157 | + maxiters::Int, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) |
| 1158 | + nothing |
| 1159 | +end |
| 1160 | + |
1131 | 1161 | function SciMLBase.solve!(cache::LinearCache, alg::SparspakFactorization; kwargs...)
|
1132 | 1162 | A = cache.A
|
1133 | 1163 | if cache.isfresh
|
|
0 commit comments