Skip to content

Commit

Permalink
Simplify iteration options for reduce_all
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sewell authored and rdbisme committed Feb 22, 2022
1 parent 65743d9 commit 0cc52b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
8 changes: 1 addition & 7 deletions bottleneck/include/iterators.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ static inline void init_iter_all(iter *it, PyArrayObject *a, int ravel, int anyo
it->ndim_m2 = -1;
it->length = 1;
it->astride = 0;
} else if (F_CONTIGUOUS(a) && !C_CONTIGUOUS(a) && ravel && !anyorder) {
it->ndim_m2 = -1;
a = (PyArrayObject *)PyArray_Ravel(a, NPY_CORDER);
it->a_ravel = a;
it->length = PyArray_DIM(a, 0);
it->astride = PyArray_STRIDE(a, 0);
} else if (C_CONTIGUOUS(a) || F_CONTIGUOUS(a)) {
} else if (C_CONTIGUOUS(a) || (anyorder && F_CONTIGUOUS(a))) {
/* If continguous then we just need the itemsize */
it->ndim_m2 = -1;
// it->axis does not matter
Expand Down
24 changes: 18 additions & 6 deletions bottleneck/tests/reduce_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,28 @@ def test_ddof_nans(func, dtype):


@pytest.mark.parametrize("dtype", DTYPES)
@pytest.mark.parametrize("func", (bn.nanmean, bn.nanmax), ids=lambda x: x.__name__)
def test_reduce_with_unordered_strides_ccontig(func, dtype) -> None:
@pytest.mark.parametrize(
("func", "expected"),
[(bn.nansum, 1000),
(bn.nanmean, 1),
(bn.nanmax, 1)],
ids=lambda x: x.__name__ if not isinstance(x, int) else x
)
def test_reduce_with_unordered_strides_ccontig(func, expected, dtype) -> None:
array = np.ones((1, 500, 2), dtype=dtype).transpose((1,2,0))
result = func(array)
assert result == 1000
assert result == expected

@pytest.mark.parametrize("dtype", DTYPES)
@pytest.mark.parametrize("func", (bn.nanmean, bn.nanmax), ids=lambda x: x.__name__)
def test_reduce_with_unordered_strides_fcontig(func, dtype) -> None:
@pytest.mark.parametrize(
("func", "expected"),
[(bn.nansum, 1000),
(bn.nanmean, 1),
(bn.nanmax, 1)],
ids=lambda x: x.__name__ if not isinstance(x, int) else x
)
def test_reduce_with_unordered_strides_fcontig(func, expected, dtype) -> None:
array = np.ones((1, 500, 2), dtype=dtype).transpose((0,2,1))
result = func(array)
assert result == 1000
assert result == expected

0 comments on commit 0cc52b5

Please sign in to comment.