Dense .+ sparse -> sparse?

I find this counterintuitive:

julia> using SparseArrays

julia> A=rand(100,100);

julia> B=sprand(100,100,0.01);

julia> typeof(A + B)
Array{Float64,2}

julia> typeof(A .+ B)
SparseMatrixCSC{Float64,Int64}

I would have expected the result to be dense. What is the rationale?

3 Likes

Seems like a bug to me. Anything that is guaranteed to generate a sparse matrix with all structural non-zeros is pointless and should just produce a dense matrix.

4 Likes

Thanks, I’ll open an issue then. Done here.

5 Likes