SparseArrays.jl icon indicating copy to clipboard operation
SparseArrays.jl copied to clipboard

Elementwise multiplication by a view of a dense matrix gives a dense matrix

Open LorenzoFioroni opened this issue 1 year ago • 0 comments

When a sparse matrix is multiplied elementwise by a dense one, the result remains sparse. I expect the same to happen when the sparse matrix is multiplied by an NxN view of a larger array. However, this does not seem to be the case.

Here is a minimal example:

using SparseArrays

A = sprand(10, 10, 0.1)           # 10x10 sparse matrix
B = rand(10, 10, 10)              # big dense array

C = B[:, :, 1]                    # 10x10 dense matrix
C_view = view(B, :, :, 1)         # 10x10 view of B

println(typeof(A .* C))        # Output: SparseMatrixCSC{Float64, Int64}
println(typeof(A .* C_view))   # Output: Matrix{Float64}

I am using julia v1.10.0 and SparseArrays v1.10.0

LorenzoFioroni avatar Feb 07 '24 14:02 LorenzoFioroni