Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LorenzoFioroni opened this issue Feb 7, 2024 · 0 comments

Comments

@LorenzoFioroni
Copy link

LorenzoFioroni commented Feb 7, 2024

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

@rayegun rayegun changed the title In-place multiplication by a view of a dense matrix gives a dense matrix In-place elementwise multiplication by a view of a dense matrix gives a dense matrix Feb 7, 2024
@rayegun rayegun changed the title In-place elementwise multiplication by a view of a dense matrix gives a dense matrix Elementwise multiplication by a view of a dense matrix gives a dense matrix Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant