Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/random/setup.py
7757 views
1
import os
2
import platform
3
import sys
4
from os.path import join
5
6
from numpy.distutils.system_info import platform_bits
7
8
is_msvc = (platform.platform().startswith('Windows') and
9
platform.python_compiler().startswith('MS'))
10
11
12
def configuration(parent_package='', top_path=None):
13
from numpy.distutils.misc_util import Configuration, get_mathlibs
14
config = Configuration('random', parent_package, top_path)
15
16
def generate_libraries(ext, build_dir):
17
config_cmd = config.get_config_cmd()
18
libs = get_mathlibs()
19
if sys.platform == 'win32':
20
libs.extend(['Advapi32', 'Kernel32'])
21
ext.libraries.extend(libs)
22
return None
23
24
# enable unix large file support on 32 bit systems
25
# (64 bit off_t, lseek -> lseek64 etc.)
26
if sys.platform[:3] == 'aix':
27
defs = [('_LARGE_FILES', None)]
28
else:
29
defs = [('_FILE_OFFSET_BITS', '64'),
30
('_LARGEFILE_SOURCE', '1'),
31
('_LARGEFILE64_SOURCE', '1')]
32
33
defs.append(('NPY_NO_DEPRECATED_API', 0))
34
config.add_subpackage('tests')
35
config.add_data_dir('tests/data')
36
config.add_data_dir('_examples')
37
38
EXTRA_LINK_ARGS = []
39
EXTRA_LIBRARIES = ['npyrandom']
40
if os.name != 'nt':
41
# Math lib
42
EXTRA_LIBRARIES.append('m')
43
# Some bit generators exclude GCC inlining
44
EXTRA_COMPILE_ARGS = ['-U__GNUC_GNU_INLINE__']
45
46
if is_msvc and platform_bits == 32:
47
# 32-bit windows requires explicit sse2 option
48
EXTRA_COMPILE_ARGS += ['/arch:SSE2']
49
elif not is_msvc:
50
# Some bit generators require c99
51
EXTRA_COMPILE_ARGS += ['-std=c99']
52
53
# Use legacy integer variable sizes
54
LEGACY_DEFS = [('NP_RANDOM_LEGACY', '1')]
55
PCG64_DEFS = []
56
# One can force emulated 128-bit arithmetic if one wants.
57
#PCG64_DEFS += [('PCG_FORCE_EMULATED_128BIT_MATH', '1')]
58
depends = ['__init__.pxd', 'c_distributions.pxd', 'bit_generator.pxd']
59
60
# npyrandom - a library like npymath
61
npyrandom_sources = [
62
'src/distributions/logfactorial.c',
63
'src/distributions/distributions.c',
64
'src/distributions/random_mvhg_count.c',
65
'src/distributions/random_mvhg_marginals.c',
66
'src/distributions/random_hypergeometric.c',
67
]
68
69
def gl_if_msvc(build_cmd):
70
""" Add flag if we are using MSVC compiler
71
72
We can't see this in our scope, because we have not initialized the
73
distutils build command, so use this deferred calculation to run when
74
we are building the library.
75
"""
76
# Keep in sync with numpy/core/setup.py
77
if build_cmd.compiler.compiler_type == 'msvc':
78
# explicitly disable whole-program optimization
79
return ['/GL-']
80
return []
81
82
config.add_installed_library('npyrandom',
83
sources=npyrandom_sources,
84
install_dir='lib',
85
build_info={
86
'include_dirs' : [], # empty list required for creating npyrandom.h
87
'extra_compiler_args': [gl_if_msvc],
88
})
89
90
for gen in ['mt19937']:
91
# gen.pyx, src/gen/gen.c, src/gen/gen-jump.c
92
config.add_extension(f'_{gen}',
93
sources=[f'_{gen}.c',
94
f'src/{gen}/{gen}.c',
95
f'src/{gen}/{gen}-jump.c'],
96
include_dirs=['.', 'src', join('src', gen)],
97
libraries=EXTRA_LIBRARIES,
98
extra_compile_args=EXTRA_COMPILE_ARGS,
99
extra_link_args=EXTRA_LINK_ARGS,
100
depends=depends + [f'_{gen}.pyx'],
101
define_macros=defs,
102
)
103
for gen in ['philox', 'pcg64', 'sfc64']:
104
# gen.pyx, src/gen/gen.c
105
_defs = defs + PCG64_DEFS if gen == 'pcg64' else defs
106
config.add_extension(f'_{gen}',
107
sources=[f'_{gen}.c',
108
f'src/{gen}/{gen}.c'],
109
include_dirs=['.', 'src', join('src', gen)],
110
libraries=EXTRA_LIBRARIES,
111
extra_compile_args=EXTRA_COMPILE_ARGS,
112
extra_link_args=EXTRA_LINK_ARGS,
113
depends=depends + [f'_{gen}.pyx',
114
'bit_generator.pyx', 'bit_generator.pxd'],
115
define_macros=_defs,
116
)
117
for gen in ['_common', 'bit_generator']:
118
# gen.pyx
119
config.add_extension(gen,
120
sources=[f'{gen}.c'],
121
libraries=EXTRA_LIBRARIES,
122
extra_compile_args=EXTRA_COMPILE_ARGS,
123
extra_link_args=EXTRA_LINK_ARGS,
124
include_dirs=['.', 'src'],
125
depends=depends + [f'{gen}.pyx', f'{gen}.pxd',],
126
define_macros=defs,
127
)
128
config.add_data_files(f'{gen}.pxd')
129
for gen in ['_generator', '_bounded_integers']:
130
# gen.pyx, src/distributions/distributions.c
131
config.add_extension(gen,
132
sources=[f'{gen}.c'],
133
libraries=EXTRA_LIBRARIES + ['npymath'],
134
extra_compile_args=EXTRA_COMPILE_ARGS,
135
include_dirs=['.', 'src'],
136
extra_link_args=EXTRA_LINK_ARGS,
137
depends=depends + [f'{gen}.pyx'],
138
define_macros=defs,
139
)
140
config.add_data_files('_bounded_integers.pxd')
141
mtrand_libs = ['m', 'npymath'] if os.name != 'nt' else ['npymath']
142
config.add_extension('mtrand',
143
sources=['mtrand.c',
144
'src/legacy/legacy-distributions.c',
145
'src/distributions/distributions.c',
146
],
147
include_dirs=['.', 'src', 'src/legacy'],
148
libraries=mtrand_libs,
149
extra_compile_args=EXTRA_COMPILE_ARGS,
150
extra_link_args=EXTRA_LINK_ARGS,
151
depends=depends + ['mtrand.pyx'],
152
define_macros=defs + LEGACY_DEFS,
153
)
154
config.add_data_files(*depends)
155
config.add_data_files('*.pyi')
156
return config
157
158
159
if __name__ == '__main__':
160
from numpy.distutils.core import setup
161
162
setup(configuration=configuration)
163
164