CuPy supports sparse matrices using cuSPARSE. These matrices have the same interfaces of SciPy's sparse matrices.
cupyx.scipy.sparse
cupyx.scipy.sparse.*_matrix
and scipy.sparse.*_matrix
are not implicitly convertible to each other. That means, SciPy functions cannot take cupyx.scipy.sparse.*_matrix
objects as inputs, and vice versa.
- To convert SciPy sparse matrices to CuPy, pass it to the constructor of each CuPy sparse matrix class.
- To convert CuPy sparse matrices to SciPy, use
get <cupyx.scipy.sparse.spmatrix.get>
method of each CuPy sparse matrix class.
Note that converting between CuPy and SciPy incurs data transfer between the host (CPU) device and the GPU device, which is costly in terms of performance.
- To convert CuPy ndarray to CuPy sparse matrices, pass it to the constructor of each CuPy sparse matrix class.
- To convert CuPy sparse matrices to CuPy ndarray, use
toarray
of each CuPy sparse matrix instance (e.g.,cupyx.scipy.sparse.csr_matrix.toarray
).
Converting between CuPy ndarray and CuPy sparse matrices does not incur data transfer; it is copied inside the GPU device.
cupyx.scipy.sparse.coo_matrix cupyx.scipy.sparse.csc_matrix cupyx.scipy.sparse.csr_matrix cupyx.scipy.sparse.dia_matrix cupyx.scipy.sparse.spmatrix
cupyx.scipy.sparse.bmat cupyx.scipy.sparse.diags cupyx.scipy.sparse.eye cupyx.scipy.sparse.hstack cupyx.scipy.sparse.identity cupyx.scipy.sparse.kron cupyx.scipy.sparse.spdiags cupyx.scipy.sparse.rand cupyx.scipy.sparse.random cupyx.scipy.sparse.vstack
cupyx.scipy.sparse.issparse cupyx.scipy.sparse.isspmatrix cupyx.scipy.sparse.isspmatrix_csc cupyx.scipy.sparse.isspmatrix_csr cupyx.scipy.sparse.isspmatrix_coo cupyx.scipy.sparse.isspmatrix_dia
cupyx.scipy.sparse.linalg.lsqr cupyx.scipy.sparse.linalg.norm