summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2022-01-31 22:25:13 +0200
committerGitHub <noreply@github.com>2022-01-31 22:25:13 +0200
commitc65bc212ec1987caefba0ea7efe6a55803318de9 (patch)
tree84da14c460e3ec4fa674d2057d6a25e211974da1
parent862994cbc20bde948b7066560fda20717d978d78 (diff)
parent2b3a279eb74e1a19297aefbf0c05c0b9f5ed2835 (diff)
downloadnumpy-c65bc212ec1987caefba0ea7efe6a55803318de9.tar.gz
Merge pull request #20955 from seberg/issue-20921
BUG: Fix incorrect return type in reduce without initial value
-rw-r--r--numpy/core/src/umath/reduction.c2
-rw-r--r--numpy/core/tests/test_ufunc.py12
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/core/src/umath/reduction.c b/numpy/core/src/umath/reduction.c
index 8c4df6e02..817f99a04 100644
--- a/numpy/core/src/umath/reduction.c
+++ b/numpy/core/src/umath/reduction.c
@@ -68,7 +68,7 @@ count_axes(int ndim, const npy_bool *axis_flags)
* Returns -1 if an error occurred, and otherwise the reduce arrays size,
* which is the number of elements already initialized.
*/
-NPY_NO_EXPORT int
+static npy_intp
PyArray_CopyInitialReduceValues(
PyArrayObject *result, PyArrayObject *operand,
const npy_bool *axis_flags, const char *funcname,
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 9a9d46da0..41f9778b6 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -14,6 +14,7 @@ from numpy.testing import (
assert_almost_equal, assert_array_almost_equal, assert_no_warnings,
assert_allclose, HAS_REFCOUNT, suppress_warnings
)
+from numpy.testing._private.utils import requires_memory
from numpy.compat import pickle
@@ -1555,6 +1556,17 @@ class TestUfunc:
[[0, 1, 1], [1, 1, 1]])
assert_equal(np.minimum.reduce(a, axis=()), a)
+ @requires_memory(6 * 1024**3)
+ def test_identityless_reduction_huge_array(self):
+ # Regression test for gh-20921 (copying identity incorrectly failed)
+ arr = np.zeros((2, 2**31), 'uint8')
+ arr[:, 0] = [1, 3]
+ arr[:, -1] = [4, 1]
+ res = np.maximum.reduce(arr, axis=0)
+ del arr
+ assert res[0] == 3
+ assert res[-1] == 4
+
def test_identityless_reduction_corder(self):
a = np.empty((2, 3, 4), order='C')
self.check_identityless_reduction(a)