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
|
2023-07-18 18:44:45 -06:00
|
|
|
|
, fetchpatch
|
2020-01-03 12:52:42 +01:00
|
|
|
|
, python
|
|
|
|
|
, buildPythonPackage
|
|
|
|
|
, gfortran
|
2020-08-09 08:35:41 +02:00
|
|
|
|
, hypothesis
|
2021-02-01 00:29:05 -05:00
|
|
|
|
, pytest
|
2022-07-15 12:50:02 +02:00
|
|
|
|
, typing-extensions
|
2020-01-03 12:52:42 +01:00
|
|
|
|
, blas
|
2020-03-31 10:47:18 -04:00
|
|
|
|
, lapack
|
2020-01-03 12:52:42 +01:00
|
|
|
|
, writeTextFile
|
|
|
|
|
, cython
|
2021-02-01 00:29:05 -05:00
|
|
|
|
, pythonOlder
|
|
|
|
|
}:
|
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-02-27 02:14:32 +01:00
|
|
|
|
version = "1.24.2";
|
2022-09-15 19:05:14 +02:00
|
|
|
|
format = "setuptools";
|
2021-02-01 00:29:05 -05:00
|
|
|
|
disabled = pythonOlder "3.7";
|
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-02-27 02:14:32 +01:00
|
|
|
|
hash = "sha256-ADqfUw6IDLLNF3y6GvciC5qkLe+cSvwqL8Pua+frKyI=";
|
2017-05-16 09:22:07 +02:00
|
|
|
|
};
|
2016-02-04 21:30:39 +01:00
|
|
|
|
|
2021-11-22 22:00:05 -08:00
|
|
|
|
patches = lib.optionals python.hasDistutilsCxxPatch [
|
2018-04-26 17:54:25 -04: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.
|
2016-10-15 17:51:09 -04:00
|
|
|
|
./numpy-distutils-C++.patch
|
2023-07-18 18:44:45 -06:00
|
|
|
|
]
|
|
|
|
|
++ lib.optionals stdenv.cc.isClang [
|
|
|
|
|
# f2py.f90mod_rules generates code with invalid function pointer conversions, which are
|
|
|
|
|
# clang 16 makes an error by default.
|
|
|
|
|
(fetchpatch {
|
|
|
|
|
url = "https://github.com/numpy/numpy/commit/609fee4324f3521d81a3454f5fcc33abb0d3761e.patch";
|
|
|
|
|
hash = "sha256-6Dbmf/RWvQJPTIjvchVaywHGcKCsgap/0wAp5WswuCo=";
|
|
|
|
|
})
|
2023-07-18 18:33:38 -06:00
|
|
|
|
]
|
|
|
|
|
++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
|
|
|
|
|
# Backport from 1.25. `platform.machine` returns `arm64` on aarch64-darwin, which causes
|
|
|
|
|
# differing results between `_selected_real_kind_func` and Fortran’s `selected_real_kind`.
|
|
|
|
|
(fetchpatch {
|
|
|
|
|
url = "https://github.com/numpy/numpy/commit/afcedf4b63f4a94187e6995c2adea0da3bb18e83.patch";
|
|
|
|
|
hash = "sha256-cxBoimX5a9wC2qUIGAo5o/M2E9+eV63bV2/wLmfDYKg=";
|
|
|
|
|
})
|
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
|
|
|
|
]
|
|
|
|
|
++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
|
|
|
|
|
# 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
|
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
|
|
|
|
|
'';
|
|
|
|
|
|
2022-09-15 19:05:14 +02:00
|
|
|
|
nativeBuildInputs = [ gfortran cython ];
|
2021-02-01 00:29:05 -05:00
|
|
|
|
buildInputs = [ blas lapack ];
|
|
|
|
|
|
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
|
2017-07-30 10:19:02 +02:00
|
|
|
|
export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES
|
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 = [
|
2021-02-01 00:29:05 -05:00
|
|
|
|
pytest
|
2023-05-22 18:19:06 +02:00
|
|
|
|
hypothesis
|
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
|
|
|
|
|
2016-02-04 21:30:39 +01:00
|
|
|
|
checkPhase = ''
|
|
|
|
|
runHook preCheck
|
2022-09-15 14:20:27 +02:00
|
|
|
|
pushd "$out"
|
2023-06-28 22:24:06 +02:00
|
|
|
|
${python.interpreter} -c 'import numpy, sys; sys.exit(numpy.test("fast", verbose=10) is False)'
|
2016-02-04 21:30:39 +01:00
|
|
|
|
popd
|
|
|
|
|
runHook postCheck
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
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
|
2019-07-02 23:36:09 +02:00
|
|
|
|
NOSE_EXCLUDE="test_large_file_support";
|
2016-02-04 21:30:39 +01:00
|
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
|
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
|
|
|
|
}
|