Skip to content

Commit fc1b139

Browse files
authored
WITH_PYTHON conditionals (#313)
1 parent 7b0aa73 commit fc1b139

17 files changed

+42
-15
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 14)
44
set(TORCHSCATTER_VERSION 2.0.9)
55

66
option(WITH_CUDA "Enable CUDA support" OFF)
7+
option(WITH_PYTHON "Link to Python when building" ON)
78

89
if(WITH_CUDA)
910
enable_language(CUDA)
@@ -12,7 +13,10 @@ if(WITH_CUDA)
1213
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
1314
endif()
1415

15-
find_package(Python3 COMPONENTS Development)
16+
if (WITH_PYTHON)
17+
add_definitions(-DWITH_PYTHON)
18+
find_package(Python3 COMPONENTS Development)
19+
endif()
1620
find_package(Torch REQUIRED)
1721

1822
file(GLOB HEADERS csrc/*.h)
@@ -22,7 +26,10 @@ if(WITH_CUDA)
2226
endif()
2327

2428
add_library(${PROJECT_NAME} SHARED ${OPERATOR_SOURCES})
25-
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} Python3::Python)
29+
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES})
30+
if (WITH_PYTHON)
31+
target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
32+
endif()
2633
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchScatter)
2734

2835
target_include_directories(${PROJECT_NAME} INTERFACE

csrc/cpu/index_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
#define MAX_TENSORINFO_DIMS 25
66

csrc/cpu/scatter_cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
66
scatter_cpu(torch::Tensor src, torch::Tensor index, int64_t dim,

csrc/cpu/segment_coo_cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
66
segment_coo_cpu(torch::Tensor src, torch::Tensor index,

csrc/cpu/segment_csr_cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
66
segment_csr_cpu(torch::Tensor src, torch::Tensor indptr,

csrc/cpu/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
#define CHECK_CPU(x) AT_ASSERTM(x.device().is_cpu(), #x " must be CPU tensor")
66
#define CHECK_INPUT(x) AT_ASSERTM(x, "Input mismatch")

csrc/cuda/scatter_cuda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
66
scatter_cuda(torch::Tensor src, torch::Tensor index, int64_t dim,

csrc/cuda/segment_coo_cuda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
66
segment_coo_cuda(torch::Tensor src, torch::Tensor index,

csrc/cuda/segment_csr_cuda.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
66
segment_csr_cuda(torch::Tensor src, torch::Tensor indptr,

csrc/cuda/utils.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <torch/extension.h>
3+
#include "../extensions.h"
44

55
#define CHECK_CUDA(x) \
66
AT_ASSERTM(x.device().is_cuda(), #x " must be CUDA tensor")

0 commit comments

Comments
 (0)