GraphBLAS / graphblas-api-c

Other
7 stars 3 forks source link

empty matrices and vectors #58

Open DrTimothyAldenDavis opened 2 years ago

DrTimothyAldenDavis commented 2 years ago

GrB_Matrix_new and GrB_Vector_new should allow any or all dimensions of a matrix or vector to be zero. MATLAB, Python, and Julia all allow for this, and if GraphBLAS is to be used in such languages, it must support them. Empty matrices of size, say, 10-by-0 or 0-by-10, are important.

Example: say an algorithm searches a graph for nodes with a particular property, and wishes to return an INT64 GrB_Vector with a list of those k nodes. If no nodes are found, k is zero and the vector has length zero.

Suppose the set of neighbors of these k nodes is to be computed, one set per node. Then C = A (list,:) can be created using a list of such nodes. If the list is empty, C is 0-by-n, which is the correct answer and correct dimension of C.

There are many such examples. Empty matrices and vectors allow for clean handling of edge conditions in an algorithm. This issue should be considered for the v2.1 release.