Skip to content

Commit 1e6c7dd

Browse files
authored
Merge pull request #30 from wamuir/refine-coo-nnz
Clarify NNZ behavior on COO format sparse matrices
2 parents 04b5e68 + 2e473a5 commit 1e6c7dd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

coordinate.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var (
1111
_ mat.Mutable = (*COO)(nil)
1212
)
1313

14-
// COO is a COOrdinate format sparse matrix implementation (sometimes called `Tiplet` format) and implements the
15-
// Matrix interface from gonum/matrix. This allows large sparse (mostly zero values) matrices to be stored
14+
// COO is a COOrdinate format sparse matrix implementation (sometimes called `Triplet` format) and implements the
15+
// Matrix interface from gonum/matrix. This allows large sparse (mostly zero-valued) matrices to be stored
1616
// efficiently in memory (only storing non-zero values). COO matrices are good for constructing sparse matrices
1717
// initially and very good at converting to CSR and CSC formats but poor for arithmetic operations. As this
1818
// type implements the gonum mat.Matrix interface, it may be used with any of the Gonum mat functions that
@@ -25,7 +25,7 @@ type COO struct {
2525
data []float64
2626
}
2727

28-
// NewCOO creates a new DIAgonal format sparse matrix.
28+
// NewCOO creates a new COOrdinate format sparse matrix.
2929
// The matrix is initialised to the size of the specified r * c dimensions (rows * columns)
3030
// with the specified slices containing either nil or containing rows and cols indexes of non-zero elements
3131
// and the non-zero data values themselves respectively. If not nil, the supplied slices will be used as the
@@ -54,12 +54,14 @@ func NewCOO(r int, c int, rows []int, cols []int, data []float64) *COO {
5454
return coo
5555
}
5656

57-
// NNZ returns the Number of Non Zero elements in the sparse matrix.
57+
// NNZ returns the number of stored data elements. This number includes explicit
58+
// zeroes, if stored, and may be exceed the total number of matrix elements
59+
// (rows * columns) if duplicate coordinates are stored.
5860
func (c *COO) NNZ() int {
5961
return len(c.data)
6062
}
6163

62-
// DoNonZero calls the function fn for each of the non-zero elements of the receiver.
64+
// DoNonZero calls the function fn for each of the stored data elements in the receiver.
6365
// The function fn takes a row/column index and the element value of the receiver at
6466
// (i, j). The order of visiting to each non-zero element is not guaranteed.
6567
func (c *COO) DoNonZero(fn func(i, j int, v float64)) {

0 commit comments

Comments
 (0)