Skip to content

Diagonal broadcast results in SparseMatrixCSC #24317

@garrison

Description

@garrison

I was surprised to notice that broadcast on a Diagonal matrix results in a sparse matrix, not a dense one:

julia> Diagonal(-1:0) .+ 1
2×2 SparseMatrixCSC{Int64,Int64} with 4 stored entries:
  [1, 1]  =  0
  [2, 1]  =  1
  [1, 2]  =  1
  [2, 2]  =  1

In particular, the 0 in the above example is a "stored entry", so even in the case where there are many zeros in the result, it will still take more memory than a dense matrix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collectionsparseSparse arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions