From: "Marek Szuba" <marecki@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/numpy/, dev-python/numpy/files/
Date: Fri, 14 May 2021 21:39:11 +0000 (UTC) [thread overview]
Message-ID: <1621028341.8901b5e61974c1e6df76de1cd86b72f417ee4221.marecki@gentoo> (raw)
commit: 8901b5e61974c1e6df76de1cd86b72f417ee4221
Author: Marek Szuba <marecki <AT> gentoo <DOT> org>
AuthorDate: Fri May 14 21:22:11 2021 +0000
Commit: Marek Szuba <marecki <AT> gentoo <DOT> org>
CommitDate: Fri May 14 21:39:01 2021 +0000
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8901b5e6
dev-python/numpy: support python3_10
Needed one commit to be backported from master. Now it builds, tests and
installs fine.
Signed-off-by: Marek Szuba <marecki <AT> gentoo.org>
.../files/numpy-1.20.3-float-hashing-py310.patch | 129 +++++++++++++++++++++
dev-python/numpy/numpy-1.20.3.ebuild | 3 +-
2 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/dev-python/numpy/files/numpy-1.20.3-float-hashing-py310.patch b/dev-python/numpy/files/numpy-1.20.3-float-hashing-py310.patch
new file mode 100644
index 00000000000..f3b2ea3ef0c
--- /dev/null
+++ b/dev-python/numpy/files/numpy-1.20.3-float-hashing-py310.patch
@@ -0,0 +1,129 @@
+From ad2a73c18dcff95d844c382c94ab7f73b5571cf3 Mon Sep 17 00:00:00 2001
+From: Sebastian Berg <sebastian@sipsolutions.net>
+Date: Tue, 4 May 2021 17:43:26 -0500
+Subject: [PATCH] MAINT: Adjust NumPy float hashing to Python's slightly
+ changed hash
+
+This is necessary, since we use the Python double hash and the
+semi-private function to calculate it in Python has a new signature
+to return the identity-hash when the value is NaN.
+
+closes gh-18833, gh-18907
+---
+ numpy/core/src/common/npy_pycompat.h | 16 ++++++++++
+ numpy/core/src/multiarray/scalartypes.c.src | 13 ++++----
+ numpy/core/tests/test_scalarmath.py | 34 +++++++++++++++++++++
+ 3 files changed, 57 insertions(+), 6 deletions(-)
+
+diff --git a/numpy/core/src/common/npy_pycompat.h b/numpy/core/src/common/npy_pycompat.h
+index aa0b5c1224d..9e94a971090 100644
+--- a/numpy/core/src/common/npy_pycompat.h
++++ b/numpy/core/src/common/npy_pycompat.h
+@@ -3,4 +3,20 @@
+
+ #include "numpy/npy_3kcompat.h"
+
++
++/*
++ * In Python 3.10a7 (or b1), python started using the identity for the hash
++ * when a value is NaN. See https://bugs.python.org/issue43475
++ */
++#if PY_VERSION_HEX > 0x030a00a6
++#define Npy_HashDouble _Py_HashDouble
++#else
++static NPY_INLINE Py_hash_t
++Npy_HashDouble(PyObject *NPY_UNUSED(identity), double val)
++{
++ return _Py_HashDouble(val);
++}
++#endif
++
++
+ #endif /* _NPY_COMPAT_H_ */
+diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
+index a001500b0a9..9930f7791d6 100644
+--- a/numpy/core/src/multiarray/scalartypes.c.src
++++ b/numpy/core/src/multiarray/scalartypes.c.src
+@@ -3172,7 +3172,7 @@ static npy_hash_t
+ static npy_hash_t
+ @lname@_arrtype_hash(PyObject *obj)
+ {
+- return _Py_HashDouble((double) PyArrayScalar_VAL(obj, @name@));
++ return Npy_HashDouble(obj, (double)PyArrayScalar_VAL(obj, @name@));
+ }
+
+ /* borrowed from complex_hash */
+@@ -3180,14 +3180,14 @@ static npy_hash_t
+ c@lname@_arrtype_hash(PyObject *obj)
+ {
+ npy_hash_t hashreal, hashimag, combined;
+- hashreal = _Py_HashDouble((double)
+- PyArrayScalar_VAL(obj, C@name@).real);
++ hashreal = Npy_HashDouble(
++ obj, (double)PyArrayScalar_VAL(obj, C@name@).real);
+
+ if (hashreal == -1) {
+ return -1;
+ }
+- hashimag = _Py_HashDouble((double)
+- PyArrayScalar_VAL(obj, C@name@).imag);
++ hashimag = Npy_HashDouble(
++ obj, (double)PyArrayScalar_VAL(obj, C@name@).imag);
+ if (hashimag == -1) {
+ return -1;
+ }
+@@ -3202,7 +3202,8 @@ c@lname@_arrtype_hash(PyObject *obj)
+ static npy_hash_t
+ half_arrtype_hash(PyObject *obj)
+ {
+- return _Py_HashDouble(npy_half_to_double(PyArrayScalar_VAL(obj, Half)));
++ return Npy_HashDouble(
++ obj, npy_half_to_double(PyArrayScalar_VAL(obj, Half)));
+ }
+
+ static npy_hash_t
+diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
+index d91b4a39146..09a734284a7 100644
+--- a/numpy/core/tests/test_scalarmath.py
++++ b/numpy/core/tests/test_scalarmath.py
+@@ -712,6 +712,40 @@ def test_shift_all_bits(self, type_code, op):
+ assert_equal(res_arr, res_scl)
+
+
++class TestHash:
++ @pytest.mark.parametrize("type_code", np.typecodes['AllInteger'])
++ def test_integer_hashes(self, type_code):
++ scalar = np.dtype(type_code).type
++ for i in range(128):
++ assert hash(i) == hash(scalar(i))
++
++ @pytest.mark.parametrize("type_code", np.typecodes['AllFloat'])
++ def test_float_and_complex_hashes(self, type_code):
++ scalar = np.dtype(type_code).type
++ for val in [np.pi, np.inf, 3, 6.]:
++ numpy_val = scalar(val)
++ # Cast back to Python, in case the NumPy scalar has less precision
++ if numpy_val.dtype.kind == 'c':
++ val = complex(numpy_val)
++ else:
++ val = float(numpy_val)
++ assert val == numpy_val
++ print(repr(numpy_val), repr(val))
++ assert hash(val) == hash(numpy_val)
++
++ if hash(float(np.nan)) != hash(float(np.nan)):
++ # If Python distinguises different NaNs we do so too (gh-18833)
++ assert hash(scalar(np.nan)) != hash(scalar(np.nan))
++
++ @pytest.mark.parametrize("type_code", np.typecodes['Complex'])
++ def test_complex_hashes(self, type_code):
++ # Test some complex valued hashes specifically:
++ scalar = np.dtype(type_code).type
++ for val in [np.pi+1j, np.inf-3j, 3j, 6.+1j]:
++ numpy_val = scalar(val)
++ assert hash(complex(numpy_val)) == hash(numpy_val)
++
++
+ @contextlib.contextmanager
+ def recursionlimit(n):
+ o = sys.getrecursionlimit()
diff --git a/dev-python/numpy/numpy-1.20.3.ebuild b/dev-python/numpy/numpy-1.20.3.ebuild
index 10bbd07b87e..5b772a58a6f 100644
--- a/dev-python/numpy/numpy-1.20.3.ebuild
+++ b/dev-python/numpy/numpy-1.20.3.ebuild
@@ -3,7 +3,7 @@
EAPI=7
-PYTHON_COMPAT=( python3_{7..9} )
+PYTHON_COMPAT=( python3_{7..10} )
PYTHON_REQ_USE="threads(+)"
FORTRAN_NEEDED=lapack
@@ -46,6 +46,7 @@ BDEPEND="
PATCHES=(
"${FILESDIR}"/numpy-1.20.1-no-hardcode-blasv2.patch
"${FILESDIR}"/numpy-1.20.2-fix-ccompiler-tests.patch
+ "${FILESDIR}"/numpy-1.20.3-float-hashing-py310.patch
)
distutils_enable_tests pytest
next reply other threads:[~2021-05-14 21:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-14 21:39 Marek Szuba [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-10-31 19:19 [gentoo-commits] repo/gentoo:master commit in: dev-python/numpy/, dev-python/numpy/files/ Michał Górny
2024-07-22 1:20 Michał Górny
2023-11-07 20:35 Sam James
2023-08-22 4:12 Michał Górny
2023-08-01 6:48 Sam James
2023-07-23 21:43 Sam James
2023-06-26 13:14 Sam James
2022-12-03 17:01 Michał Górny
2022-10-25 8:21 Sam James
2022-10-08 13:52 Michał Górny
2021-12-31 22:49 Sam James
2021-09-08 6:16 Michał Górny
2021-05-24 22:09 Sam James
2021-04-30 20:25 Michał Górny
2021-03-28 9:48 Michał Górny
2020-09-16 10:13 Michał Górny
2020-02-26 19:46 David Seifert
2019-11-20 1:24 Patrick McLean
2019-06-23 12:47 Benda XU
2019-01-08 18:54 Virgil Dupras
2018-07-15 22:22 Michał Górny
2018-07-14 21:44 Michał Górny
2016-10-18 20:02 David Seifert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1621028341.8901b5e61974c1e6df76de1cd86b72f417ee4221.marecki@gentoo \
--to=marecki@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox