utils.py 729 Bytes
Newer Older
aiss's avatar
aiss committed
1
2
3
4
5
6
from typing import Any, Optional, Tuple

import torch

import torch_sparse.typing
from torch_sparse.typing import pyg_lib
quyuanhao123's avatar
quyuanhao123 committed
7
8
9
10
11
12
13

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


aiss's avatar
aiss committed
14
15
16
17
18
19
20
21
22
23
def index_sort(
        inputs: torch.Tensor,
        max_value: Optional[int] = None) -> Tuple[torch.Tensor, torch.Tensor]:
    r"""See pyg-lib documentation for more details:
    https://pyg-lib.readthedocs.io/en/latest/modules/ops.html"""
    if not torch_sparse.typing.WITH_INDEX_SORT:  # pragma: no cover
        return inputs.sort()
    return pyg_lib.ops.index_sort(inputs, max_value)


quyuanhao123's avatar
quyuanhao123 committed
24
25
def is_scalar(other: Any) -> bool:
    return isinstance(other, int) or isinstance(other, float)