Sparse arrays "\"

Apparently “A\b” is not fully supported for both A and b being sparse arrays.
using SparseArrays
A=sprand(10,10,0.4)
b=sprand(10,10,0.3)
A\b
ERROR: MethodError: no method matching ldiv!(::SuiteSparse.UMFPACK.UmfpackLU{Float64,Int64}, ::SparseMatrixCSC{Float64,Int64})
Closest candidates are:
ldiv!(::Number, ::AbstractArray) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\generic.jl:152
ldiv!(::LinearAlgebra.LU{T,LinearAlgebra.Tridiagonal{T,V}}, ::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T) where {T, V} at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\lu.jl:523

A\Array(b)
julia> A\Array(b)
10×1 Array{Float64,2}:
-2.975057686758748
1.4647987429262779
0.5383182428619319
-0.8475332612566527
-0.8920771064715199
0.139199739907848
1.198495620310481
-0.733125055450034
-0.2269834237581322
0.3880953759457807

This is the intended behaviour. See the following issue on Github:


The underlying library (Suitesparse) julia uses for factorization of sparse matrices and the direct solution of sparse linear systems does not support sparse right hand sides. If the right hand side b has many columns then converting this to a dense array can cause unacceptably high memory use, so I don’t think it’s a good idea to have the backslash operator do that automatically under the hood.

It might still be good to post an issue asking for a more useful error message in this case. It would be nice if you got a message that said something like “sparse right hand sides not supported” or something like that, rather than the method error.

As a side note, the MUMPS sparse direct solver does support sparse right hand sides. The main julia interface to MUMPS does not expose that support unfortunately. There is an alternative julia MUMPS interface that does support sparse right hand sides but overall it’s not as full featured an interface as the main one.

4 Likes

Ok, thanks for the reply.