Cupy 稀疏矩阵不对应其 Scipy 等价?

Cupy sparse matrix does not correspond to its Scipy equivalence?

我挖掘了 cupy 稀疏矩阵的文档。

scipy 我希望有这样的东西:

from scipy.sparse import csr_matrix
A_csr = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]])

但在 cupy here:

To convert CuPy ndarray to CuPy sparse matrices, pass it to the constructor of each CuPy sparse matrix class.

# from cupy.sparse import csr_matrix as cp_csr_matrix
from cupyx.scipy.sparse import csr_matrix as cp_csr_matrix

cA = cp.array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
cA_csr = cp_csr_matrix(cA)

return :

ValueError: Only bool, float32, float64, complex64 and complex128 are supported

我还找到了 this 给出同样错误的答案。

如错误中所述,您需要将数据类型转换为 bool、float32/64 或 complex64/128:

import cupy as cp
from cupyx.scipy.sparse import csr_matrix as cp_csr_matrix

cA = cp.array([[1, 2, 0], [0, 0, 3], [4, 0, 5]], dtype=cp.float32)
cA_csr = cp_csr_matrix(cA)

顺便说一句,你能不能在你的机器上试试cA.astype(cp.float64)看看有没有错误?我的会抛出 NVRTCError。奇怪...