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.
This commit is contained in:
parent
8e12c817e9
commit
4f923aa46c
|
@ -72,6 +72,12 @@ in buildPythonPackage rec {
|
|||
url = "https://github.com/numpy/numpy/commit/afcedf4b63f4a94187e6995c2adea0da3bb18e83.patch";
|
||||
hash = "sha256-cxBoimX5a9wC2qUIGAo5o/M2E9+eV63bV2/wLmfDYKg=";
|
||||
})
|
||||
]
|
||||
++ 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
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
|
||||
index 6951d41e4..eefe86ad4 100644
|
||||
--- a/numpy/core/tests/test_umath.py
|
||||
+++ b/numpy/core/tests/test_umath.py
|
||||
@@ -4180,7 +4180,17 @@ def test_against_cmath(self):
|
||||
)
|
||||
@pytest.mark.xfail(IS_MUSL, reason="gh23049")
|
||||
@pytest.mark.xfail(IS_WASM, reason="doesn't work")
|
||||
- @pytest.mark.parametrize('dtype', [np.complex64, np.complex_, np.longcomplex])
|
||||
+ @pytest.mark.parametrize('dtype', [
|
||||
+ np.complex64,
|
||||
+ np.complex_,
|
||||
+ pytest.param(
|
||||
+ np.longcomplex,
|
||||
+ marks=pytest.mark.skipif(
|
||||
+ sys.platform == "darwin" and platform.machine() == "x86_64",
|
||||
+ reason="doesn’t work under Rosetta 2",
|
||||
+ ),
|
||||
+ ),
|
||||
+ ])
|
||||
def test_loss_of_precision(self, dtype):
|
||||
"""Check loss of precision in complex arc* functions"""
|
||||
|
Loading…
Reference in a new issue