Skip to content

Commit 6cbe99d

Browse files
Merge pull request #288 from SciML/sparseview
Fix non-square sparse views
2 parents c83bf11 + 49f8c3b commit 6cbe99d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/factorization.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ function _ldiv!(x::Vector, A::Factorization, b::Vector)
66
ldiv!(A, x)
77
end
88

9+
@static if VERSION >= v"1.9-"
10+
function _ldiv!(x::AbstractVector, A::SparseArrays.SPQR.QRSparse, b::AbstractVector)
11+
x .= A \ b
12+
end
13+
function _ldiv!(x::Vector, A::SparseArrays.SPQR.QRSparse, b::Vector)
14+
x .= A \ b
15+
end
16+
else
17+
function _ldiv!(x::AbstractVector, A::SuiteSparse.SPQR.QRSparse, b::AbstractVector)
18+
x .= A \ b
19+
end
20+
function _ldiv!(x::Vector, A::SuiteSparse.SPQR.QRSparse, b::Vector)
21+
x .= A \ b
22+
end
23+
end
24+
925
function SciMLBase.solve(cache::LinearCache, alg::AbstractFactorization; kwargs...)
1026
if cache.isfresh
1127
fact = do_factorization(alg, cache.A, cache.b, cache.u)

test/nonsquare.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ b = rand(n)
2424
prob = LinearProblem(A, b)
2525
res = Matrix(A) \ b
2626
@test solve(prob, KrylovJL_CRAIGMR()) res
27+
28+
A = sprandn(1000, 100, 0.1)
29+
b = randn(1001)
30+
prob = LinearProblem(A, view(b, 1:1000))
31+
linsolve = init(prob, QRFactorization())
32+
solve(linsolve)

0 commit comments

Comments
 (0)