Skip to content

Commit

Permalink
Merge pull request JuliaLang#16979 from Sacha0/backslashfix
Browse files Browse the repository at this point in the history
Simple but inelegant fix for #16548
  • Loading branch information
vtjnash authored Jun 23, 2016
2 parents bb67bd3 + 0c36fb3 commit fbe6e5a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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
5 changes: 4 additions & 1 deletion test/sparsedir/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1391,4 +1391,7 @@ let m = 5
intmat = fill(1, m, m)
ltintmat = LowerTriangular(rand(1:5, m, m))
@test isapprox(At_ldiv_B(ltintmat, sparse(intmat)), At_ldiv_B(ltintmat, intmat))
end
end

# 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 fbe6e5a

Please sign in to comment.