-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
During construction of sparse matrices and when using setindex!
, entries with values 0
are not included/dropped from the underlying storage. This is no good for certain applications. In particular when preallocating sparse matrices.
For example we currently got:
julia> sparse([1],[1], [0.], 5 ,5)
5x5 sparse matrix with 0 Float64 entries:
Instead
julia> sparse([1],[1], [1.], 5 ,5)
5x5 sparse matrix with 1 Float64 entries:
[1, 1] = 0.0
or
julia> sparse([1],[1], [1.], 5 ,5, keepzeros=true)
5x5 sparse matrix with 1 Float64 entries:
[1, 1] = 0.0
My use case are preallocated Jacobian matrices when solving PDEs. Usually the pattern of potential non-zeros in the Jacobian is known, so it can be preallocated. However, when repeatedly filling the Jacobian during the calculation there is no guarantee that its underlaying storage will be kept fixed.
Maybe there could be a sparse type for fixed size sparse matrix, say SparseMatrixCSCfixed
. Constructed with sparse([1],[1], [1.], 5 ,5, keepzeros=true)
. Then setindex!
would not drop zeros and error when trying to assign to a not-allocated entry.