add forgotten patches from main repo

This commit is contained in:
Andreas Billmeier 2021-06-12 18:32:15 +02:00 committed by Andreas Billmeier
parent 746e7bf2e2
commit 51268318fc
Signed by: onkelbeh
GPG Key ID: E6DB12C8C550F3C0
3 changed files with 234 additions and 0 deletions

View File

@ -1,6 +1,8 @@
AUX numpy-1.17.4-no-hardcode-blasv2.patch 2420 BLAKE2B e4c0058b1226fced2c38caf67b2843021c6f42773781668a556eb48d7038acd0b1c7cbf30a432fdc3f4d2abf8eef28df7102be1bc9669a4ddc4ee4fc5e239d68 SHA512 9c6dc7e4f5b28b24ac5e1c686066c973b218b0e4e07b500a52c8b3e247acb150714072d17dd1a8579f47c48e9776bddebf9f049616aca52e0325c8f09ef09dad
AUX numpy-1.20.1-no-hardcode-blasv2.patch 2582 BLAKE2B 5057f925a12e6703ab5d9d4c342db80f7f5a7f02a5b5884bd9fac574dcadb9234901b08b1b2ca5bc5ba0345a58e896a241e3a48b4b050b2f5a1063324359d84c SHA512 4418b9c5ed3842848bc06a56ebbd7cd9261657e407775374f2f060944522128d8a5178888def6e4cf42ff6d81082d9cc1425d9553c5334ad4e728d0df9b86bc8
AUX numpy-1.20.2-fix-ccompiler-tests.patch 1616 BLAKE2B 3e2796029854207187322b1061201e7f014472c64d8c66a2dd3f82ec2eed7311f5cc3351d98aeb4b8b75d95608853066a30394e5316bb91e443744f33d66966b SHA512 5ed01b466a0da96b5d7c56b78e420d6c589c48c20053b9da66344384fa93048f90e281d3ed5caa9325f6afe00ff48841b24abc926c75aacb8a6bd5418ed32117
AUX numpy-1.20.2-fix-popcnt-detection.patch 2852 BLAKE2B c7b97d54649e33fecfa9cdd7e79fbd6a0f599648edd9a923a4d8ff428f774813d81f045e82905e236828608f4c969e56d681a828ed0190f86f8731a2c22401d8 SHA512 cb0e461b4ec788812fcdb528be18dcc04222c1aedb9ecef96d8f0ccefd407640dfb7d10b2bd392e0e40054b016a0d023f4a397432904496b793c8a2f1fba8f74
AUX numpy-1.20.3-float-hashing-py310.patch 4677 BLAKE2B 410438f8b9ba7bc346cd9fbb4d3087d60af6cc54b7ba4a839a1d9559d5b09db623932089ca8c34a70d30622d6260f3bff13fd2d97c94f6af437502f2e5b3c27d SHA512 a7605bf4db0886f4e7d4edd65c7b46d6b47ccb43140555cc86b35c2f003cdf29e8704593d77f7cc551f3be1550af209e7910a95e1421fe45b5d0ea5716d62588
DIST numpy-1.19.0.zip 7296082 BLAKE2B e388a1b8aa8fa5e23b57c69c5aa5f2b7b286a69fca6007843adbfa374d541ace7875757a302e851bc41194f565390b52777fff13da8166e7a2c6b0a0f3efd29c SHA512 24f8847ff6b72dd44db197fbd80596677f9f3c5afcc87f30c41a4c0a2ccd4ee652ca630a537997ba8fe68c4919fa488e9d8cadd9a310e5356b017f6086055850
DIST numpy-1.19.1.zip 7301568 BLAKE2B f7c17666d8cd4f477d7946be383d2ff1656c412e23dc49c55f94a6fcb95a6cffe6b4958169b1b27e027a7d674feb96de979d8bba4f1e3d9daef9b72e7f48cafa SHA512 ddc5f5e262d6f7f6e1a8879165860427baa237b6aad5b09d5b943a36bb0d5922424aac4c0e32a2cc3e14087bf6eb671988b6ff6df0d9ab8c89724e093220eead
DIST numpy-1.19.2.zip 7310530 BLAKE2B a019c64809bd61071a4dd5e10c2cdf6927f392ebe58b45a08529295079bca68a683502aba89847578e122271d2fa4ea6d2d5461f1e58322f550cda863d36125b SHA512 56ae348f08818e30b6675df7d41a2b03687af452d7a96356fccfce2994843c7b61918946381c3af25fe03f209413d0378ee691fc38d805491a12c464e49bb59c

