__init__.py 3.27 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
import importlib
import os.path as osp

import torch

rusty1s's avatar
rusty1s committed
6
__version__ = '0.6.1'
rusty1s's avatar
rusty1s committed
7
8
9
expected_torch_version = (1, 4)

try:
rusty1s's avatar
rusty1s committed
10
    for library in [
rusty1s's avatar
rusty1s committed
11
            '_version', '_convert', '_diag', '_spmm', '_spspmm', '_metis',
rusty1s's avatar
rusty1s committed
12
            '_rw', '_saint', '_padding'
rusty1s's avatar
rusty1s committed
13
    ]:
rusty1s's avatar
rusty1s committed
14
15
        torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
            library, [osp.dirname(__file__)]).origin)
rusty1s's avatar
rusty1s committed
16
except OSError as e:
rusty1s's avatar
rusty1s committed
17
18
19
20
21
22
    major, minor = [int(x) for x in torch.__version__.split('.')[:2]]
    t_major, t_minor = expected_torch_version
    if major != t_major or (major == t_major and minor != t_minor):
        raise RuntimeError(
            f'Expected PyTorch version {t_major}.{t_minor} but found '
            f'version {major}.{minor}.')
rusty1s's avatar
rusty1s committed
23
24
    raise OSError(e)

rusty1s's avatar
cleaner  
rusty1s committed
25
26
27
28
29
30
if torch.version.cuda is not None:  # pragma: no cover
    cuda_version = torch.ops.torch_sparse.cuda_version()

    if cuda_version == -1:
        major = minor = 0
    elif cuda_version < 10000:
rusty1s's avatar
rusty1s committed
31
32
33
34
35
36
37
38
39
40
41
42
43
        major, minor = int(str(cuda_version)[0]), int(str(cuda_version)[2])
    else:
        major, minor = int(str(cuda_version)[0:2]), int(str(cuda_version)[3])
    t_major, t_minor = [int(x) for x in torch.version.cuda.split('.')]

    if t_major != major or t_minor != minor:
        raise RuntimeError(
            f'Detected that PyTorch and torch_sparse were compiled with '
            f'different CUDA versions. PyTorch has CUDA version '
            f'{t_major}.{t_minor} and torch_sparse has CUDA version '
            f'{major}.{minor}. Please reinstall the torch_sparse that '
            f'matches your PyTorch install.')

rusty1s's avatar
typos  
rusty1s committed
44
45
46
47
48
49
50
from .storage import SparseStorage  # noqa
from .tensor import SparseTensor  # noqa
from .transpose import t  # noqa
from .narrow import narrow, __narrow_diag__  # noqa
from .select import select  # noqa
from .index_select import index_select, index_select_nnz  # noqa
from .masked_select import masked_select, masked_select_nnz  # noqa
rusty1s's avatar
rusty1s committed
51
from .permute import permute  # noqa
rusty1s's avatar
typos  
rusty1s committed
52
53
54
55
56
57
from .diag import remove_diag, set_diag, fill_diag  # noqa
from .add import add, add_, add_nnz, add_nnz_  # noqa
from .mul import mul, mul_, mul_nnz, mul_nnz_  # noqa
from .reduce import sum, mean, min, max  # noqa
from .matmul import matmul  # noqa
from .cat import cat, cat_diag  # noqa
rusty1s's avatar
rusty1s committed
58
from .rw import random_walk  # noqa
rusty1s's avatar
fix  
rusty1s committed
59
from .metis import partition  # noqa
rusty1s's avatar
rusty1s committed
60
from .saint import saint_subgraph  # noqa
rusty1s's avatar
rusty1s committed
61

rusty1s's avatar
typos  
rusty1s committed
62
63
64
65
66
67
68
from .convert import to_torch_sparse, from_torch_sparse  # noqa
from .convert import to_scipy, from_scipy  # noqa
from .coalesce import coalesce  # noqa
from .transpose import transpose  # noqa
from .eye import eye  # noqa
from .spmm import spmm  # noqa
from .spspmm import spspmm  # noqa
rusty1s's avatar
rusty1s committed
69
70

__all__ = [
rusty1s's avatar
rusty1s committed
71
72
73
74
    'SparseStorage',
    'SparseTensor',
    't',
    'narrow',
rusty1s's avatar
rusty1s committed
75
    '__narrow_diag__',
rusty1s's avatar
rusty1s committed
76
77
78
79
80
    'select',
    'index_select',
    'index_select_nnz',
    'masked_select',
    'masked_select_nnz',
rusty1s's avatar
rusty1s committed
81
    'permute',
rusty1s's avatar
rusty1s committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    'remove_diag',
    'set_diag',
    'fill_diag',
    'add',
    'add_',
    'add_nnz',
    'add_nnz_',
    'mul',
    'mul_',
    'mul_nnz',
    'mul_nnz_',
    'sum',
    'mean',
    'min',
    'max',
    'matmul',
    'cat',
    'cat_diag',
rusty1s's avatar
rusty1s committed
100
    'random_walk',
rusty1s's avatar
fix  
rusty1s committed
101
    'partition',
rusty1s's avatar
rusty1s committed
102
    'saint_subgraph',
103
104
    'to_torch_sparse',
    'from_torch_sparse',
rusty1s's avatar
rusty1s committed
105
106
    'to_scipy',
    'from_scipy',
rusty1s's avatar
rusty1s committed
107
    'coalesce',
rusty1s's avatar
rusty1s committed
108
    'transpose',
rusty1s's avatar
rusty1s committed
109
    'eye',
rusty1s's avatar
rusty1s committed
110
    'spmm',
rusty1s's avatar
rusty1s committed
111
    'spspmm',
rusty1s's avatar
rusty1s committed
112
    '__version__',
rusty1s's avatar
rusty1s committed
113
]