Skip to content

Commit 0cc52b5

Browse files
Luke Sewellrdbisme
authored andcommitted
Simplify iteration options for reduce_all
1 parent 65743d9 commit 0cc52b5

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

bottleneck/include/iterators.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,7 @@ static inline void init_iter_all(iter *it, PyArrayObject *a, int ravel, int anyo
9898
it->ndim_m2 = -1;
9999
it->length = 1;
100100
it->astride = 0;
101-
} else if (F_CONTIGUOUS(a) && !C_CONTIGUOUS(a) && ravel && !anyorder) {
102-
it->ndim_m2 = -1;
103-
a = (PyArrayObject *)PyArray_Ravel(a, NPY_CORDER);
104-
it->a_ravel = a;
105-
it->length = PyArray_DIM(a, 0);
106-
it->astride = PyArray_STRIDE(a, 0);
107-
} else if (C_CONTIGUOUS(a) || F_CONTIGUOUS(a)) {
101+
} else if (C_CONTIGUOUS(a) || (anyorder && F_CONTIGUOUS(a))) {
108102
/* If continguous then we just need the itemsize */
109103
it->ndim_m2 = -1;
110104
// it->axis does not matter

bottleneck/tests/reduce_test.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,28 @@ def test_ddof_nans(func, dtype):
239239

240240

241241
@pytest.mark.parametrize("dtype", DTYPES)
242-
@pytest.mark.parametrize("func", (bn.nanmean, bn.nanmax), ids=lambda x: x.__name__)
243-
def test_reduce_with_unordered_strides_ccontig(func, dtype) -> None:
242+
@pytest.mark.parametrize(
243+
("func", "expected"),
244+
[(bn.nansum, 1000),
245+
(bn.nanmean, 1),
246+
(bn.nanmax, 1)],
247+
ids=lambda x: x.__name__ if not isinstance(x, int) else x
248+
)
249+
def test_reduce_with_unordered_strides_ccontig(func, expected, dtype) -> None:
244250
array = np.ones((1, 500, 2), dtype=dtype).transpose((1,2,0))
245251
result = func(array)
246-
assert result == 1000
252+
assert result == expected
247253

248254
@pytest.mark.parametrize("dtype", DTYPES)
249-
@pytest.mark.parametrize("func", (bn.nanmean, bn.nanmax), ids=lambda x: x.__name__)
250-
def test_reduce_with_unordered_strides_fcontig(func, dtype) -> None:
255+
@pytest.mark.parametrize(
256+
("func", "expected"),
257+
[(bn.nansum, 1000),
258+
(bn.nanmean, 1),
259+
(bn.nanmax, 1)],
260+
ids=lambda x: x.__name__ if not isinstance(x, int) else x
261+
)
262+
def test_reduce_with_unordered_strides_fcontig(func, expected, dtype) -> None:
251263
array = np.ones((1, 500, 2), dtype=dtype).transpose((0,2,1))
252264
result = func(array)
253-
assert result == 1000
265+
assert result == expected
254266

0 commit comments

Comments
 (0)