Skip to content

Commit 557c7ae

Browse files
author
Luke Sewell
committed
Simplify iteration options for reduce_all
1 parent 969b5cf commit 557c7ae

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

bottleneck/include/iterators.h

+1-7
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

+18-6
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,28 @@ def test_ddof_nans(func, dtype) -> None:
305305

306306

307307
@pytest.mark.parametrize("dtype", DTYPES)
308-
@pytest.mark.parametrize("func", (bn.nanmean, bn.nanmax), ids=lambda x: x.__name__)
309-
def test_reduce_with_unordered_strides_ccontig(func, dtype) -> None:
308+
@pytest.mark.parametrize(
309+
("func", "expected"),
310+
[(bn.nansum, 1000),
311+
(bn.nanmean, 1),
312+
(bn.nanmax, 1)],
313+
ids=lambda x: x.__name__ if not isinstance(x, int) else x
314+
)
315+
def test_reduce_with_unordered_strides_ccontig(func, expected, dtype) -> None:
310316
array = np.ones((1, 500, 2), dtype=dtype).transpose((1,2,0))
311317
result = func(array)
312-
assert result == 1000
318+
assert result == expected
313319

314320
@pytest.mark.parametrize("dtype", DTYPES)
315-
@pytest.mark.parametrize("func", (bn.nanmean, bn.nanmax), ids=lambda x: x.__name__)
316-
def test_reduce_with_unordered_strides_fcontig(func, dtype) -> None:
321+
@pytest.mark.parametrize(
322+
("func", "expected"),
323+
[(bn.nansum, 1000),
324+
(bn.nanmean, 1),
325+
(bn.nanmax, 1)],
326+
ids=lambda x: x.__name__ if not isinstance(x, int) else x
327+
)
328+
def test_reduce_with_unordered_strides_fcontig(func, expected, dtype) -> None:
317329
array = np.ones((1, 500, 2), dtype=dtype).transpose((0,2,1))
318330
result = func(array)
319-
assert result == 1000
331+
assert result == expected
320332

0 commit comments

Comments
 (0)