2020-04-24 23:36:52 +00:00
|
|
|
{ lib
|
|
|
|
, fetchPypi
|
2021-12-06 16:07:01 +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
|
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";
|
|
|
|
text = (lib.generators.toINI {} {
|
|
|
|
${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
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
in buildPythonPackage rec {
|
|
|
|
pname = "numpy";
|
2023-03-15 16:39:30 +00:00
|
|
|
version = "1.24.2";
|
2022-09-30 11:47:45 +00:00
|
|
|
format = "setuptools";
|
2021-03-09 03:18:52 +00:00
|
|
|
disabled = pythonOlder "3.7";
|
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-03-15 16:39:30 +00:00
|
|
|
hash = "sha256-ADqfUw6IDLLNF3y6GvciC5qkLe+cSvwqL8Pua+frKyI=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
patches = lib.optionals python.hasDistutilsCxxPatch [
|
2020-04-24 23:36:52 +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.
|
|
|
|
./numpy-distutils-C++.patch
|
|
|
|
];
|
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
nativeBuildInputs = [ gfortran cython ];
|
2021-03-09 03:18:52 +00:00
|
|
|
buildInputs = [ blas lapack ];
|
|
|
|
|
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-02-02 18:25:31 +00:00
|
|
|
# "hypothesis" indirectly depends on numpy to build its documentation.
|
|
|
|
(hypothesis.override { enableDocumentation = false; })
|
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"
|
2020-04-24 23:36:52 +00:00
|
|
|
${python.interpreter} -c 'import numpy; numpy.test("fast", verbose=10)'
|
|
|
|
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 ];
|
|
|
|
};
|
|
|
|
}
|