torch_cluster/testing.py
raw| 1 | from typing import Any |
| 2 | |
| 3 | import torch |
| 4 | |
| 5 | dtypes = [ |
| 6 | torch.half, torch.bfloat16, torch.float, torch.double, torch.int, |
| 7 | torch.long |
| 8 | ] |
| 9 | grad_dtypes = [torch.half, torch.float, torch.double] |
| 10 | |
| 11 | devices = [torch.device('cpu')] |
| 12 | if torch.cuda.is_available(): |
| 13 | devices += [torch.device('cuda:0')] |
| 14 | |
| 15 | |
| 16 | def tensor(x: Any, dtype: torch.dtype, device: torch.device): |
| 17 | return None if x is None else torch.tensor(x, dtype=dtype, device=device) |