summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2017-01-20 21:09:30 +0100
committerPauli Virtanen <pav@iki.fi>2017-01-20 21:09:30 +0100
commitead5cb7fcfff510c81e293b5fabe006ddab399e6 (patch)
tree2ba9642c852c674c1742a33e91580f1e812a84d1
parentcd28173172c2f20ded46d921534e7e5245eeabc3 (diff)
downloadnumpy-ead5cb7fcfff510c81e293b5fabe006ddab399e6.tar.gz
BUG: core: fix bug with zero strides in PyArray_EQUIVALENTLY_ITERABLE_OVERLAP_OK
Arrays with zero strides are never "ahead", as the same element is reused multiple times. The previous logic was incorrect eg. for stride1==0, stride2<0 and arr1->data==arr2->data.
-rw-r--r--numpy/core/src/private/lowlevel_strided_loops.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/numpy/core/src/private/lowlevel_strided_loops.h b/numpy/core/src/private/lowlevel_strided_loops.h
index 8a1312c35..691c6bcd5 100644
--- a/numpy/core/src/private/lowlevel_strided_loops.h
+++ b/numpy/core/src/private/lowlevel_strided_loops.h
@@ -720,20 +720,23 @@ PyArray_EQUIVALENTLY_ITERABLE_OVERLAP_OK(PyArrayObject *arr1, PyArrayObject *arr
stride1 = PyArray_TRIVIAL_PAIR_ITERATION_STRIDE(size1, arr1);
stride2 = PyArray_TRIVIAL_PAIR_ITERATION_STRIDE(size2, arr2);
- if (stride1 >= 0) {
+ /* Arrays with zero stride are never "ahead" since the element is reused
+ (at this point we know the arrays do overlap). */
+
+ if (stride1 > 0) {
arr1_ahead = (stride1 >= stride2 &&
(npy_uintp)PyArray_BYTES(arr1) >= (npy_uintp)PyArray_BYTES(arr2));
}
- else {
+ else if (stride1 < 0) {
arr1_ahead = (stride1 <= stride2 &&
(npy_uintp)PyArray_BYTES(arr1) <= (npy_uintp)PyArray_BYTES(arr2));
}
- if (stride2 >= 0) {
+ if (stride2 > 0) {
arr2_ahead = (stride2 >= stride1 &&
(npy_uintp)PyArray_BYTES(arr2) >= (npy_uintp)PyArray_BYTES(arr1));
}
- else {
+ else if (stride2 < 0) {
arr2_ahead = (stride2 <= stride1 &&
(npy_uintp)PyArray_BYTES(arr2) <= (npy_uintp)PyArray_BYTES(arr1));
}