Debian Codegraph @

torch_cluster/__init__.py

raw
1 import importlib
2 import os.path as osp
3
4 import torch
5
6 __version__ = '1.6.3'
7
8 for library in [
9 '_version', '_grid', '_graclus', '_fps', '_rw', '_sampler', '_nearest',
10 '_knn', '_radius'
11 ]:
12 cuda_spec = importlib.machinery.PathFinder().find_spec(
13 f'{library}_cuda', [osp.dirname(__file__)])
14 cpu_spec = importlib.machinery.PathFinder().find_spec(
15 f'{library}_cpu', [osp.dirname(__file__)])
16 spec = cuda_spec or cpu_spec
17 if spec is not None:
18 torch.ops.load_library(spec.origin)
19 else: # pragma: no cover
20 raise ImportError(f"Could not find module '{library}_cpu' in "
21 f"{osp.dirname(__file__)}")
22
23 cuda_version = torch.ops.torch_cluster.cuda_version()
24 if torch.version.cuda is not None and cuda_version != -1: # pragma: no cover
25 if cuda_version < 10000:
26 major, minor = int(str(cuda_version)[0]), int(str(cuda_version)[2])
27 else:
28 major, minor = int(str(cuda_version)[0:2]), int(str(cuda_version)[3])
29 t_major, t_minor = [int(x) for x in torch.version.cuda.split('.')]
30
31 if t_major != major:
32 raise RuntimeError(
33 f'Detected that PyTorch and torch_cluster were compiled with '
34 f'different CUDA versions. PyTorch has CUDA version '
35 f'{t_major}.{t_minor} and torch_cluster has CUDA version '
36 f'{major}.{minor}. Please reinstall the torch_cluster that '
37 f'matches your PyTorch install.')
38
39 from .fps import fps # noqa
40 from .graclus import graclus_cluster # noqa
41 from .grid import grid_cluster # noqa
42 from .knn import knn, knn_graph # noqa
43 from .nearest import nearest # noqa
44 from .radius import radius, radius_graph # noqa
45 from .rw import random_walk # noqa
46 from .sampler import neighbor_sampler # noqa
47
48 __all__ = [
49 'graclus_cluster',
50 'grid_cluster',
51 'fps',
52 'nearest',
53 'knn',
54 'knn_graph',
55 'radius',
56 'radius_graph',
57 'random_walk',
58 'neighbor_sampler',
59 '__version__',
60 ]