2020-01-03 12:52:42 +01:00
|
|
|
{ lib
|
2023-07-18 18:44:45 -06:00
|
|
|
, stdenv
|
2020-01-03 12:52:42 +01:00
|
|
|
, fetchPypi
|
|
|
|
, python
|
2023-10-28 23:04:01 +02:00
|
|
|
, pythonAtLeast
|
|
|
|
, pythonOlder
|
2020-01-03 12:52:42 +01:00
|
|
|
, buildPythonPackage
|
2023-10-28 23:04:01 +02:00
|
|
|
, writeTextFile
|
|
|
|
|
|
|
|
# build-system
|
|
|
|
, cython_3
|
2020-01-03 12:52:42 +01:00
|
|
|
, gfortran
|
2023-10-28 23:04:01 +02:00
|
|
|
, meson-python
|
|
|
|
, pkg-config
|
|
|
|
, xcbuild
|
|
|
|
|
|
|
|
# native dependencies
|
|
|
|
, blas
|
|
|
|
, lapack
|
|
|
|
|
|
|
|
# tests
|
2020-08-09 08:35:41 +02:00
|
|
|
, hypothesis
|
2023-10-28 23:04:01 +02:00
|
|
|
, pytest-xdist
|
2023-08-28 09:10:49 +03:00
|
|
|
, pytestCheckHook
|
2023-10-28 23:04:01 +02:00
|
|
|
, setuptools
|
2022-07-15 12:50:02 +02:00
|
|
|
, typing-extensions
|
2021-02-01 00:29:05 -05:00
|
|
|
}:
|
2016-02-04 21:30:39 +01:00
|
|
|
|
2020-04-20 15:50:55 -05:00
|
|
|
assert (!blas.isILP64) && (!lapack.isILP64);
|
2020-03-31 10:47:18 -04:00
|
|
|
|
2018-10-18 15:00:48 -04:00
|
|
|
let
|
|
|
|
cfg = writeTextFile {
|
|
|
|
name = "site.cfg";
|
2023-06-28 22:24:06 +02:00
|
|
|
text = lib.generators.toINI {} {
|
2020-03-31 10:47:18 -04:00
|
|
|
${blas.implementation} = {
|
2020-04-20 16:31:59 -04:00
|
|
|
include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include";
|
2020-03-31 10:47:18 -04:00
|
|
|
library_dirs = "${blas}/lib:${lapack}/lib";
|
2020-08-26 21:14:53 -05:00
|
|
|
runtime_library_dirs = "${blas}/lib:${lapack}/lib";
|
2020-04-20 13:53:29 -05:00
|
|
|
libraries = "lapack,lapacke,blas,cblas";
|
2018-10-18 15:00:48 -04:00
|
|
|
};
|
2020-05-07 16:26:55 -05:00
|
|
|
lapack = {
|
|
|
|
include_dirs = "${lib.getDev lapack}/include";
|
|
|
|
library_dirs = "${lapack}/lib";
|
2020-08-26 21:14:53 -05:00
|
|
|
runtime_library_dirs = "${lapack}/lib";
|
2020-05-07 16:26:55 -05:00
|
|
|
};
|
|
|
|
blas = {
|
|
|
|
include_dirs = "${lib.getDev blas}/include";
|
|
|
|
library_dirs = "${blas}/lib";
|
2020-08-26 21:14:53 -05:00
|
|
|
runtime_library_dirs = "${blas}/lib";
|
2020-05-07 16:26:55 -05:00
|
|
|
};
|
2023-06-28 22:24:06 +02:00
|
|
|
};
|
2018-10-18 15:00:48 -04:00
|
|
|
};
|
2023-07-20 10:28:02 +02:00
|
|
|
in buildPythonPackage rec {
|
2017-05-16 09:22:07 +02:00
|
|
|
pname = "numpy";
|
2023-10-28 23:04:01 +02:00
|
|
|
version = "1.26.1";
|
|
|
|
pyproject = true;
|
|
|
|
disabled = pythonOlder "3.9" || pythonAtLeast "3.13";
|
2016-02-04 21:30:39 +01:00
|
|
|
|
2017-09-28 10:50:50 +02:00
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2022-07-15 12:50:02 +02:00
|
|
|
extension = "tar.gz";
|
2023-10-28 23:04:01 +02:00
|
|
|
hash = "sha256-yMbHLUqfgx8yjvsTEmQqHK+vqoiYHZq3Y2jVDQfZPL4=";
|
2017-05-16 09:22:07 +02:00
|
|
|
};
|
2016-02-04 21:30:39 +01:00
|
|
|
|
2023-07-20 10:34:29 +02:00
|
|
|
patches = [
|
python3Packages.numpy: fix test failure on x86_64-darwin under Rosetta 2
The `atanhl` function is broken under Rosetta 2 with 80-bit long
doubles, which numpy uses to implement long double complex numbers. This
results in a test failure. Attempts were made to change the
implementation of things, but that just changed the breakage.
The following Swift program demonstrates the problem.
import Foundation
import Numerics
let x = Float80(1.00000000e-20)
let z = Complex(x)
print("X: \(x), Z: \(z)")
let x_atanh = Float80.atanh(x)
let z_atanh = Complex.atanh(z)
print("atanh:")
print("X: \(x_atanh), Z: \(z_atanh)")
let d = abs(x_atanh / z_atanh.real - 1)
print("d: \(d)")
On x86_64-darwin hardware, it prints the following:
X: 1e-20, Z: (1e-20, 0.0)
atanh:
X: 1e-20, Z: (1e-20, 0.0)
d: 0.0
On aarch64-darwin under Rosetta 2, it prints the following:
X: 1e-20, Z: (1e-20, 0.0)
atanh:
X: 1e-20, Z: (-1.0237493319595677839e-40, 0.0)
d: 9.7680161420558978584e+19
The latter is obviously incorrect. FB12656897 was submitted to Apple,
but even if this is fixed eventually, this derivation needs to build for
users (and Hydra) who aren’t on the latest version.
2023-07-18 18:34:38 -06:00
|
|
|
# Disable `numpy/core/tests/test_umath.py::TestComplexFunctions::test_loss_of_precision[complex256]`
|
|
|
|
# on x86_64-darwin because it fails under Rosetta 2 due to issues with trig functions and
|
|
|
|
# 80-bit long double complex numbers.
|
|
|
|
./disable-failing-long-double-test-Rosetta-2.patch
|
2023-07-20 10:34:29 +02:00
|
|
|
]
|
|
|
|
# We patch cpython/distutils to fix https://bugs.python.org/issue1222585
|
|
|
|
# Patching of numpy.distutils is needed to prevent it from undoing the
|
|
|
|
# patch to distutils.
|
|
|
|
++ lib.optionals python.hasDistutilsCxxPatch [
|
|
|
|
./numpy-distutils-C++.patch
|
2016-10-15 17:51:09 -04:00
|
|
|
];
|
|
|
|
|
2023-06-28 22:24:06 +02:00
|
|
|
postPatch = ''
|
|
|
|
# fails with multiple errors because we are not using the pinned setuptools version
|
|
|
|
# see https://github.com/numpy/numpy/blob/v1.25.0/pyproject.toml#L7
|
|
|
|
# error: option --single-version-externally-managed not recognized
|
|
|
|
# TypeError: dist must be a Distribution instance
|
|
|
|
rm numpy/core/tests/test_cython.py
|
2023-10-28 23:04:01 +02:00
|
|
|
|
|
|
|
patchShebangs numpy/_build_utils/*.py
|
2023-11-19 16:06:47 -06:00
|
|
|
|
|
|
|
# remove needless reference to full Python path stored in built wheel
|
|
|
|
substituteInPlace numpy/meson.build \
|
|
|
|
--replace 'py.full_path()' "'python'"
|
2023-06-28 22:24:06 +02:00
|
|
|
'';
|
|
|
|
|
2023-10-28 23:04:01 +02:00
|
|
|
nativeBuildInputs = [
|
|
|
|
cython_3
|
|
|
|
gfortran
|
|
|
|
meson-python
|
|
|
|
pkg-config
|
|
|
|
] ++ lib.optionals (stdenv.isDarwin) [
|
|
|
|
xcbuild.xcrun
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
blas
|
|
|
|
lapack
|
|
|
|
];
|
2021-02-01 00:29:05 -05:00
|
|
|
|
2023-07-20 10:28:02 +02:00
|
|
|
# Causes `error: argument unused during compilation: '-fno-strict-overflow'` due to `-Werror`.
|
|
|
|
hardeningDisable = lib.optionals stdenv.cc.isClang [ "strictoverflow" ];
|
|
|
|
|
2020-11-17 08:31:06 -08:00
|
|
|
# we default openblas to build with 64 threads
|
|
|
|
# if a machine has more than 64 threads, it will segfault
|
|
|
|
# see https://github.com/xianyi/OpenBLAS/issues/2993
|
2016-02-04 21:30:39 +01:00
|
|
|
preConfigure = ''
|
|
|
|
sed -i 's/-faltivec//' numpy/distutils/system_info.py
|
2020-11-17 08:31:06 -08:00
|
|
|
export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES))
|
2016-02-04 21:30:39 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
preBuild = ''
|
2018-10-18 15:00:48 -04:00
|
|
|
ln -s ${cfg} site.cfg
|
2016-02-04 21:30:39 +01:00
|
|
|
'';
|
|
|
|
|
2017-07-30 10:19:02 +02:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2023-01-21 12:00:00 +00:00
|
|
|
nativeCheckInputs = [
|
2023-10-28 23:04:01 +02:00
|
|
|
pytest-xdist
|
2023-08-28 09:10:49 +03:00
|
|
|
pytestCheckHook
|
2023-05-22 18:19:06 +02:00
|
|
|
hypothesis
|
2023-10-28 23:04:01 +02:00
|
|
|
setuptools
|
2022-07-15 12:50:02 +02:00
|
|
|
typing-extensions
|
2020-11-29 14:12:41 -08:00
|
|
|
];
|
2020-08-09 08:35:41 +02:00
|
|
|
|
2023-08-28 09:10:49 +03:00
|
|
|
preCheck = ''
|
|
|
|
cd "$out"
|
2016-02-04 21:30:39 +01:00
|
|
|
'';
|
|
|
|
|
2023-08-28 09:10:49 +03:00
|
|
|
# https://github.com/numpy/numpy/blob/a277f6210739c11028f281b8495faf7da298dbef/numpy/_pytesttester.py#L180
|
|
|
|
pytestFlagsArray = [
|
|
|
|
"-m" "not\\ slow" # fast test suite
|
|
|
|
];
|
|
|
|
|
|
|
|
# https://github.com/numpy/numpy/issues/24548
|
|
|
|
disabledTests = lib.optionals stdenv.isi686 [
|
|
|
|
"test_new_policy" # AssertionError: assert False
|
|
|
|
"test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded
|
|
|
|
"test_float_remainder_overflow" # AssertionError: FloatingPointError not raised by divmod
|
|
|
|
"test_int" # AssertionError: selectedintkind(19): expected 16 but got -1
|
|
|
|
] ++ lib.optionals stdenv.isAarch32 [
|
|
|
|
"test_impossible_feature_enable" # AssertionError: Failed to generate error
|
|
|
|
"test_features" # AssertionError: Failure Detection
|
|
|
|
"test_new_policy" # AssertionError: assert False
|
|
|
|
"test_identityless_reduction_huge_array" # ValueError: Maximum allowed dimension exceeded
|
|
|
|
"test_unary_spurious_fpexception"# AssertionError: Got warnings: [<warnings.WarningMessage object at 0xd1197430>]
|
|
|
|
"test_int" # AssertionError: selectedintkind(19): expected 16 but got -1
|
|
|
|
"test_real" # AssertionError: selectedrealkind(16): expected 10 but got -1
|
|
|
|
"test_quad_precision" # AssertionError: selectedrealkind(32): expected 16 but got -1
|
|
|
|
"test_big_arrays" # ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger tha...
|
|
|
|
"test_multinomial_pvals_float32" # Failed: DID NOT RAISE <class 'ValueError'>
|
|
|
|
] ++ lib.optionals stdenv.isAarch64 [
|
|
|
|
"test_big_arrays" # OOM on a 16G machine
|
|
|
|
];
|
|
|
|
|
2016-02-04 21:30:39 +01:00
|
|
|
passthru = {
|
2020-03-31 10:47:18 -04:00
|
|
|
# just for backwards compatibility
|
|
|
|
blas = blas.provider;
|
|
|
|
blasImplementation = blas.implementation;
|
|
|
|
inherit cfg;
|
2016-02-04 21:30:39 +01:00
|
|
|
};
|
|
|
|
|
2019-07-02 23:36:09 +02:00
|
|
|
# Disable test
|
2016-12-24 12:06:28 +01:00
|
|
|
# - test_large_file_support: takes a long time and can cause the machine to run out of disk space
|
2023-10-28 23:04:01 +02:00
|
|
|
env.NOSE_EXCLUDE = "test_large_file_support";
|
2016-02-04 21:30:39 +01:00
|
|
|
|
|
|
|
meta = {
|
2023-10-28 23:04:01 +02:00
|
|
|
changelog = "https://github.com/numpy/numpy/releases/tag/v${version}";
|
2016-02-04 21:30:39 +01:00
|
|
|
description = "Scientific tools for Python";
|
2020-03-31 21:11:51 -04:00
|
|
|
homepage = "https://numpy.org/";
|
2020-10-22 15:24:51 +02:00
|
|
|
license = lib.licenses.bsd3;
|
2016-02-04 21:30:39 +01:00
|
|
|
maintainers = with lib.maintainers; [ fridh ];
|
2017-05-16 09:22:07 +02:00
|
|
|
};
|
2023-07-20 10:28:02 +02:00
|
|
|
}
|