35 assert (!blas.isILP64) && (!lapack.isILP64);
40 text = lib.generators.toINI { } {
41 ${blas.implementation} = {
42 include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include";
43 library_dirs = "${blas}/lib:${lapack}/lib";
44 runtime_library_dirs = "${blas}/lib:${lapack}/lib";
45 libraries = "lapack,lapacke,blas,cblas";
48 include_dirs = "${lib.getDev lapack}/include";
49 library_dirs = "${lapack}/lib";
50 runtime_library_dirs = "${lapack}/lib";
53 include_dirs = "${lib.getDev blas}/include";
54 library_dirs = "${blas}/lib";
55 runtime_library_dirs = "${blas}/lib";
60 buildPythonPackage rec {
64 disabled = pythonOlder "3.9" || pythonAtLeast "3.13";
67 inherit pname version;
69 hash = "sha256-KgKrqe0S5KxOs+qUIcQgMBoMZGDZgw10qd+H76SRIBA=";
74 # Disable `numpy/core/tests/test_umath.py::TestComplexFunctions::test_loss_of_precision[complex256]`
75 # on x86_64-darwin because it fails under Rosetta 2 due to issues with trig functions and
76 # 80-bit long double complex numbers.
77 ./disable-failing-long-double-test-Rosetta-2.patch
79 # We patch cpython/distutils to fix https://bugs.python.org/issue1222585
80 # Patching of numpy.distutils is needed to prevent it from undoing the
82 ++ lib.optionals python.hasDistutilsCxxPatch [ ./numpy-distutils-C++.patch ];
85 # fails with multiple errors because we are not using the pinned setuptools version
86 # see https://github.com/numpy/numpy/blob/v1.25.0/pyproject.toml#L7
87 # error: option --single-version-externally-managed not recognized
88 # TypeError: dist must be a Distribution instance
89 rm numpy/core/tests/test_cython.py
91 patchShebangs numpy/_build_utils/*.py
93 # remove needless reference to full Python path stored in built wheel
94 substituteInPlace numpy/meson.build \
95 --replace 'py.full_path()' "'python'"
97 substituteInPlace pyproject.toml \
98 --replace-fail "meson-python>=0.15.0,<0.16.0" "meson-python"
108 ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ xcbuild.xcrun ]
109 ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ mesonEmulatorHook ];
116 # Causes `error: argument unused during compilation: '-fno-strict-overflow'` due to `-Werror`.
117 hardeningDisable = lib.optionals stdenv.cc.isClang [ "strictoverflow" ];
119 # we default openblas to build with 64 threads
120 # if a machine has more than 64 threads, it will segfault
121 # see https://github.com/OpenMathLib/OpenBLAS/issues/2993
123 sed -i 's/-faltivec//' numpy/distutils/system_info.py
124 export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES))
127 # HACK: copy mesonEmulatorHook's flags to the variable used by meson-python
129 mesonFlags="$mesonFlags ''${mesonFlagsArray[@]}"
133 ln -s ${cfg} site.cfg
136 enableParallelBuilding = true;
138 nativeCheckInputs = [
150 # https://github.com/numpy/numpy/blob/a277f6210739c11028f281b8495faf7da298dbef/numpy/_pytesttester.py#L180
153 "not\\ slow" # fast test suite
156 # https://github.com/numpy/numpy/issues/24548
159 # Tries to import numpy.distutils.msvccompiler, removed in setuptools 74.0
160 "test_api_importable"
162 ++ lib.optionals stdenv.hostPlatform.isi686 [
163 "test_new_policy" # AssertionError: assert False
164 "test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded
165 "test_float_remainder_overflow" # AssertionError: FloatingPointError not raised by divmod
166 "test_int" # AssertionError: selectedintkind(19): expected 16 but got -1
168 ++ lib.optionals stdenv.hostPlatform.isAarch32 [
169 "test_impossible_feature_enable" # AssertionError: Failed to generate error
170 "test_features" # AssertionError: Failure Detection
171 "test_new_policy" # AssertionError: assert False
172 "test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded
173 "test_unary_spurious_fpexception" # AssertionError: Got warnings: [<warnings.WarningMessage object at 0xd1197430>]
174 "test_int" # AssertionError: selectedintkind(19): expected 16 but got -1
175 "test_real" # AssertionError: selectedrealkind(16): expected 10 but got -1
176 "test_quad_precision" # AssertionError: selectedrealkind(32): expected 16 but got -1
177 "test_big_arrays" # ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger tha...
178 "test_multinomial_pvals_float32" # Failed: DID NOT RAISE <class 'ValueError'>
180 ++ lib.optionals stdenv.hostPlatform.isAarch64 [
181 "test_big_arrays" # OOM on a 16G machine
183 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
184 # can fail on virtualized machines confused over their cpu identity
189 # just for backwards compatibility
190 blas = blas.provider;
191 blasImplementation = blas.implementation;
193 coreIncludeDir = "${numpy_1}/${python.sitePackages}/numpy/core/include";
200 # - test_large_file_support: takes a long time and can cause the machine to run out of disk space
201 env.NOSE_EXCLUDE = "test_large_file_support";
204 changelog = "https://github.com/numpy/numpy/releases/tag/v${version}";
205 description = "Scientific tools for Python";
206 mainProgram = "f2py";
207 homepage = "https://numpy.org/";
208 license = lib.licenses.bsd3;