JuliaSparse / SuiteSparseGraphBLAS.jl

Sparse, General Linear Algebra for Graphs!
MIT License
102 stars 16 forks source link

How not to store 0's #110

Closed cdelv closed 1 year ago

cdelv commented 1 year ago

Hi, given a sparse matrix

 A = GBMatrix{Float64}(300,300)
A[1,2] = 1.0
A[2,2] = 0.0
A[2,3] = 1.0
A
300x300 GraphBLAS double matrix, hypersparse by row
  3 entries, memory: 480 bytes

    (1,2)    1
    (2,2)    0
    (2,3)    1

Note that it is stored in memory element [2,2] although it's 0. Is it possible to do A[2,2] = 0.0 and make the matrix not store it?

However, if A[2,2] were to be different from 0 and then I set it to zero, it will be important to store it as 0 so I can drop it later (or it should drop it automatically). After all, it's a space matrix, zeros should not be stored.

Thanks.

rayegun commented 1 year ago

No, this violates one of the core concepts of GraphBLAS: the pattern determines the sparsity not the operator/value. You can do dropzeros! of course at any time.

GraphBLAS collections are not compressed over 0, technically the implicit value is GrB_NO_VALUE. To make things more interoperable with the rest of the Julia ecosystem the default fill is A.fill = 0, but A.fill = missing or A.fill = nothing are perhaps closer to what is actually going on.

The original intent of GraphBLAS is to represent graphs, where it is perfectly reasonable for an edge to both exist and have a weight of 0 in the adjacency matrix.

cdelv commented 1 year ago

@Wimmerer tnahk you for your answer. That's a shame, it makes a bit complicated what I'm trying to do. Although, I want to ask, it it possible to assign a GrB_NO_VALUE? For instance

A[1,2] = GrB_NO_VALUE

Thanks.

rayegun commented 1 year ago

You mean to delete that entry by assignment (or no-op if it doesn't exist)? Not in the current wrapper, I'll add that as soon as I get a chance.

It will either be A[...] = GBScalar() or A[...] = novalue (novalue will be a new constant in the next version).

rayegun commented 1 year ago

Note also this is the direction that many sparse libraries (potentially including SparseArrays.jl) are going in. The sparsity structure shouldn't necessarily be coupled to the fill.

cdelv commented 1 year ago

Hey @Wimmerer,

I come back to ask you if you had a chance to implement the assignment deletion of a matrix entry.

Best regards.