Skip to content

Commit f2a85cb

Browse files
authored
Merge pull request #20983 from charris/backport-20955
BUG: Fix incorrect return type in reduce without initial value
2 parents a6b059b + 2d05278 commit f2a85cb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎numpy/core/src/umath/reduction.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ count_axes(int ndim, const npy_bool *axis_flags)
6868
* Returns -1 if an error occurred, and otherwise the reduce arrays size,
6969
* which is the number of elements already initialized.
7070
*/
71-
NPY_NO_EXPORT int
71+
static npy_intp
7272
PyArray_CopyInitialReduceValues(
7373
PyArrayObject *result, PyArrayObject *operand,
7474
const npy_bool *axis_flags, const char *funcname,

‎numpy/core/tests/test_ufunc.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
assert_almost_equal, assert_array_almost_equal, assert_no_warnings,
1515
assert_allclose, HAS_REFCOUNT, suppress_warnings
1616
)
17+
from numpy.testing._private.utils import requires_memory
1718
from numpy.compat import pickle
1819

1920

@@ -1555,6 +1556,17 @@ def check_identityless_reduction(self, a):
15551556
[[0, 1, 1], [1, 1, 1]])
15561557
assert_equal(np.minimum.reduce(a, axis=()), a)
15571558

1559+
@requires_memory(6 * 1024**3)
1560+
def test_identityless_reduction_huge_array(self):
1561+
# Regression test for gh-20921 (copying identity incorrectly failed)
1562+
arr = np.zeros((2, 2**31), 'uint8')
1563+
arr[:, 0] = [1, 3]
1564+
arr[:, -1] = [4, 1]
1565+
res = np.maximum.reduce(arr, axis=0)
1566+
del arr
1567+
assert res[0] == 3
1568+
assert res[-1] == 4
1569+
15581570
def test_identityless_reduction_corder(self):
15591571
a = np.empty((2, 3, 4), order='C')
15601572
self.check_identityless_reduction(a)

0 commit comments

Comments
 (0)