summaryrefslogtreecommitdiff
path: root/numpy/random
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2022-11-23 23:40:23 +0100
committerRalf Gommers <ralf.gommers@gmail.com>2022-11-25 12:37:46 +0100
commit4002a7d421ff10780c28a3643683af7a9754f87f (patch)
treea06d4c10642d1c93d552f80f1e90f393c9953c18 /numpy/random
parent632f573f12c641990bfac24cf4df435804340a7f (diff)
downloadnumpy-4002a7d421ff10780c28a3643683af7a9754f87f.tar.gz
BLD: enable building NumPy with Meson
This enables building with NumPy on Linux and macOS. Windows support should be complete to, but is untested as of now and may need a few tweaks. This contains: - A set of `meson.build` files and related code generation script tweaks, header templates, etc. - One CI job on Linux - Basic docs on using Meson to build NumPy (not yet integrated in the html docs, it's too early for that - this is for early adopters right now). The build should be complete, with the major exception of SIMD support. The full test suite passes. See gh-22546 for the tracking issue with detailed notes on the plan for switching NumPy to Meson as its build system. Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu>
Diffstat (limited to 'numpy/random')
-rw-r--r--numpy/random/meson.build164
1 files changed, 164 insertions, 0 deletions
diff --git a/numpy/random/meson.build b/numpy/random/meson.build
new file mode 100644
index 000000000..cc61c66dd
--- /dev/null
+++ b/numpy/random/meson.build
@@ -0,0 +1,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'
+ ], ['-DNPY_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'
+)