import torch def get_all_dtypes(): return [torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64, torch.float16, torch.float32, torch.float64] dtypes = get_all_dtypes() dtypes.remove(torch.half) devices = [torch.device('cpu')] if torch.cuda.is_available(): devices += [torch.device('cuda:{}'.format(torch.cuda.current_device()))] def tensor(x, dtype, device): return None if x is None else torch.tensor(x, dtype=dtype, device=device)