summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/reference/c-api.iterator.rst15
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h4
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c4
-rw-r--r--numpy/core/src/multiarray/nditer_pywrap.c4
-rw-r--r--numpy/core/src/umath/ufunc_object.c12
-rw-r--r--numpy/core/tests/test_nditer.py6
6 files changed, 21 insertions, 24 deletions
diff --git a/doc/source/reference/c-api.iterator.rst b/doc/source/reference/c-api.iterator.rst
index 367dc15ef..679763067 100644
--- a/doc/source/reference/c-api.iterator.rst
+++ b/doc/source/reference/c-api.iterator.rst
@@ -608,17 +608,14 @@ Construction and Destruction
returns true from the corresponding element in the ARRAYMASK
operand.
- .. c:var:: NPY_ITER_OVERLAP_ALLOW_SAME
+ .. c:var:: NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE
- In memory overlap checks, operands with ``NPY_ITER_OVERLAP_ALLOW_SAME``
- set are considered non-overlapping if they point to exactly the same array.
- This means arrays with the same shape, dtype, strides, and start address.
- In other cases, the default rules implied by
- ``NPY_ITER_COPY_IF_OVERLAP`` apply.
+ In memory overlap checks, assume that operands with
+ ``NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE`` enabled are accessed only
+ in the iterator order.
- This flag can be enabled on the set of operands that are accessed
- only in the iterator order, i.e. the operation is element-wise,
- to avoid unnecessary copies.
+ This enables the iterator to reason about data dependency,
+ possibly avoiding unnecessary copies.
This flag has effect only if ``NPY_ITER_COPY_IF_OVERLAP`` is enabled
on the iterator.
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index d2e73d73a..7f6fe6524 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -1045,8 +1045,8 @@ typedef void (NpyIter_GetMultiIndexFunc)(NpyIter *iter,
#define NPY_ITER_WRITEMASKED 0x10000000
/* This array is the mask for all WRITEMASKED operands */
#define NPY_ITER_ARRAYMASK 0x20000000
-/* Consider identical arrays non-overlapping for COPY_IF_OVERLAP */
-#define NPY_ITER_OVERLAP_ALLOW_SAME 0x40000000
+/* Assume iterator order data access for COPY_IF_OVERLAP */
+#define NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE 0x40000000
#define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
#define NPY_ITER_PER_OP_FLAGS 0xffff0000
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index 27906ca53..608b91cef 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -2750,8 +2750,8 @@ npyiter_allocate_arrays(NpyIter *iter,
* to make copies, if the caller (eg ufunc) says it accesses
* data only in the iterator order.
*/
- if ((op_flags[iop] & NPY_ITER_OVERLAP_ALLOW_SAME) &&
- (op_flags[iother] & NPY_ITER_OVERLAP_ALLOW_SAME) &&
+ if ((op_flags[iop] & NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE) &&
+ (op_flags[iother] & NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE) &&
PyArray_BYTES(op[iop]) == PyArray_BYTES(op[iother]) &&
PyArray_NDIM(op[iop]) == PyArray_NDIM(op[iother]) &&
PyArray_CompareLists(PyArray_DIMS(op[iop]),
diff --git a/numpy/core/src/multiarray/nditer_pywrap.c b/numpy/core/src/multiarray/nditer_pywrap.c
index 1f512bb7d..982ed2489 100644
--- a/numpy/core/src/multiarray/nditer_pywrap.c
+++ b/numpy/core/src/multiarray/nditer_pywrap.c
@@ -361,8 +361,8 @@ NpyIter_OpFlagsConverter(PyObject *op_flags_in,
}
break;
case 'o':
- if (strcmp(str, "overlap_allow_same") == 0) {
- flag = NPY_ITER_OVERLAP_ALLOW_SAME;
+ if (strcmp(str, "overlap_assume_elementwise") == 0) {
+ flag = NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
}
break;
case 'r':
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index dd399cafd..5dc3187e5 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -1418,7 +1418,7 @@ iterator_loop(PyUFuncObject *ufunc,
for (i = 0; i < nin; ++i) {
op_flags[i] = NPY_ITER_READONLY |
NPY_ITER_ALIGNED |
- NPY_ITER_OVERLAP_ALLOW_SAME;
+ NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
/*
* If READWRITE flag has been set for this operand,
* then clear default READONLY flag
@@ -1434,7 +1434,7 @@ iterator_loop(PyUFuncObject *ufunc,
NPY_ITER_ALLOCATE |
NPY_ITER_NO_BROADCAST |
NPY_ITER_NO_SUBTYPE |
- NPY_ITER_OVERLAP_ALLOW_SAME;
+ NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
}
iter_flags = ufunc->iter_flags |
@@ -1730,7 +1730,7 @@ execute_fancy_ufunc_loop(PyUFuncObject *ufunc,
op_flags[i] = default_op_in_flags |
NPY_ITER_READONLY |
NPY_ITER_ALIGNED |
- NPY_ITER_OVERLAP_ALLOW_SAME;
+ NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
/*
* If READWRITE flag has been set for this operand,
* then clear default READONLY flag
@@ -1751,7 +1751,7 @@ execute_fancy_ufunc_loop(PyUFuncObject *ufunc,
NPY_ITER_ALLOCATE |
NPY_ITER_NO_BROADCAST |
NPY_ITER_NO_SUBTYPE |
- NPY_ITER_OVERLAP_ALLOW_SAME;
+ NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
}
if (wheremask != NULL) {
op_flags[nop] = NPY_ITER_READONLY | NPY_ITER_ARRAYMASK;
@@ -2287,7 +2287,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
op_flags[i] = NPY_ITER_READONLY |
NPY_ITER_COPY |
NPY_ITER_ALIGNED |
- NPY_ITER_OVERLAP_ALLOW_SAME;
+ NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
/*
* If READWRITE flag has been set for this operand,
* then clear default READONLY flag
@@ -2303,7 +2303,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc,
NPY_ITER_ALIGNED|
NPY_ITER_ALLOCATE|
NPY_ITER_NO_BROADCAST|
- NPY_ITER_OVERLAP_ALLOW_SAME;
+ NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
}
iter_flags = ufunc->iter_flags |
diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py
index 15735406c..c1a931773 100644
--- a/numpy/core/tests/test_nditer.py
+++ b/numpy/core/tests/test_nditer.py
@@ -1155,12 +1155,12 @@ def test_iter_copy_if_overlap():
i = nditer([a, b], ['copy_if_overlap'], [['readonly'], ['readwrite']])
assert_(not np.shares_memory(*i.operands))
- # Copy not needed with allow_same, 2 ops, exactly same arrays
+ # Copy not needed with elementwise, 2 ops, exactly same arrays
x = arange(10)
a = x
b = x
- i = nditer([a, b], ['copy_if_overlap'], [['readonly', 'overlap_allow_same'],
- ['readwrite', 'overlap_allow_same']])
+ i = nditer([a, b], ['copy_if_overlap'], [['readonly', 'overlap_assume_elementwise'],
+ ['readwrite', 'overlap_assume_elementwise']])
assert_(i.operands[0] is a and i.operands[1] is b)
i = nditer([a, b], ['copy_if_overlap'], [['readonly'], ['readwrite']])
assert_(i.operands[0] is a and not np.shares_memory(i.operands[1], b))