dgl.sparse.SparseMatrix.toΒΆ

SparseMatrix.to(device=None, dtype=None)[source]ΒΆ

Performs matrix dtype and/or device conversion. If the target device and dtype are already in use, the original matrix will be returned.

Parameters
  • device (torch.device, optional) – The target device of the matrix if provided, otherwise the current device will be used

  • dtype (torch.dtype, optional) – The target data type of the matrix values if provided, otherwise the current data type will be used

Returns

The converted matrix

Return type

SparseMatrix

Examples

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