dgl.sparse.SparseMatrix.to
- SparseMatrix.to(device=None, dtype=None)[source]
执行矩阵数据类型和/或设备转换。如果目标设备和数据类型已经在使用中,将返回原始矩阵。
- Parameters:
device (torch.device, optional) – 如果提供了矩阵的目标设备,否则将使用当前设备
dtype (torch.dtype, 可选) – 如果提供了矩阵值的目标数据类型,否则将使用当前数据类型
- Returns:
转换后的矩阵
- Return type:
示例
>>> 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)