summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/numpy_api.py4
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h4
-rw-r--r--numpy/core/src/multiarray/convert.c2
-rw-r--r--numpy/core/src/multiarray/ctors.c6
-rw-r--r--numpy/core/src/multiarray/einsum.c.src2
-rw-r--r--numpy/core/src/multiarray/item_selection.c2
-rw-r--r--numpy/core/src/multiarray/nditer.c.src78
-rw-r--r--numpy/core/src/multiarray/nditer_pywrap.c54
-rw-r--r--numpy/core/src/umath/ufunc_object.c6
-rw-r--r--numpy/core/tests/test_iterator.py62
-rw-r--r--numpy/lib/src/_compiled_base.c4
11 files changed, 112 insertions, 112 deletions
diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py
index 1bb1ce666..4aef212bf 100644
--- a/numpy/core/code_generators/numpy_api.py
+++ b/numpy/core/code_generators/numpy_api.py
@@ -263,8 +263,8 @@ multiarray_funcs_api = {
'NpyIter_Copy': 227,
'NpyIter_Deallocate': 228,
'NpyIter_HasDelayedBufAlloc': 229,
- 'NpyIter_HasInnerLoop': 230,
- 'NpyIter_RemoveInnerLoop': 231,
+ 'NpyIter_HasExternalLoop': 230,
+ 'NpyIter_EnableExternalLoop': 231,
'NpyIter_GetInnerStrideArray': 232,
'NpyIter_GetInnerLoopSizePtr': 233,
'NpyIter_Reset': 234,
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index d37f1ce38..26077ba59 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -879,8 +879,8 @@ typedef void (NpyIter_GetCoordsFunc)(NpyIter *iter,
#define NPY_ITER_F_INDEX 0x00000002
/* Track coordinates */
#define NPY_ITER_COORDS 0x00000004
-/* Let the caller handle the inner loop of iteration */
-#define NPY_ITER_NO_INNER_ITERATION 0x00000008
+/* User code external to the iterator does the 1-dimensional innermost loop */
+#define NPY_ITER_EXTERNAL_LOOP 0x00000008
/* Convert all the operands to a common data type */
#define NPY_ITER_COMMON_DTYPE 0x00000010
/* Operands may hold references, requiring API access during iteration */
diff --git a/numpy/core/src/multiarray/convert.c b/numpy/core/src/multiarray/convert.c
index 44aff3a8d..134350222 100644
--- a/numpy/core/src/multiarray/convert.c
+++ b/numpy/core/src/multiarray/convert.c
@@ -391,7 +391,7 @@ PyArray_FillWithZero(PyArrayObject *a)
}
/* Use an iterator to go through all the data */
- iter = NpyIter_New(a, NPY_ITER_WRITEONLY|NPY_ITER_NO_INNER_ITERATION,
+ iter = NpyIter_New(a, NPY_ITER_WRITEONLY|NPY_ITER_EXTERNAL_LOOP,
NPY_KEEPORDER, NPY_NO_CASTING, NULL);
if (iter == NULL) {
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 369cc411e..b137b34f4 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -2481,7 +2481,7 @@ PyArray_CopyAnyIntoOrdered(PyArrayObject *dst, PyArrayObject *src,
* can be processed at once.
*/
dst_iter = NpyIter_New(dst, NPY_ITER_WRITEONLY|
- NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_DONT_NEGATE_STRIDES|
NPY_ITER_REFS_OK,
order,
@@ -2491,7 +2491,7 @@ PyArray_CopyAnyIntoOrdered(PyArrayObject *dst, PyArrayObject *src,
return -1;
}
src_iter = NpyIter_New(src, NPY_ITER_READONLY|
- NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_DONT_NEGATE_STRIDES|
NPY_ITER_REFS_OK,
order,
@@ -2712,7 +2712,7 @@ PyArray_CopyInto(PyArrayObject *dst, PyArrayObject *src)
op_flags[1] = NPY_ITER_READONLY;
iter = NpyIter_MultiNew(2, op,
- NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_REFS_OK|
NPY_ITER_ZEROSIZE_OK,
NPY_KEEPORDER,
diff --git a/numpy/core/src/multiarray/einsum.c.src b/numpy/core/src/multiarray/einsum.c.src
index 10c6bdca5..98a26c322 100644
--- a/numpy/core/src/multiarray/einsum.c.src
+++ b/numpy/core/src/multiarray/einsum.c.src
@@ -2965,7 +2965,7 @@ PyArray_EinsteinSum(char *subscripts, npy_intp nop,
NPY_ITER_NO_BROADCAST;
/* Allocate the iterator */
- iter = NpyIter_AdvancedNew(nop+1, op, NPY_ITER_NO_INNER_ITERATION|
+ iter = NpyIter_AdvancedNew(nop+1, op, NPY_ITER_EXTERNAL_LOOP|
((dtype != NULL) ? 0 : NPY_ITER_COMMON_DTYPE)|
NPY_ITER_BUFFERED|
NPY_ITER_DELAY_BUFALLOC|
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index c497845a1..91d5f1f4e 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -1726,7 +1726,7 @@ PyArray_CountNonzero(PyArrayObject *self)
/* Otherwise create and use an iterator to count the nonzeros */
iter = NpyIter_New(self, NPY_ITER_READONLY|
- NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_REFS_OK,
NPY_KEEPORDER, NPY_NO_CASTING,
NULL);
diff --git a/numpy/core/src/multiarray/nditer.c.src b/numpy/core/src/multiarray/nditer.c.src
index dd8285242..648d32a33 100644
--- a/numpy/core/src/multiarray/nditer.c.src
+++ b/numpy/core/src/multiarray/nditer.c.src
@@ -80,7 +80,7 @@
/* The iteration order was forced on construction */
#define NPY_ITFLAG_FORCEDORDER 0x0010
/* The inner loop is handled outside the iterator */
-#define NPY_ITFLAG_NOINNER 0x0020
+#define NPY_ITFLAG_EXLOOP 0x0020
/* The iterator is ranged */
#define NPY_ITFLAG_RANGE 0x0040
/* The iterator is buffered */
@@ -697,7 +697,7 @@ NpyIter_AdvancedNew(int niter, PyArrayObject **op_in, npy_uint32 flags,
*/
if (!(itflags&NPY_ITFLAG_BUFFER)) {
NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
- if (itflags&NPY_ITFLAG_NOINNER) {
+ if (itflags&NPY_ITFLAG_EXLOOP) {
if (NIT_ITERSIZE(iter) == NAD_SHAPE(axisdata)) {
NIT_ITFLAGS(iter) |= NPY_ITFLAG_ONEITERATION;
}
@@ -1116,10 +1116,10 @@ NpyIter_RemoveCoords(NpyIter *iter)
}
/*NUMPY_API
- * Removes the inner loop handling (so HasInnerLoop returns false)
+ * Removes the inner loop handling (so HasExternalLoop returns true)
*/
NPY_NO_EXPORT int
-NpyIter_RemoveInnerLoop(NpyIter *iter)
+NpyIter_EnableExternalLoop(NpyIter *iter)
{
npy_uint32 itflags = NIT_ITFLAGS(iter);
/*int ndim = NIT_NDIM(iter);*/
@@ -1128,20 +1128,20 @@ NpyIter_RemoveInnerLoop(NpyIter *iter)
/* Check conditions under which this can be done */
if (itflags&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASCOORDS)) {
PyErr_SetString(PyExc_ValueError,
- "Iterator flag NO_INNER_ITERATION cannot be used "
+ "Iterator flag EXTERNAL_LOOP cannot be used "
"if coords or an index is being tracked");
return NPY_FAIL;
}
- if ((itflags&(NPY_ITFLAG_BUFFER|NPY_ITFLAG_RANGE|NPY_ITFLAG_NOINNER))
- == (NPY_ITFLAG_RANGE|NPY_ITFLAG_NOINNER)) {
+ if ((itflags&(NPY_ITFLAG_BUFFER|NPY_ITFLAG_RANGE|NPY_ITFLAG_EXLOOP))
+ == (NPY_ITFLAG_RANGE|NPY_ITFLAG_EXLOOP)) {
PyErr_SetString(PyExc_ValueError,
- "Iterator flag NO_INNER_ITERATION cannot be used "
+ "Iterator flag EXTERNAL_LOOP cannot be used "
"with ranged iteration unless buffering is also enabled");
return NPY_FAIL;
}
/* Set the flag */
- if (!(itflags&NPY_ITFLAG_NOINNER)) {
- itflags |= NPY_ITFLAG_NOINNER;
+ if (!(itflags&NPY_ITFLAG_EXLOOP)) {
+ itflags |= NPY_ITFLAG_EXLOOP;
NIT_ITFLAGS(iter) = itflags;
/*
@@ -1352,10 +1352,10 @@ NpyIter_GotoCoords(NpyIter *iter, npy_intp *coords)
return NPY_FAIL;
}
- if (itflags&NPY_ITFLAG_NOINNER) {
+ if (itflags&NPY_ITFLAG_EXLOOP) {
PyErr_SetString(PyExc_ValueError,
"Cannot call GotoCoords on an iterator which "
- "has the flag NO_INNER_ITERATION");
+ "has the flag EXTERNAL_LOOP");
return NPY_FAIL;
}
@@ -1437,10 +1437,10 @@ NpyIter_GotoIndex(NpyIter *iter, npy_intp index)
return NPY_FAIL;
}
- if (itflags&NPY_ITFLAG_NOINNER) {
+ if (itflags&NPY_ITFLAG_EXLOOP) {
PyErr_SetString(PyExc_ValueError,
"Cannot call GotoIndex on an iterator which "
- "has the flag NO_INNER_ITERATION");
+ "has the flag EXTERNAL_LOOP");
return NPY_FAIL;
}
@@ -1507,10 +1507,10 @@ NpyIter_GotoIterIndex(NpyIter *iter, npy_intp iterindex)
/*int ndim = NIT_NDIM(iter);*/
int iiter, niter = NIT_NITER(iter);
- if (itflags&NPY_ITFLAG_NOINNER) {
+ if (itflags&NPY_ITFLAG_EXLOOP) {
PyErr_SetString(PyExc_ValueError,
"Cannot call GotoIterIndex on an iterator which "
- "has the flag NO_INNER_ITERATION");
+ "has the flag EXTERNAL_LOOP");
return NPY_FAIL;
}
@@ -1600,7 +1600,7 @@ NpyIter_GetIterIndex(NpyIter *iter)
/**begin repeat
* #const_itflags = 0,
* NPY_ITFLAG_HASINDEX,
- * NPY_ITFLAG_NOINNER,
+ * NPY_ITFLAG_EXLOOP,
* NPY_ITFLAG_RANGE,
* NPY_ITFLAG_RANGE|NPY_ITFLAG_HASINDEX#
* #tag_itflags = 0, IND, NOINN, RNG, RNGuIND#
@@ -1651,7 +1651,7 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@(
sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, niter);
axisdata0 = NIT_AXISDATA(iter);
-# if !(@const_itflags@&NPY_ITFLAG_NOINNER)
+# if !(@const_itflags@&NPY_ITFLAG_EXLOOP)
/* Increment coordinate 0 */
NAD_COORD(axisdata0)++;
/* Increment pointer 0 */
@@ -1662,7 +1662,7 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@(
#if @const_ndim@ == 1
-# if !(@const_itflags@&NPY_ITFLAG_NOINNER)
+# if !(@const_itflags@&NPY_ITFLAG_EXLOOP)
/* Finished when the coordinate equals the shape */
return NAD_COORD(axisdata0) < NAD_SHAPE(axisdata0);
# else
@@ -1674,7 +1674,7 @@ npyiter_iternext_itflags@tag_itflags@_dims@tag_ndim@_iters@tag_niter@(
#else
-# if !(@const_itflags@&NPY_ITFLAG_NOINNER)
+# if !(@const_itflags@&NPY_ITFLAG_EXLOOP)
if (NAD_COORD(axisdata0) < NAD_SHAPE(axisdata0)) {
return 1;
}
@@ -1795,7 +1795,7 @@ npyiter_buffered_reduce_iternext_iters@tag_niter@(NpyIter *iter)
* If the iterator handles the inner loop, need to increment all
* the coordinates and pointers
*/
- if (!(itflags&NPY_ITFLAG_NOINNER)) {
+ if (!(itflags&NPY_ITFLAG_EXLOOP)) {
/* Increment within the buffer */
if (++NIT_ITERINDEX(iter) < NBF_BUFITEREND(bufferdata)) {
npy_intp *strides;
@@ -1865,7 +1865,7 @@ npyiter_buffered_iternext(NpyIter *iter)
* If the iterator handles the inner loop, need to increment all
* the coordinates and pointers
*/
- if (!(itflags&NPY_ITFLAG_NOINNER)) {
+ if (!(itflags&NPY_ITFLAG_EXLOOP)) {
/* Increment within the buffer */
if (++NIT_ITERINDEX(iter) < NBF_BUFITEREND(bufferdata)) {
int iiter;
@@ -1963,20 +1963,20 @@ NpyIter_GetIterNext(NpyIter *iter, char **errmsg)
/*
* Ignore all the flags that don't affect the iterator memory
* layout or the iternext function. Currently only HASINDEX,
- * NOINNER, and RANGE affect them here.
+ * EXLOOP, and RANGE affect them here.
*/
- itflags &= (NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NOINNER|NPY_ITFLAG_RANGE);
+ itflags &= (NPY_ITFLAG_HASINDEX|NPY_ITFLAG_EXLOOP|NPY_ITFLAG_RANGE);
/* Switch statements let the compiler optimize this most effectively */
switch (itflags) {
/*
- * The combinations HASINDEX|NOINNER and RANGE|NOINNER are excluded
+ * The combinations HASINDEX|EXLOOP and RANGE|EXLOOP are excluded
* by the New functions
*/
/**begin repeat
* #const_itflags = 0,
* NPY_ITFLAG_HASINDEX,
- * NPY_ITFLAG_NOINNER,
+ * NPY_ITFLAG_EXLOOP,
* NPY_ITFLAG_RANGE,
* NPY_ITFLAG_RANGE|NPY_ITFLAG_HASINDEX#
* #tag_itflags = 0, IND, NOINN, RNG, RNGuIND#
@@ -2196,9 +2196,9 @@ NpyIter_HasDelayedBufAlloc(NpyIter *iter)
* Whether the iterator handles the inner loop
*/
NPY_NO_EXPORT npy_bool
-NpyIter_HasInnerLoop(NpyIter *iter)
+NpyIter_HasExternalLoop(NpyIter *iter)
{
- return (NIT_ITFLAGS(iter)&NPY_ITFLAG_NOINNER) == 0;
+ return (NIT_ITFLAGS(iter)&NPY_ITFLAG_EXLOOP) != 0;
}
/*NUMPY_API
@@ -2642,7 +2642,7 @@ NpyIter_GetWriteFlags(NpyIter *iter, char *outwriteflags)
/*NUMPY_API
- * Get the array of strides for the inner loop (when HasInnerLoop is false)
+ * Get the array of strides for the inner loop (when HasExternalLoop is true)
*
* This function may be safely called without holding the Python GIL.
*/
@@ -2797,7 +2797,7 @@ NpyIter_GetInnerFixedStrideArray(NpyIter *iter, npy_intp *out_strides)
/*NUMPY_API
- * Get a pointer to the size of the inner loop (when HasInnerLoop is false)
+ * Get a pointer to the size of the inner loop (when HasExternalLoop is true)
*
* This function may be safely called without holding the Python GIL.
*/
@@ -2818,7 +2818,7 @@ NpyIter_GetInnerLoopSizePtr(NpyIter *iter)
}
}
-/* Checks 'flags' for (C|F)_ORDER_INDEX, COORDS, and NO_INNER_ITERATION,
+/* Checks 'flags' for (C|F)_ORDER_INDEX, COORDS, and EXTERNAL_LOOP,
* setting the appropriate internal flags in 'itflags'.
*
* Returns 1 on success, 0 on error.
@@ -2853,23 +2853,23 @@ npyiter_check_global_flags(npy_uint32 flags, npy_uint32* itflags)
(*itflags) |= NPY_ITFLAG_HASCOORDS;
}
/* Check if the caller wants to handle inner iteration */
- if (flags&NPY_ITER_NO_INNER_ITERATION) {
+ if (flags&NPY_ITER_EXTERNAL_LOOP) {
if ((*itflags)&(NPY_ITFLAG_HASINDEX|NPY_ITFLAG_HASCOORDS)) {
PyErr_SetString(PyExc_ValueError,
- "Iterator flag NO_INNER_ITERATION cannot be used "
+ "Iterator flag EXTERNAL_LOOP cannot be used "
"if coords or an index is being tracked");
return 0;
}
- (*itflags) |= NPY_ITFLAG_NOINNER;
+ (*itflags) |= NPY_ITFLAG_EXLOOP;
}
/* Ranged */
if (flags&NPY_ITER_RANGED) {
(*itflags) |= NPY_ITFLAG_RANGE;
- if ((flags&NPY_ITER_NO_INNER_ITERATION) &&
+ if ((flags&NPY_ITER_EXTERNAL_LOOP) &&
!(flags&NPY_ITER_BUFFERED)) {
PyErr_SetString(PyExc_ValueError,
"Iterator flag RANGED cannot be used with "
- "the flag NO_INNER_ITERATION unless "
+ "the flag EXTERNAL_LOOP unless "
"BUFFERED is also enabled");
return 0;
}
@@ -6177,8 +6177,8 @@ NpyIter_DebugPrint(NpyIter *iter)
printf("HASCOORDS ");
if (itflags&NPY_ITFLAG_FORCEDORDER)
printf("FORCEDORDER ");
- if (itflags&NPY_ITFLAG_NOINNER)
- printf("NOINNER ");
+ if (itflags&NPY_ITFLAG_EXLOOP)
+ printf("EXLOOP ");
if (itflags&NPY_ITFLAG_RANGE)
printf("RANGE ");
if (itflags&NPY_ITFLAG_BUFFER)
@@ -6302,7 +6302,7 @@ NpyIter_DebugPrint(NpyIter *iter)
printf("%d ", (int)NBF_STRIDES(bufferdata)[iiter]);
printf("\n");
/* Print the fixed strides when there's no inner loop */
- if (itflags&NPY_ITFLAG_NOINNER) {
+ if (itflags&NPY_ITFLAG_EXLOOP) {
npy_intp fixedstrides[NPY_MAXDIMS];
printf("| Fixed Strides: ");
NpyIter_GetInnerFixedStrideArray(iter, fixedstrides);
diff --git a/numpy/core/src/multiarray/nditer_pywrap.c b/numpy/core/src/multiarray/nditer_pywrap.c
index 1f2adc535..d604d7889 100644
--- a/numpy/core/src/multiarray/nditer_pywrap.c
+++ b/numpy/core/src/multiarray/nditer_pywrap.c
@@ -57,14 +57,14 @@ void npyiter_cache_values(NewNpyArrayIterObject *self)
self->dtypes = NpyIter_GetDescrArray(iter);
self->operands = NpyIter_GetOperandArray(iter);
- if (NpyIter_HasInnerLoop(iter)) {
- self->innerstrides = NULL;
- self->innerloopsizeptr = NULL;
- }
- else {
+ if (NpyIter_HasExternalLoop(iter)) {
self->innerstrides = NpyIter_GetInnerStrideArray(iter);
self->innerloopsizeptr = NpyIter_GetInnerLoopSizePtr(iter);
}
+ else {
+ self->innerstrides = NULL;
+ self->innerloopsizeptr = NULL;
+ }
/* The read/write settings */
NpyIter_GetReadFlags(iter, self->readflags);
@@ -163,6 +163,11 @@ NpyIter_GlobalFlagsConverter(PyObject *flags_in, npy_uint32 *flags)
flag = NPY_ITER_DELAY_BUFALLOC;
}
break;
+ case 'e':
+ if (strcmp(str, "external_loop") == 0) {
+ flag = NPY_ITER_EXTERNAL_LOOP;
+ }
+ break;
case 'f':
if (strcmp(str, "f_index") == 0) {
flag = NPY_ITER_F_INDEX;
@@ -173,11 +178,6 @@ NpyIter_GlobalFlagsConverter(PyObject *flags_in, npy_uint32 *flags)
flag = NPY_ITER_GROWINNER;
}
break;
- case 'n':
- if (strcmp(str, "no_inner_iteration") == 0) {
- flag = NPY_ITER_NO_INNER_ITERATION;
- }
- break;
case 'r':
if (strcmp(str, "ranged") == 0) {
flag = NPY_ITER_RANGED;
@@ -1047,7 +1047,7 @@ NpyIter_NestedIters(PyObject *NPY_UNUSED(self),
/* Only the inner loop gets the buffering and no inner flags */
flags_inner = flags&~NPY_ITER_COMMON_DTYPE;
- flags &= ~(NPY_ITER_NO_INNER_ITERATION|
+ flags &= ~(NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_BUFFERED);
for (inest = 0; inest < nnest; ++inest) {
@@ -1372,7 +1372,7 @@ npyiter_remove_coords(NewNpyArrayIterObject *self)
}
static PyObject *
-npyiter_remove_inner_loop(NewNpyArrayIterObject *self)
+npyiter_enable_external_loop(NewNpyArrayIterObject *self)
{
if (self->iter == NULL) {
PyErr_SetString(PyExc_ValueError,
@@ -1380,10 +1380,10 @@ npyiter_remove_inner_loop(NewNpyArrayIterObject *self)
return NULL;
}
- NpyIter_RemoveInnerLoop(self->iter);
- /* RemoveInnerLoop invalidates cached values */
+ NpyIter_EnableExternalLoop(self->iter);
+ /* EnableExternalLoop invalidates cached values */
npyiter_cache_values(self);
- /* RemoveInnerLoop also resets the iterator */
+ /* EnableExternalLoop also resets the iterator */
if (NpyIter_GetIterSize(self->iter) == 0) {
self->started = 1;
self->finished = 1;
@@ -2037,17 +2037,17 @@ npyiter_seq_item(NewNpyArrayIterObject *self, Py_ssize_t i)
dataptr = self->dataptrs[i];
dtype = self->dtypes[i];
- if (NpyIter_HasInnerLoop(self->iter)) {
+ if (NpyIter_HasExternalLoop(self->iter)) {
+ innerloopsize = *self->innerloopsizeptr;
+ innerstride = self->innerstrides[i];
+ ret_ndim = 1;
+ }
+ else {
innerloopsize = 1;
innerstride = 0;
/* If the iterator is going over every element, return array scalars */
ret_ndim = 0;
}
- else {
- innerloopsize = *self->innerloopsizeptr;
- innerstride = self->innerstrides[i];
- ret_ndim = 1;
- }
Py_INCREF(dtype);
ret = (PyObject *)PyArray_NewFromDescr(&PyArray_Type, dtype,
@@ -2156,14 +2156,14 @@ npyiter_seq_ass_item(NewNpyArrayIterObject *self, Py_ssize_t i, PyObject *v)
dataptr = self->dataptrs[i];
dtype = self->dtypes[i];
- if (NpyIter_HasInnerLoop(self->iter)) {
- innerloopsize = 1;
- innerstride = 0;
- }
- else {
+ if (NpyIter_HasExternalLoop(self->iter)) {
innerloopsize = *self->innerloopsizeptr;
innerstride = self->innerstrides[i];
}
+ else {
+ innerloopsize = 1;
+ innerstride = 0;
+ }
/* TODO - there should be a better way than this... */
Py_INCREF(dtype);
@@ -2337,7 +2337,7 @@ static PyMethodDef npyiter_methods[] = {
{"iternext", (PyCFunction)npyiter_iternext, METH_NOARGS, NULL},
{"remove_axis", (PyCFunction)npyiter_remove_axis, METH_VARARGS, NULL},
{"remove_coords", (PyCFunction)npyiter_remove_coords, METH_NOARGS, NULL},
- {"remove_inner_loop", (PyCFunction)npyiter_remove_inner_loop,
+ {"enable_external_loop", (PyCFunction)npyiter_enable_external_loop,
METH_NOARGS, NULL},
{"debug_print", (PyCFunction)npyiter_debug_print, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL},
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 638032bab..e619da81d 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -1797,7 +1797,7 @@ iterator_loop(PyUFuncObject *self,
* is faster to calculate.
*/
iter = NpyIter_AdvancedNew(niter, op,
- NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_REFS_OK|
NPY_ITER_ZEROSIZE_OK|
NPY_ITER_BUFFERED|
@@ -2369,7 +2369,7 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *self,
retval = -1;
goto fail;
}
- if (NpyIter_RemoveInnerLoop(iter) != NPY_SUCCEED) {
+ if (NpyIter_EnableExternalLoop(iter) != NPY_SUCCEED) {
retval = -1;
goto fail;
}
@@ -3036,7 +3036,7 @@ PyUFunc_ReductionOp(PyUFuncObject *self, PyArrayObject *arr,
op_axes[0][0] = -1;
op_axes[1][0] = axis;
- iter_inner = NpyIter_AdvancedNew(2, op, NPY_ITER_NO_INNER_ITERATION|
+ iter_inner = NpyIter_AdvancedNew(2, op, NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_BUFFERED|
NPY_ITER_DELAY_BUFALLOC|
NPY_ITER_GROWINNER|
diff --git a/numpy/core/tests/test_iterator.py b/numpy/core/tests/test_iterator.py
index 818b15524..4b4aaecd9 100644
--- a/numpy/core/tests/test_iterator.py
+++ b/numpy/core/tests/test_iterator.py
@@ -426,17 +426,17 @@ def test_iter_no_inner_full_coalesce():
aview = a.reshape(shape)[dirs_index]
# C-order
- i = nditer(aview, ['no_inner_iteration'], [['readonly']])
+ i = nditer(aview, ['external_loop'], [['readonly']])
assert_equal(i.ndim, 1)
assert_equal(i[0].shape, (size,))
# Fortran-order
- i = nditer(aview.T, ['no_inner_iteration'], [['readonly']])
+ i = nditer(aview.T, ['external_loop'], [['readonly']])
assert_equal(i.ndim, 1)
assert_equal(i[0].shape, (size,))
# Other order
if len(shape) > 2:
i = nditer(aview.swapaxes(0,1),
- ['no_inner_iteration'], [['readonly']])
+ ['external_loop'], [['readonly']])
assert_equal(i.ndim, 1)
assert_equal(i[0].shape, (size,))
@@ -446,21 +446,21 @@ def test_iter_no_inner_dim_coalescing():
# Skipping the last element in a dimension prevents coalescing
# with the next-bigger dimension
a = arange(24).reshape(2,3,4)[:,:,:-1]
- i = nditer(a, ['no_inner_iteration'], [['readonly']])
+ i = nditer(a, ['external_loop'], [['readonly']])
assert_equal(i.ndim, 2)
assert_equal(i[0].shape, (3,))
a = arange(24).reshape(2,3,4)[:,:-1,:]
- i = nditer(a, ['no_inner_iteration'], [['readonly']])
+ i = nditer(a, ['external_loop'], [['readonly']])
assert_equal(i.ndim, 2)
assert_equal(i[0].shape, (8,))
a = arange(24).reshape(2,3,4)[:-1,:,:]
- i = nditer(a, ['no_inner_iteration'], [['readonly']])
+ i = nditer(a, ['external_loop'], [['readonly']])
assert_equal(i.ndim, 1)
assert_equal(i[0].shape, (12,))
# Even with lots of 1-sized dimensions, should still coalesce
a = arange(24).reshape(1,1,2,1,1,3,1,1,4,1,1)
- i = nditer(a, ['no_inner_iteration'], [['readonly']])
+ i = nditer(a, ['external_loop'], [['readonly']])
assert_equal(i.ndim, 1)
assert_equal(i[0].shape, (24,))
@@ -683,11 +683,11 @@ def test_iter_flags_errors():
['c_index','f_index'], [['readonly']])
# Inner iteration and coords/indices are incompatible
assert_raises(ValueError, nditer, a,
- ['no_inner_iteration','coords'], [['readonly']])
+ ['external_loop','coords'], [['readonly']])
assert_raises(ValueError, nditer, a,
- ['no_inner_iteration','c_index'], [['readonly']])
+ ['external_loop','c_index'], [['readonly']])
assert_raises(ValueError, nditer, a,
- ['no_inner_iteration','f_index'], [['readonly']])
+ ['external_loop','f_index'], [['readonly']])
# Must specify exactly one of readwrite/readonly/writeonly per operand
assert_raises(ValueError, nditer, a, [], [[]])
assert_raises(ValueError, nditer, a, [], [['readonly','writeonly']])
@@ -720,7 +720,7 @@ def test_iter_flags_errors():
i.iterindex = 0;
def assign_iterrange(i):
i.iterrange = (0,1);
- i = nditer(arange(6), ['no_inner_iteration'])
+ i = nditer(arange(6), ['external_loop'])
assert_raises(ValueError, assign_coords, i)
assert_raises(ValueError, assign_index, i)
assert_raises(ValueError, assign_iterindex, i)
@@ -795,7 +795,7 @@ def test_iter_nbo_align_contig():
assert_(i.operands[0].flags.contiguous)
assert_equal(i.operands[0], a[:6]);
# If it isn't contiguous, should buffer
- i = nditer(a[::2], ['buffered','no_inner_iteration'],
+ i = nditer(a[::2], ['buffered','external_loop'],
[['readonly','contig']],
buffersize=10)
assert_(i[0].flags.contiguous)
@@ -1403,7 +1403,7 @@ def test_iter_remove_coords_inner_loop():
i.reset()
assert_equal(i.itersize, 24)
assert_equal(i[0].shape, tuple())
- i.remove_inner_loop()
+ i.enable_external_loop()
assert_equal(i.itersize, 24)
assert_equal(i[0].shape, (24,))
assert_equal(i.value, arange(24))
@@ -1473,7 +1473,7 @@ def test_iter_iterrange():
val = np.concatenate((val, x))
return val
- i = nditer(a, ['ranged','buffered','no_inner_iteration'],
+ i = nditer(a, ['ranged','buffered','external_loop'],
['readonly'], order='F',
op_dtypes='f8', buffersize=buffersize)
assert_equal(i.iterrange, (0,24))
@@ -1501,7 +1501,7 @@ def test_iter_buffering():
for a in arrays:
for buffersize in (1,2,3,5,8,11,16,1024):
vals = []
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readonly','nbo','aligned']],
order='C',
casting='equiv',
@@ -1558,7 +1558,7 @@ def test_iter_buffered_cast_simple():
# Test that buffering can handle a simple cast
a = np.arange(10, dtype='f4')
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='same_kind',
op_dtypes=[np.dtype('f8')],
@@ -1572,7 +1572,7 @@ def test_iter_buffered_cast_byteswapped():
# Test that buffering can handle a cast which requires swap->cast->swap
a = np.arange(10, dtype='f4').newbyteorder().byteswap()
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='same_kind',
op_dtypes=[np.dtype('f8').newbyteorder()],
@@ -1586,7 +1586,7 @@ def test_iter_buffered_cast_byteswapped():
warnings.simplefilter("ignore", np.ComplexWarning)
a = np.arange(10, dtype='f8').newbyteorder().byteswap()
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='unsafe',
op_dtypes=[np.dtype('c8').newbyteorder()],
@@ -1603,7 +1603,7 @@ def test_iter_buffered_cast_byteswapped_complex():
a = np.arange(10, dtype='c8').newbyteorder().byteswap()
a += 2j
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='same_kind',
op_dtypes=[np.dtype('c16')],
@@ -1614,7 +1614,7 @@ def test_iter_buffered_cast_byteswapped_complex():
a = np.arange(10, dtype='c8')
a += 2j
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='same_kind',
op_dtypes=[np.dtype('c16').newbyteorder()],
@@ -1625,7 +1625,7 @@ def test_iter_buffered_cast_byteswapped_complex():
a = np.arange(10, dtype=np.clongdouble).newbyteorder().byteswap()
a += 2j
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='same_kind',
op_dtypes=[np.dtype('c16')],
@@ -1635,7 +1635,7 @@ def test_iter_buffered_cast_byteswapped_complex():
assert_equal(a, 2*np.arange(10, dtype=np.clongdouble) + 4j)
a = np.arange(10, dtype=np.longdouble).newbyteorder().byteswap()
- i = nditer(a, ['buffered','no_inner_iteration'],
+ i = nditer(a, ['buffered','external_loop'],
[['readwrite','nbo','aligned']],
casting='same_kind',
op_dtypes=[np.dtype('f4')],
@@ -1941,30 +1941,30 @@ def test_iter_buffering_badwriteback():
a = np.arange(6).reshape(2,3,1)
b = np.arange(12).reshape(2,3,2)
assert_raises(ValueError,nditer,[a,b],
- ['buffered','no_inner_iteration'],
+ ['buffered','external_loop'],
[['readwrite'],['writeonly']],
order='C')
# But if a is readonly, it's fine
- i = nditer([a,b],['buffered','no_inner_iteration'],
+ i = nditer([a,b],['buffered','external_loop'],
[['readonly'],['writeonly']],
order='C')
# If a has just one element, it's fine too (constant 0 stride, a reduction)
a = np.arange(1).reshape(1,1,1)
- i = nditer([a,b],['buffered','no_inner_iteration','reduce_ok'],
+ i = nditer([a,b],['buffered','external_loop','reduce_ok'],
[['readwrite'],['writeonly']],
order='C')
# check that it fails on other dimensions too
a = np.arange(6).reshape(1,3,2)
assert_raises(ValueError,nditer,[a,b],
- ['buffered','no_inner_iteration'],
+ ['buffered','external_loop'],
[['readwrite'],['writeonly']],
order='C')
a = np.arange(4).reshape(2,1,2)
assert_raises(ValueError,nditer,[a,b],
- ['buffered','no_inner_iteration'],
+ ['buffered','external_loop'],
[['readwrite'],['writeonly']],
order='C')
@@ -1989,7 +1989,7 @@ def test_iter_buffering_string():
def test_iter_buffering_growinner():
# Test that the inner loop grows when no buffering is needed
a = np.arange(30)
- i = nditer(a, ['buffered','growinner','no_inner_iteration'],
+ i = nditer(a, ['buffered','growinner','external_loop'],
buffersize=5)
# Should end up with just one inner loop here
assert_equal(i[0].size, a.size)
@@ -2182,7 +2182,7 @@ def test_iter_reduction_error():
op_axes=[[0],[-1]])
a = np.arange(6).reshape(2,3)
- assert_raises(ValueError, nditer, [a,None], ['no_inner_iteration'],
+ assert_raises(ValueError, nditer, [a,None], ['external_loop'],
[['readonly'], ['readwrite','allocate']],
op_axes=[[0,1],[-1,-1]])
@@ -2203,7 +2203,7 @@ def test_iter_reduction():
assert_equal(i.operands[1], np.sum(a))
a = np.arange(6).reshape(2,3)
- i = nditer([a,None], ['reduce_ok','no_inner_iteration'],
+ i = nditer([a,None], ['reduce_ok','external_loop'],
[['readonly'], ['readwrite','allocate']],
op_axes=[[0,1],[-1,-1]])
# Need to initialize the output operand to the addition unit
@@ -2237,7 +2237,7 @@ def test_iter_buffering_reduction():
a = np.arange(6).reshape(2,3)
b = np.array([0,0], dtype='f8').byteswap().newbyteorder()
- i = nditer([a,b], ['reduce_ok','no_inner_iteration', 'buffered'],
+ i = nditer([a,b], ['reduce_ok','external_loop', 'buffered'],
[['readonly'], ['readwrite','nbo']],
op_axes=[[0,1],[0,-1]])
# Reduction shape/strides for the output
diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c
index d1b2b2c6a..b81d2783a 100644
--- a/numpy/lib/src/_compiled_base.c
+++ b/numpy/lib/src/_compiled_base.c
@@ -755,7 +755,7 @@ arr_ravel_coords(PyObject *self, PyObject *args, PyObject *kwds)
}
iter = NpyIter_MultiNew(dimensions.len+1, op, NPY_ITER_BUFFERED|
- NPY_ITER_NO_INNER_ITERATION|
+ NPY_ITER_EXTERNAL_LOOP|
NPY_ITER_ZEROSIZE_OK,
NPY_KEEPORDER,
NPY_SAME_KIND_CASTING,
@@ -949,7 +949,7 @@ arr_unravel_index(PyObject *self, PyObject *args, PyObject *kwds)
if (NpyIter_RemoveCoords(iter) != NPY_SUCCEED) {
goto fail;
}
- if (NpyIter_RemoveInnerLoop(iter) != NPY_SUCCEED) {
+ if (NpyIter_EnableExternalLoop(iter) != NPY_SUCCEED) {
goto fail;
}