-
Notifications
You must be signed in to change notification settings - Fork 18
/
setup.py
120 lines (98 loc) · 3.54 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
from setuptools import Extension, setup
class get_numpy_include(object):
"""Defer numpy.get_include() until after numpy is installed.
From: https://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py
"""
def __str__(self):
import numpy
return numpy.get_include()
ext_modules = []
ext_modules += [
Extension(
"dadapy._cython.cython_clustering",
sources=["dadapy/_cython/cython_clustering.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
ext_modules += [
Extension(
"dadapy._cython.cython_clustering_v2",
sources=["dadapy/_cython/cython_clustering_v2.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
ext_modules += [
Extension(
"dadapy._cython.cython_maximum_likelihood_opt",
sources=["dadapy/_cython/cython_maximum_likelihood_opt.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
ext_modules += [
Extension(
"dadapy._cython.cython_maximum_likelihood_opt_full",
sources=["dadapy/_cython/cython_maximum_likelihood_opt_full.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
ext_modules += [
Extension(
"dadapy._cython.cython_density",
sources=["dadapy/_cython/cython_density.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
ext_modules += [
Extension(
"dadapy._cython.cython_overlap",
sources=["dadapy/_cython/cython_overlap.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
ext_modules += [
Extension(
"dadapy._cython.cython_grads",
sources=["dadapy/_cython/cython_grads.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
]
exts_parallel = [
Extension(
"dadapy._cython.cython_distances",
sources=["dadapy/_cython/cython_distances.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
Extension(
"dadapy._cython.cython_differentiable_imbalance",
sources=["dadapy/_cython/cython_differentiable_imbalance.c"],
include_dirs=[get_numpy_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
]
extra_compile_args = (["-fopenmp"],)
extra_link_args = (["-fopenmp"],)
# Check if the '-fopenmp' flag is supported
command = 'gcc -fopenmp -E - < /dev/null > /dev/null 2>&1 && echo "OpenMP supported" || echo "OpenMP not supported"'
if os.system(command) == "OpenMP supported":
# If '-fopenmp' is supported, add the extra compile and link arguments
# Installing cython_distances using OpenMP
for ext_parallel in exts_parallel:
ext_parallel.extra_compile_args.append("-fopenmp")
ext_parallel.extra_link_args.append("-fopenmp")
# If OpenMP is not available, the C extension to compute distances in discrete spaces will not run in parallel.
ext_modules += exts_parallel
setup(
packages=["dadapy", "dadapy._utils"],
ext_modules=ext_modules,
include_package_data=True,
package_data={"dadapy": ["_utils/discrete_volumes/*.dat"]},
)