View File

@ -0,0 +1,103 @@
https://github.com/numpy/numpy/pull/19074
https://bugs.gentoo.org/788184
From 8dc768964b5578a8aa9db1ef2c55134a00731e10 Mon Sep 17 00:00:00 2001
From: Carl Michal <michal@physics.ubc.ca>
Date: Sat, 22 May 2021 20:43:10 -0700
Subject: [PATCH 1/2] Fix compile-time test of POPCNT
The compile-time test of POPCNT, cpu_popcnt.c produced code that would
execute without error even if the machine didn't support the popcnt
instruction. This patch attempts to use popcnt on random numbers so the
compiler can't substitute the answer at compile time.
---
numpy/distutils/checks/cpu_popcnt.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/numpy/distutils/checks/cpu_popcnt.c b/numpy/distutils/checks/cpu_popcnt.c
index e6a80fb40be4..f6c785dd2a97 100644
--- a/numpy/distutils/checks/cpu_popcnt.c
+++ b/numpy/distutils/checks/cpu_popcnt.c
@@ -4,20 +4,26 @@
#include <popcntintrin.h>
#endif
+#include <stdlib.h>
+
int main(void)
{
long long a = 0;
int b;
+
+ a = random();
+ b = random();
+
#ifdef _MSC_VER
#ifdef _M_X64
- a = _mm_popcnt_u64(1);
+ a = _mm_popcnt_u64(a);
#endif
- b = _mm_popcnt_u32(1);
+ b = _mm_popcnt_u32(b);
#else
#ifdef __x86_64__
- a = __builtin_popcountll(1);
+ a = __builtin_popcountll(a);
#endif
- b = __builtin_popcount(1);
+ b = __builtin_popcount(b);
#endif
return (int)a + b;
}
From 52d5fe1ede45083d0783c3e2bbaee5c44df9d553 Mon Sep 17 00:00:00 2001
From: Carl Michal <michal@physics.ubc.ca>
Date: Sun, 23 May 2021 08:24:52 -0700
Subject: [PATCH 2/2] Change fix of cpu_popcnt.c to use
_mm_popcnt_u64/_mm_popcnt_u32 on GCC
_builtin_popcount is always available, so the compile-time check always
succeeds.
---
numpy/distutils/checks/cpu_popcnt.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/numpy/distutils/checks/cpu_popcnt.c b/numpy/distutils/checks/cpu_popcnt.c
index f6c785dd2a97..540c98dab05d 100644
--- a/numpy/distutils/checks/cpu_popcnt.c
+++ b/numpy/distutils/checks/cpu_popcnt.c
@@ -4,26 +4,16 @@
#include <popcntintrin.h>
#endif
-#include <stdlib.h>
-
-int main(void)
+int main(int argc, char **argv)
{
- long long a = 0;
- int b;
-
- a = random();
- b = random();
-
-#ifdef _MSC_VER
- #ifdef _M_X64
+ // To make sure popcnt instructions are generated
+ // and been tested against the assembler
+ unsigned long long a = *((unsigned long long*)argv[argc-1]);
+ unsigned int b = *((unsigned int*)argv[argc-2]);
+
+#if defined(_M_X64) || defined(__x86_64__)
a = _mm_popcnt_u64(a);
- #endif
- b = _mm_popcnt_u32(b);
-#else
- #ifdef __x86_64__
- a = __builtin_popcountll(a);
- #endif
- b = __builtin_popcount(b);
#endif
+ b = _mm_popcnt_u32(b);
return (int)a + b;
}

View File

@ -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()