utils.py 392 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
from typing import Any
2
import torch
rusty1s's avatar
rusty1s committed
3
4
5
6
7
8

try:
    from typing_extensions import Final  # noqa
except ImportError:
    from torch.jit import Final  # noqa

rusty1s's avatar
rusty1s committed
9

rusty1s's avatar
rusty1s committed
10
def is_scalar(other: Any) -> bool:
rusty1s's avatar
rusty1s committed
11
    return isinstance(other, int) or isinstance(other, float)
12
13
14
15
16
17


def cartesian1d(x, y):
    a1, a2 = torch.meshgrid([x, y])
    coos = torch.stack([a1, a2]).T.reshape(-1, 2)
    return coos.split(1, dim=1)