2020-04-24 23:36:52 +00:00
|
|
|
{ lib
|
2023-08-04 22:07:22 +00:00
|
|
|
, stdenv
|
2020-04-24 23:36:52 +00:00
|
|
|
, fetchPypi
|
2023-08-04 22:07:22 +00:00
|
|
|
, fetchpatch
|
2020-04-24 23:36:52 +00:00
|
|
|
, python
|
|
|
|
, buildPythonPackage
|
|
|
|
, gfortran
|
2020-09-25 04:45:31 +00:00
|
|
|
, hypothesis
|
2021-03-09 03:18:52 +00:00
|
|
|
, pytest
|
2022-08-12 12:06:08 +00:00
|
|
|
, typing-extensions
|
2020-04-24 23:36:52 +00:00
|
|
|
, blas
|
|
|
|
, lapack
|
|
|
|
, writeTextFile
|
|
|
|
, cython
|
2023-10-19 13:55:26 +00:00
|
|
|
, pythonAtLeast
|
2021-03-09 03:18:52 +00:00
|
|
|
, pythonOlder
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
assert (!blas.isILP64) && (!lapack.isILP64);
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = writeTextFile {
|
|
|
|
name = "site.cfg";
|
2023-08-04 22:07:22 +00:00
|
|
|
text = lib.generators.toINI {} {
|
2020-04-24 23:36:52 +00:00
|
|
|
${blas.implementation} = {
|
|
|
|
include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include";
|
|
|
|
library_dirs = "${blas}/lib:${lapack}/lib";
|
2020-09-25 04:45:31 +00:00
|
|
|
runtime_library_dirs = "${blas}/lib:${lapack}/lib";
|
2020-04-24 23:36:52 +00:00
|
|
|
libraries = "lapack,lapacke,blas,cblas";
|
|
|
|
};
|
2020-05-15 21:57:56 +00:00
|
|
|
lapack = {
|
|
|
|
include_dirs = "${lib.getDev lapack}/include";
|
|
|
|
library_dirs = "${lapack}/lib";
|
2020-09-25 04:45:31 +00:00
|
|
|
runtime_library_dirs = "${lapack}/lib";
|
2020-05-15 21:57:56 +00:00
|
|
|
};
|
|
|
|
blas = {
|
|
|
|
include_dirs = "${lib.getDev blas}/include";
|
|
|
|
library_dirs = "${blas}/lib";
|
2020-09-25 04:45:31 +00:00
|
|
|
runtime_library_dirs = "${blas}/lib";
|
2020-05-15 21:57:56 +00:00
|
|
|
};
|
2023-08-04 22:07:22 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2023-08-10 07:59:29 +00:00
|
|
|
in buildPythonPackage rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "numpy";
|
2023-08-10 07:59:29 +00:00
|
|
|
version = "1.25.1";
|
2022-09-30 11:47:45 +00:00
|
|
|
format = "setuptools";
|
2023-10-19 13:55:26 +00:00
|
|
|
disabled = pythonOlder "3.9" || pythonAtLeast "3.12";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2022-08-12 12:06:08 +00:00
|
|
|
extension = "tar.gz";
|
2023-08-10 07:59:29 +00:00
|
|
|
hash = "sha256-mjqfOmFIDMCGEXtCaovYaGnCE/xAcuYG8BxOS2brkr8=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
patches = [
|
2023-08-04 22:07:22 +00:00
|
|
|
# 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-08-10 07:59:29 +00:00
|
|
|
|
2023-08-04 22:07:22 +00: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-08-10 07:59:29 +00: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
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
2023-08-04 22:07:22 +00: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-30 11:47:45 +00:00
|
|
|
nativeBuildInputs = [ gfortran cython ];
|
2021-03-09 03:18:52 +00:00
|
|
|
buildInputs = [ blas lapack ];
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
# Causes `error: argument unused during compilation: '-fno-strict-overflow'` due to `-Werror`.
|
|
|
|
hardeningDisable = lib.optionals stdenv.cc.isClang [ "strictoverflow" ];
|
|
|
|
|
2020-11-21 19:51:51 +00: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
|
2020-04-24 23:36:52 +00:00
|
|
|
preConfigure = ''
|
|
|
|
sed -i 's/-faltivec//' numpy/distutils/system_info.py
|
|
|
|
export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES
|
2020-11-21 19:51:51 +00:00
|
|
|
export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 64 ? 64 : NIX_BUILD_CORES))
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
preBuild = ''
|
|
|
|
ln -s ${cfg} site.cfg
|
|
|
|
'';
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [
|
2021-03-09 03:18:52 +00:00
|
|
|
pytest
|
2023-07-15 17:15:38 +00:00
|
|
|
hypothesis
|
2022-08-12 12:06:08 +00:00
|
|
|
typing-extensions
|
2020-12-07 07:45:13 +00:00
|
|
|
];
|
2020-09-25 04:45:31 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
checkPhase = ''
|
|
|
|
runHook preCheck
|
2022-09-30 11:47:45 +00:00
|
|
|
pushd "$out"
|
2023-08-04 22:07:22 +00:00
|
|
|
${python.interpreter} -c 'import numpy, sys; sys.exit(numpy.test("fast", verbose=10) is False)'
|
2020-04-24 23:36:52 +00:00
|
|
|
popd
|
|
|
|
runHook postCheck
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
# just for backwards compatibility
|
|
|
|
blas = blas.provider;
|
|
|
|
blasImplementation = blas.implementation;
|
|
|
|
inherit cfg;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Disable test
|
|
|
|
# - test_large_file_support: takes a long time and can cause the machine to run out of disk space
|
|
|
|
NOSE_EXCLUDE="test_large_file_support";
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "Scientific tools for Python";
|
|
|
|
homepage = "https://numpy.org/";
|
2020-11-19 00:13:47 +00:00
|
|
|
license = lib.licenses.bsd3;
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with lib.maintainers; [ fridh ];
|
|
|
|
};
|
2023-08-10 07:59:29 +00:00
|
|
|
}
|