commit:     fb1e7ebd3b199eadab7869aca983bc5e8b3ead85
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 24 20:50:38 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Oct 24 20:52:01 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fb1e7ebd

dev-python/numpy: Backport unaligned access fix

Closes: https://bugs.gentoo.org/805974
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../numpy/files/numpy-1.21.3-unaligned-array.patch | 45 ++++++++++++++++++++++
 ...{numpy-1.21.1.ebuild => numpy-1.21.1-r1.ebuild} |  1 +
 ...{numpy-1.21.3.ebuild => numpy-1.21.2-r1.ebuild} |  1 +
 ...{numpy-1.21.2.ebuild => numpy-1.21.3-r1.ebuild} |  1 +
 4 files changed, 48 insertions(+)

diff --git a/dev-python/numpy/files/numpy-1.21.3-unaligned-array.patch 
b/dev-python/numpy/files/numpy-1.21.3-unaligned-array.patch
new file mode 100644
index 00000000000..8d04cc0968d
--- /dev/null
+++ b/dev-python/numpy/files/numpy-1.21.3-unaligned-array.patch
@@ -0,0 +1,45 @@
+From d9bbd60d0f2896d1b1f865e6035dccb12db4b1a0 Mon Sep 17 00:00:00 2001
+From: Sebastian Berg <[email protected]>
+Date: Sat, 23 Oct 2021 22:54:21 -0500
+Subject: [PATCH] BUG: Do not use nonzero fastpath on unaligned arrays
+
+The fast-path does not handle unalgined access, previously only
+bools had a fast path (and bools are by definition always aligned
+since they are stored in a single byte/char).
+
+Closes gh-19592
+---
+ numpy/core/src/multiarray/item_selection.c | 19 +++++++------------
+ 1 file changed, 7 insertions(+), 12 deletions(-)
+
+diff --git a/numpy/core/src/multiarray/item_selection.c 
b/numpy/core/src/multiarray/item_selection.c
+index ee66378a938..33d378c2b58 100644
+--- a/numpy/core/src/multiarray/item_selection.c
++++ b/numpy/core/src/multiarray/item_selection.c
+@@ -2398,19 +2398,14 @@ PyArray_CountNonzero(PyArrayObject *self)
+     npy_intp *strideptr, *innersizeptr;
+     NPY_BEGIN_THREADS_DEF;
+ 
+-    // Special low-overhead version specific to the boolean/int types
+     dtype = PyArray_DESCR(self);
+-    switch(dtype->kind) {
+-        case 'u':
+-        case 'i':
+-        case 'b':
+-            if (dtype->elsize > 8) {
+-                break;
+-            }
+-            return count_nonzero_int(
+-                PyArray_NDIM(self), PyArray_BYTES(self), PyArray_DIMS(self),
+-                PyArray_STRIDES(self), dtype->elsize
+-            );
++    /* Special low-overhead version specific to the boolean/int types */
++    if (PyArray_ISALIGNED(self) && (
++            PyDataType_ISBOOL(dtype) || PyDataType_ISINTEGER(dtype))) {
++        return count_nonzero_int(
++            PyArray_NDIM(self), PyArray_BYTES(self), PyArray_DIMS(self),
++            PyArray_STRIDES(self), dtype->elsize
++        );
+     }
+ 
+     nonzero = PyArray_DESCR(self)->f->nonzero;

diff --git a/dev-python/numpy/numpy-1.21.1.ebuild 
b/dev-python/numpy/numpy-1.21.1-r1.ebuild
similarity index 98%
rename from dev-python/numpy/numpy-1.21.1.ebuild
rename to dev-python/numpy/numpy-1.21.1-r1.ebuild
index 080c7b210c9..b25c2008d41 100644
--- a/dev-python/numpy/numpy-1.21.1.ebuild
+++ b/dev-python/numpy/numpy-1.21.1-r1.ebuild
@@ -45,6 +45,7 @@ BDEPEND="
 
 PATCHES=(
        "${FILESDIR}"/numpy-1.21.0-no-hardcode-blasv2.patch
+       "${FILESDIR}"/numpy-1.21.3-unaligned-array.patch
 )
 
 distutils_enable_tests pytest

diff --git a/dev-python/numpy/numpy-1.21.3.ebuild 
b/dev-python/numpy/numpy-1.21.2-r1.ebuild
similarity index 98%
rename from dev-python/numpy/numpy-1.21.3.ebuild
rename to dev-python/numpy/numpy-1.21.2-r1.ebuild
index cd54f4bc4a6..be58d11ab9f 100644
--- a/dev-python/numpy/numpy-1.21.3.ebuild
+++ b/dev-python/numpy/numpy-1.21.2-r1.ebuild
@@ -45,6 +45,7 @@ BDEPEND="
 
 PATCHES=(
        "${FILESDIR}"/numpy-1.21.0-no-hardcode-blasv2.patch
+       "${FILESDIR}"/numpy-1.21.3-unaligned-array.patch
 )
 
 distutils_enable_tests pytest

diff --git a/dev-python/numpy/numpy-1.21.2.ebuild 
b/dev-python/numpy/numpy-1.21.3-r1.ebuild
similarity index 98%
rename from dev-python/numpy/numpy-1.21.2.ebuild
rename to dev-python/numpy/numpy-1.21.3-r1.ebuild
index cd54f4bc4a6..d9b1d09193d 100644
--- a/dev-python/numpy/numpy-1.21.2.ebuild
+++ b/dev-python/numpy/numpy-1.21.3-r1.ebuild
@@ -45,6 +45,7 @@ BDEPEND="
 
 PATCHES=(
        "${FILESDIR}"/numpy-1.21.0-no-hardcode-blasv2.patch
+       "${FILESDIR}"/${P}-unaligned-array.patch
 )
 
 distutils_enable_tests pytest

Reply via email to