Julia: 0I should not insert zeros when catted with sparse matrices

Created on 26 Apr 2017  路  8Comments  路  Source: JuliaLang/julia

julia> [speye(3,3) 0I]
3脳6 SparseMatrixCSC{Float64,Int64} with 6 stored entries:
  [1, 1]  =  1.0
  [2, 2]  =  1.0
  [3, 3]  =  1.0
  [1, 4]  =  0.0
  [2, 5]  =  0.0
  [3, 6]  =  0.0

Those stored zero values shouldn't be there.

good first issue help wanted sparse

Most helpful comment

Checking if the multiple is zero as a special case in these concatenation methods could make sense.

All 8 comments

Just curious, is there any justification for (or against) this? It's not as clear cut to me as it seems to be in the description?

It's not so bad since it's just the diagonal zeros that are inserted, but it still seems like it would be better not to insert those zeros at all. Up to the sparse folks, I guess.

Checking if the multiple is zero as a special case in these concatenation methods could make sense.

Digging through the code, I think the check doesn't go into the concatenation methods. There just needs to be an iszero(diag) check in the speye_scaled function used to convert 0I into a sparse matrix.

Marking as an intro issue since (given that information) this should be an easy PR.

I haven't careful followed the structural zeros discussion, but it seems this would be a reasonable way to define structural zeros on some diagonal of a matrix.

I don't have a use case, so I have no idea if this would ever be desired, or if there's a better way to do it. Would it, and is there?

Aren't the zeros already there?

Removing them (with dropzeros!) is a bit more convenient than creating them in the first place. a sparse matrix with stored zeros on the diagonal is needed once in a while, but since UniformScaling doesn't have a size it's probably not the best type to use for this. We could perhaps stop doing zero purging by default when converting Diagonal to sparse.

@iamnapo writes:

Aren't the zeros already there?

I assume you're referring to my comment/question? The idea of structural zeros in a sparse matrix is that, sometimes, it's useful to explicitly store zeros at a location and have it take up space, so you can change the value later without allocating. From @tkelman's answer, it sounds like using Diagonal for this would be a better solution than using 0I.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilburtownsend picture wilburtownsend  路  3Comments

musm picture musm  路  3Comments

iamed2 picture iamed2  路  3Comments

tkoolen picture tkoolen  路  3Comments

felixrehren picture felixrehren  路  3Comments