Skip to content

Commit

Permalink
Add backslash method specialized for SparseMatrixCSCs and a test ch…
Browse files Browse the repository at this point in the history
…ecking that that specialized method gets called, a simple if inelegant fix for #16548.
  • Loading branch information
Sacha0 committed Jun 17, 2016
1 parent 7ad5eee commit fb0e617
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,32 @@ end
scale!(A::SparseMatrixCSC, b::Number) = (scale!(A.nzval, b); A)
scale!(b::Number, A::SparseMatrixCSC) = (scale!(b, A.nzval); A)

function (\)(A::SparseMatrixCSC, B::AbstractVecOrMat)
m, n = size(A)
if m == n
if istril(A)
if istriu(A)
return Diagonal(A) \ B
else
return LowerTriangular(A) \ B
end
elseif istriu(A)
return UpperTriangular(A) \ B
end
if ishermitian(A)
try
return cholfact(Hermitian(A)) \ B
catch e
isa(e, PosDefException) || rethrow(e)
return ldltfact(Hermitian(A)) \ B
end
end
return lufact(A) \ B
else
return qrfact(A) \ B
end
end

function factorize(A::SparseMatrixCSC)
m, n = size(A)
if m == n
Expand Down
3 changes: 3 additions & 0 deletions test/sparsedir/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1385,3 +1385,6 @@ end
@test !issparse([rand(10,10) rand(10,10)])
@test !issparse([rand(10,10); rand(10,10)])
@test !issparse([rand(10,10) rand(10,10); rand(10,10) rand(10,10)])

# Test temporary fix for issue #16548 in PR #16979. Brittle. Expect to remove with `\` revisions.
@test which(\, (SparseMatrixCSC, AbstractVecOrMat)).module == Base.SparseArrays

0 comments on commit fb0e617

Please sign in to comment.