Moves the matrix to GPU. If the matrix is already on GPU, the original matrix will be returned. If multiple GPU devices exist, ``cuda:0`` will be selected. Returns ------- SparseMatrix The matrix on GPU Examples --------
(self)
| 295 | return from_coo(row, col, val, self.shape) |
| 296 | |
| 297 | def cuda(self): |
| 298 | """Moves the matrix to GPU. If the matrix is already on GPU, the |
| 299 | original matrix will be returned. If multiple GPU devices exist, |
| 300 | ``cuda:0`` will be selected. |
| 301 | |
| 302 | Returns |
| 303 | ------- |
| 304 | SparseMatrix |
| 305 | The matrix on GPU |
| 306 | |
| 307 | Examples |
| 308 | -------- |
| 309 | |
| 310 | >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]]) |
| 311 | >>> A = dglsp.spmatrix(indices, shape=(3, 4)) |
| 312 | >>> A.cuda() |
| 313 | SparseMatrix(indices=tensor([[1, 1, 2], |
| 314 | [1, 2, 0]], device='cuda:0'), |
| 315 | values=tensor([1., 1., 1.], device='cuda:0'), |
| 316 | shape=(3, 4), nnz=3) |
| 317 | """ |
| 318 | return self.to(device="cuda") |
| 319 | |
| 320 | def cpu(self): |
| 321 | """Moves the matrix to CPU. If the matrix is already on CPU, the |