11#ifdef WITH_PYTHON
22#include < Python.h>
33#endif
4- #include < torch/script.h>
4+ #include < torch/torch.h>
5+ #include < torch/library.h>
56
67#include " cpu/radius_cpu.h"
78
@@ -20,20 +21,25 @@ PyMODINIT_FUNC PyInit__radius_cpu(void) { return NULL; }
2021#endif
2122
2223CLUSTER_API torch::Tensor radius (torch::Tensor x, torch::Tensor y,
23- std::optional<torch::Tensor> ptr_x,
24- std::optional<torch::Tensor> ptr_y, double r,
25- int64_t max_num_neighbors, int64_t num_workers,
26- bool ignore_same_index) {
27- if (x.device ().is_cuda ()) {
28- #ifdef WITH_CUDA
29- return radius_cuda (x, y, ptr_x, ptr_y, r, max_num_neighbors, ignore_same_index);
30- #else
31- AT_ERROR (" Not compiled with CUDA support" );
32- #endif
33- } else {
34- return radius_cpu (x, y, ptr_x, ptr_y, r, max_num_neighbors, num_workers, ignore_same_index);
35- }
24+ std::optional<torch::Tensor> ptr_x,
25+ std::optional<torch::Tensor> ptr_y, double r,
26+ int64_t max_num_neighbors,
27+ int64_t num_workers,
28+ bool ignore_same_index) {
29+ return radius_cpu (x, y, ptr_x, ptr_y, r, max_num_neighbors, num_workers,
30+ ignore_same_index);
31+ }
32+
33+ TORCH_LIBRARY (torch_cluster, m) {
34+ m.def (" radius(Tensor x, Tensor y, Tensor? ptr_x, Tensor? ptr_y, float r, int max_num_neighbors, int num_workers = 1, bool ignore_same_index = False) -> Tensor" );
3635}
3736
38- static auto registry =
39- torch::RegisterOperators ().op(" torch_cluster::radius" , &radius);
37+ TORCH_LIBRARY_IMPL (torch_cluster, CPU , m) {
38+ m.impl (" radius" , &radius);
39+ }
40+
41+ #ifdef WITH_CUDA
42+ TORCH_LIBRARY_IMPL (torch_cluster, CUDA , m) {
43+ m.impl (" radius" , &radius_cuda);
44+ }
45+ #endif
0 commit comments