| 2275 | return torch.randperm(n=size, generator=self.rng_) |
| 2276 | |
| 2277 | def coo_matrix(self, data, rows, cols, shape=None, type_as=None): |
| 2278 | if type_as is None: |
| 2279 | return torch.sparse_coo_tensor(torch.stack([rows, cols]), data, size=shape) |
| 2280 | else: |
| 2281 | return torch.sparse_coo_tensor( |
| 2282 | torch.stack([rows, cols]), |
| 2283 | data, |
| 2284 | size=shape, |
| 2285 | dtype=type_as.dtype, |
| 2286 | device=type_as.device, |
| 2287 | ) |
| 2288 | |
| 2289 | def issparse(self, a): |
| 2290 | return getattr(a, "is_sparse", False) or getattr(a, "is_sparse_csr", False) |