utils.py 472 Bytes
Newer Older
limm's avatar
limm committed
1
import torch
limm's avatar
limm committed
2
3
4
5

def get_all_dtypes():
    return [torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64,
            torch.float16, torch.float32, torch.float64]
limm's avatar
limm committed
6
7
8
9
10
11
12
13
14
15
16

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)