-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
77 lines (60 loc) · 2.11 KB
/
Copy pathsetup.py
File metadata and controls
77 lines (60 loc) · 2.11 KB
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
"""
Build the Cython extension modules used by the Spinguin core.
This script configures the platform-dependent compiler and linker flags for
the `spinguin._core._sparse_dot` and `spinguin._core._intersect_indices`
extension modules.
"""
import sys
import numpy as np
from Cython.Build import cythonize
from setuptools import Extension, setup
def _get_openmp_flags() -> tuple[list[str], list[str]]:
"""
Return the platform-dependent compiler and linker flags.
Returns
-------
tuple of list of str
Compiler flags and linker flags, in this order.
Raises
------
RuntimeError
If the current platform is not supported by this build script.
"""
# Define the compiler and linker flags for Microsoft compilers.
if sys.platform == "win32":
extra_compile_args = ["/openmp", "/O2", "/arch:SSE2", "/GS-"]
extra_link_args = []
# Define the compiler and linker flags for Linux compilers.
elif sys.platform.startswith("linux"):
extra_compile_args = ["-fopenmp", "-Ofast", "-march=native"]
extra_link_args = ["-fopenmp"]
# Stop with a clear error on unsupported platforms.
else:
raise RuntimeError(
"This build script currently supports only Windows and Linux."
)
return extra_compile_args, extra_link_args
# Resolve the platform-dependent build flags.
extra_compile_args, extra_link_args = _get_openmp_flags()
# Define the extension modules to be compiled.
ext_modules = [
Extension(
name="spinguin._core._sparse_dot",
sources=["src/spinguin/_core/_sparse_dot.pyx"],
include_dirs=[np.get_include()],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
language="c++",
),
Extension(
name="spinguin._core._intersect_indices",
sources=["src/spinguin/_core/_intersect_indices.pyx"],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
language="c++",
),
]
# Build the extension modules with Cython annotation enabled.
setup(
ext_modules=cythonize(ext_modules, annotate=True),
)