dgl.sparse.SparseMatrix.cpu

SparseMatrix.cpu()[source]

将矩阵移动到 CPU。如果矩阵已在 CPU 上,则返回原始矩阵。

返回值:

位于 CPU 上的矩阵

返回类型:

SparseMatrix

示例

>>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]]).to("cuda")
>>> A = dglsp.spmatrix(indices, shape=(3, 4))
>>> A.cpu()
SparseMatrix(indices=tensor([[1, 1, 2],
                             [1, 2, 0]]),
             values=tensor([1., 1., 1.]),
             shape=(3, 4), nnz=3)