dgl.sparse.SparseMatrix.csr

SparseMatrix.csr() Tuple[Tensor, Tensor, Tensor][source]

Returns the compressed sparse row (CSR) representation of the sparse matrix.

See CSR in Wikipedia.

This function also returns value indices as an index tensor, indicating the order of the values of non-zero elements in the CSR representation. A None value indices array indicates the order of the values stays the same as the values of the SparseMatrix.

Returns:

  • torch.Tensor – Row indptr

  • torch.Tensor – Column indices

  • torch.Tensor – Value indices

Examples

>>> indices = torch.tensor([[1, 2, 1], [2, 4, 3]])
>>> A = dglsp.spmatrix(indices)
>>> A.csr()
(tensor([0, 0, 2, 3]), tensor([2, 3, 4]), tensor([0, 2, 1]))