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,
|
2024-07-22 17:48:17 +03:00
|
|
|
numpy_2,
|
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,
|
2024-05-22 16:01:06 +02:00
|
|
|
|
2023-10-28 23:04:01 +02:00
|
|
|
# build-system
|
2024-03-24 03:25:37 +01:00
|
|
|
cython,
|
2020-01-03 12:52:42 +01:00
|
|
|
gfortran,
|
2023-10-28 23:04:01 +02:00
|
|
|
meson-python,
|
2023-11-19 16:10:11 -06:00
|
|
|
mesonEmulatorHook,
|
2023-10-28 23:04:01 +02:00
|
|
|
pkg-config,
|
|
|
|
xcbuild,
|
2024-05-22 16:01:06 +02:00
|
|
|
|
2023-10-28 23:04:01 +02:00
|
|
|
# native dependencies
|
|
|
|
blas,
|
|
|
|
lapack,
|
2024-05-22 16:01:06 +02:00
|
|
|
|
2024-05-06 14:13:20 +02:00
|
|
|
# Reverse dependency
|
|
|
|
sage,
|
2024-05-22 16:01:06 +02:00
|
|
|
|
2023-10-28 23:04:01 +02:00
|
|
|
# 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";
|
2025-05-18 12:37:47 +03:00
|
|
|
version = "2.2.6";
|
2023-10-28 23:04:01 +02:00
|
|
|
pyproject = true;
|
2024-05-11 14:58:24 +02:00
|
|
|
|
|
|
|
disabled = pythonOlder "3.10";
|
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";
|
2025-05-18 12:37:47 +03:00
|
|
|
hash = "sha256-4pVU4r71SpCqXMB9ps6VWsy4PyGrXeAaYshHiJeyZP0=";
|
2017-05-16 09:22:07 +02:00
|
|
|
};
|
2016-02-04 21:30:39 +01:00
|
|
|
|
2024-05-11 14:58:24 +02:00
|
|
|
patches = lib.optionals python.hasDistutilsCxxPatch [
|
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.
|
2024-05-11 14:58:24 +02:00
|
|
|
./numpy-distutils-C++.patch
|
|
|
|
];
|
2016-10-15 17:51:09 -04:00
|
|
|
|
2023-06-28 22:24:06 +02:00
|
|
|
postPatch = ''
|
2023-11-19 16:06:47 -06:00
|
|
|
# remove needless reference to full Python path stored in built wheel
|
|
|
|
substituteInPlace numpy/meson.build \
|
2024-05-11 14:58:24 +02:00
|
|
|
--replace-fail 'py.full_path()' "'python'"
|
2023-06-28 22:24:06 +02:00
|
|
|
'';
|
|
|
|
|
2024-05-11 14:58:24 +02:00
|
|
|
build-system =
|
2023-10-28 23:04:01 +02:00
|
|
|
[
|
2024-03-24 03:25:37 +01:00
|
|
|
cython
|
2023-10-28 23:04:01 +02:00
|
|
|
gfortran
|
|
|
|
meson-python
|
|
|
|
pkg-config
|
2024-05-22 16:01:06 +02:00
|
|
|
]
|
2024-05-11 14:58:24 +02:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcrun ]
|
2023-11-19 16:10:11 -06:00
|
|
|
++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ mesonEmulatorHook ];
|
2023-10-28 23:04:01 +02:00
|
|
|
|
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
|
2024-01-29 18:16:32 +01:00
|
|
|
# see https://github.com/OpenMathLib/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
|
|
|
'';
|
|
|
|
|
2024-05-11 14:58:24 +02:00
|
|
|
buildInputs = [
|
|
|
|
blas
|
|
|
|
lapack
|
|
|
|
];
|
|
|
|
|
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-05-22 18:19:06 +02:00
|
|
|
hypothesis
|
2024-05-11 14:58:24 +02:00
|
|
|
pytestCheckHook
|
|
|
|
pytest-xdist
|
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 = ''
|
2024-05-11 14:58:24 +02:00
|
|
|
pushd $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
postCheck = ''
|
|
|
|
popd
|
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
|
|
|
|
];
|
|
|
|
|
|
|
|
disabledTests =
|
2024-10-03 01:55:47 +02:00
|
|
|
[
|
|
|
|
# Tries to import numpy.distutils.msvccompiler, removed in setuptools 74.0
|
|
|
|
"test_api_importable"
|
|
|
|
]
|
|
|
|
++ lib.optionals (pythonAtLeast "3.13") [
|
2024-05-11 14:58:24 +02:00
|
|
|
# https://github.com/numpy/numpy/issues/26713
|
|
|
|
"test_iter_refcount"
|
2023-08-28 09:10:49 +03:00
|
|
|
]
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isAarch32 [
|
2024-05-11 14:58:24 +02:00
|
|
|
# https://github.com/numpy/numpy/issues/24548
|
2023-08-28 09:10:49 +03:00
|
|
|
"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'>
|
|
|
|
]
|
2024-02-10 14:19:17 +00:00
|
|
|
++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [
|
2024-05-11 14:58:24 +02:00
|
|
|
# AssertionError: (np.int64(0), np.longdouble('9.9999999999999994515e-21'), np.longdouble('3.9696755572509052902e+20'), 'arctanh')
|
|
|
|
"test_loss_of_precision"
|
2025-04-14 13:48:52 +00:00
|
|
|
]
|
|
|
|
++ lib.optionals (stdenv.hostPlatform ? gcc.arch) [
|
|
|
|
# remove if https://github.com/numpy/numpy/issues/27460 is resolved
|
|
|
|
"test_validate_transcendentals"
|
2023-08-28 09:10:49 +03:00
|
|
|
];
|
|
|
|
|
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;
|
2024-07-22 17:48:17 +03:00
|
|
|
coreIncludeDir = "${numpy_2}/${python.sitePackages}/numpy/_core/include";
|
2024-05-06 14:13:20 +02:00
|
|
|
tests = {
|
|
|
|
inherit sage;
|
|
|
|
};
|
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;
|
2024-09-04 23:51:37 +03:00
|
|
|
maintainers = with lib.maintainers; [ doronbehar ];
|
2017-05-16 09:22:07 +02:00
|
|
|
};
|
2023-07-20 10:28:02 +02:00
|
|
|
}
|