summaryrefslogtreecommitdiff
path: root/numpy/random/meson.build
blob: 036cd81b9a2e1977da7c567b287da405fa70889e (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Build npyrandom library
# -----------------------
npyrandom_sources = [
  'src/distributions/logfactorial.c',
  'src/distributions/distributions.c',
  'src/distributions/random_mvhg_count.c',
  'src/distributions/random_mvhg_marginals.c',
  'src/distributions/random_hypergeometric.c',
]

npyrandom_lib = static_library('npyrandom',
  npyrandom_sources,
  c_args: staticlib_cflags,
  # include_directories: '../core/include',
  dependencies: [py_dep, np_core_dep],
  install: true,
  install_dir: np_dir / 'random/lib',
)

# Build Cython extensions for numpy.random
# ----------------------------------------
# pyx -> c transpile output depends on copied __init__.py and pxd files
_cython_tree_random = [
  fs.copyfile('__init__.py'),
  fs.copyfile('__init__.pxd'),
  fs.copyfile('_common.pxd'),
  fs.copyfile('bit_generator.pxd'),
  fs.copyfile('c_distributions.pxd'),
]
# Need to use `custom_target` because we need to install this .pxd file
_cython_tree_random += custom_target('_bounded_integer_pxd',
  output: '_bounded_integers.pxd',
  input: '_bounded_integers.pxd.in',
  command: [tempita_cli, '@INPUT@', '-o', '@OUTPUT@'],
  install: true,
  install_dir: np_dir / 'random'
)

_bounded_integers_pyx = custom_target('_bounded_integer_pyx',
  output: '_bounded_integers.pyx',
  input: '_bounded_integers.pyx.in',
  command: [tempita_cli, '@INPUT@', '-o', '@OUTPUT@'],
)

c_args_random = [
  cflags_large_file_support,
  '-DNPY_NO_DEPRECATED_API=0',  # Cython still uses old NumPy C API
]
if host_machine.system() == 'cygwin'
  c_args_random += ['-Wl,--export-all-symbols']
endif

# name, sources, extra link libs, extra c_args
random_pyx_sources = [
  ['_bounded_integers', _bounded_integers_pyx, [], npymath_lib],
  ['_common', '_common.pyx', [], []],
  ['_mt19937', ['_mt19937.pyx', 'src/mt19937/mt19937.c', 'src/mt19937/mt19937-jump.c'], [], []],
  ['_philox', ['_philox.pyx', 'src/philox/philox.c'], [], []],
  ['_pcg64', ['_pcg64.pyx', 'src/pcg64/pcg64.c'], ['-U__GNUC_GNU_INLINE__'], []],
  ['_sfc64', ['_sfc64.pyx', 'src/sfc64/sfc64.c'], [], []],
  ['bit_generator', 'bit_generator.pyx', [], []],
  # The `fs.copyfile` usage here is needed because these two .pyx files import
  # from _bounded_integers,and its pxd file is only present in the build directory
  ['_generator', fs.copyfile('_generator.pyx'), [], npymath_lib],
  ['mtrand', [
      fs.copyfile('mtrand.pyx'),
      'src/distributions/distributions.c',
      'src/legacy/legacy-distributions.c'
    ], ['-DNP_RANDOM_LEGACY=1'], npymath_lib,
  ],
]
foreach gen: random_pyx_sources
  py.extension_module(gen[0],
    [gen[1], _cython_tree, _cython_tree_random],
    c_args: [c_args_random, gen[2]],
    include_directories: 'src',
    dependencies: np_core_dep,
    link_with: [npyrandom_lib, gen[3]],
    install: true,
    subdir: 'numpy/random',
  )
endforeach

# Install Python sources, stub files, tests, examples and license
# ---------------------------------------------------------------
py.install_sources(
  [
    '__init__.pxd',
    '__init__.py',
    '__init__.pyi',
    '_common.pxd',
    '_generator.pyi',
    '_mt19937.pyi',
    '_pcg64.pyi',
    '_pickle.py',
    '_philox.pyi',
    '_sfc64.pyi',
    'bit_generator.pxd',
    'bit_generator.pyi',
    'c_distributions.pxd',
    'LICENSE.md',
    'mtrand.pyi',
  ],
  subdir: 'numpy/random'
)

py.install_sources(
  [
    'tests/__init__.py',
    'tests/test_direct.py',
    'tests/test_extending.py',
    'tests/test_generator_mt19937.py',
    'tests/test_generator_mt19937_regressions.py',
    'tests/test_random.py',
    'tests/test_randomstate.py',
    'tests/test_randomstate_regression.py',
    'tests/test_regression.py',
    'tests/test_seed_sequence.py',
    'tests/test_smoke.py',
  ],
  subdir: 'numpy/random/tests'
)

py.install_sources(
  [
    'tests/data/__init__.py',
    'tests/data/mt19937-testset-1.csv',
    'tests/data/mt19937-testset-2.csv',
    'tests/data/pcg64-testset-1.csv',
    'tests/data/pcg64-testset-2.csv',
    'tests/data/pcg64dxsm-testset-1.csv',
    'tests/data/pcg64dxsm-testset-2.csv',
    'tests/data/philox-testset-1.csv',
    'tests/data/philox-testset-2.csv',
    'tests/data/sfc64-testset-1.csv',
    'tests/data/sfc64-testset-2.csv',
  ],
  subdir: 'numpy/random/tests/data'
)

py.install_sources(
  [
  '_examples/cffi/extending.py',
  '_examples/cffi/parse.py',
  ],
  subdir: 'numpy/random/_examples/cffi'
)

py.install_sources(
  [
  '_examples/cython/extending.pyx',
  '_examples/cython/extending_distributions.pyx',
  '_examples/cython/setup.py',
  ],
  subdir: 'numpy/random/_examples/cython'
)

py.install_sources(
  [
  '_examples/numba/extending.py',
  '_examples/numba/extending_distributions.py',
  ],
  subdir: 'numpy/random/_examples/numba'
)