cuspa.tl.CSRMatrix#

class cuspa.tl.CSRMatrix(
indptr: Any,
indices: Any,
data: Any,
shape: tuple[int, int],
)#

CSR matrix backed by CuPy, CUDA PyTorch, or NumPy arrays.

indptr and indices share one dtype: int32, or int64 when the matrix has more than 2**31 - 1 non-zeros. data is always int32.

Attributes

Methods

to_cupy_csr([dtype])

Wrap as cupyx.scipy.sparse.csr_matrix.

to_torch_sparse([dtype])

Wrap as a torch.sparse_csr_tensor.

CSRMatrix.indptr: Any#
CSRMatrix.indices: Any#
CSRMatrix.data: Any#
CSRMatrix.shape: tuple[int, int]#
CSRMatrix.nnz#
CSRMatrix.to_cupy_csr(dtype: Any = 'float32') → Any#

Wrap as cupyx.scipy.sparse.csr_matrix.

cupyx.scipy.sparse only supports float and complex data. Counts are cast to dtype, which defaults to float32.

cupyx.scipy.sparse also only supports int32 indices, so this raises OverflowError for a matrix with more than 2**31 - 1 non-zeros. Use to_torch_sparse() or the arrays directly instead.

CSRMatrix.to_torch_sparse(dtype: Any = None) → Any#

Wrap as a torch.sparse_csr_tensor.