Skip to content

Commit

Permalink
STY: Rename NPY_ITER_NO_INNER_ITERATION to NPY_ITER_EXTERNAL_LOOP
Browse files Browse the repository at this point in the history
It's a little bit shorter, and more intuitively expresses what the
flag does.
  • Loading branch information
mwiebe committed Mar 14, 2011
1 parent 6c7d3dd commit 6880bea
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 134 deletions.
45 changes: 23 additions & 22 deletions doc/source/reference/c-api.iterator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Here is a conversion table for which functions to use with the new iterator:
*Iterator Functions*
:cfunc:`PyArray_IterNew` :cfunc:`NpyIter_New`
:cfunc:`PyArray_IterAllButAxis` :cfunc:`NpyIter_New` + ``axes`` parameter **or**
Iterator flag :cdata:`NPY_ITER_NO_INNER_ITERATION`
Iterator flag :cdata:`NPY_ITER_EXTERNAL_LOOP`
:cfunc:`PyArray_BroadcastToShape` **NOT SUPPORTED** (Use the support for
multiple operands instead.)
:cfunc:`PyArrayIter_Check` Will need to add this in Python exposure
Expand All @@ -63,7 +63,7 @@ Here is a conversion table for which functions to use with the new iterator:
:cfunc:`NpyIter_GotoIterIndex`
:cfunc:`PyArray_MultiIter_NOTDONE` Return value of ``iternext`` function pointer
:cfunc:`PyArray_Broadcast` Handled by :cfunc:`NpyIter_MultiNew`
:cfunc:`PyArray_RemoveSmallest` Iterator flag :cdata:`NPY_ITER_NO_INNER_ITERATION`
:cfunc:`PyArray_RemoveSmallest` Iterator flag :cdata:`NPY_ITER_EXTERNAL_LOOP`
*Other Functions*
:cfunc:`PyArray_ConvertToCommonType` Iterator flag :cdata:`NPY_ITER_COMMON_DTYPE`
===================================== =============================================
Expand Down Expand Up @@ -97,7 +97,7 @@ number of non-zero elements in an array.
* Create and use an iterator to count the nonzeros.
* flag NPY_ITER_READONLY
* - The array is never written to.
* flag NPY_ITER_NO_INNER_ITERATION
* flag NPY_ITER_EXTERNAL_LOOP
* - Inner loop is done outside the iterator for efficiency.
* flag NPY_ITER_NPY_ITER_REFS_OK
* - Reference types are acceptable.
Expand All @@ -109,7 +109,7 @@ number of non-zero elements in an array.
* - No casting is required for this operation.
*/
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);
Expand Down Expand Up @@ -140,7 +140,7 @@ number of non-zero elements in an array.
npy_intp stride = *strideptr;
npy_intp count = *innersizeptr;
/* This is a typical inner loop for NPY_ITER_NO_INNER_ITERATION */
/* This is a typical inner loop for NPY_ITER_EXTERNAL_LOOP */
while (count--) {
if (nonzero(data, self)) {
++nonzero_count;
Expand Down Expand Up @@ -178,7 +178,7 @@ is used to control the memory layout of the allocated result, typically
/*
* No inner iteration - inner loop is handled by CopyArray code
*/
flags = NPY_ITER_NO_INNER_ITERATION;
flags = NPY_ITER_EXTERNAL_LOOP;
/*
* Tell the constructor to automatically allocate the output.
* The data type of the output will match that of the input.
Expand Down Expand Up @@ -366,10 +366,10 @@ Construction and Destruction
This prevents the iterator from coalescing axes to
produce bigger inner loops.

.. cvar:: NPY_ITER_NO_INNER_ITERATION
.. cvar:: NPY_ITER_EXTERNAL_LOOP

Causes the iterator to skip iteration of the innermost
loop, allowing the user of the iterator to handle it.
loop, requiring the user of the iterator to handle it.

This flag is incompatible with :cdata:`NPY_ITER_C_INDEX`,
:cdata:`NPY_ITER_F_INDEX`, and :cdata:`NPY_ITER_COORDS`.
Expand Down Expand Up @@ -436,7 +436,7 @@ Construction and Destruction
the function :cfunc:`NpyIter_ResetToIterIndexRange` to specify
a range for iteration.

This flag can only be used with :cdata:`NPY_ITER_NO_INNER_ITERATION`
This flag can only be used with :cdata:`NPY_ITER_EXTERNAL_LOOP`
when :cdata:`NPY_ITER_BUFFERED` is enabled. This is because
without buffering, the inner loop is always the size of the
innermost iteration dimension, and allowing it to get cut up
Expand All @@ -453,7 +453,7 @@ Construction and Destruction
code using the iterator, allowing for larger chunks
of data at once to amortize the Python interpreter overhead.

If used with :cdata:`NPY_ITER_NO_INNER_ITERATION`, the inner loop
If used with :cdata:`NPY_ITER_EXTERNAL_LOOP`, the inner loop
for the caller may get larger chunks than would be possible
without buffering, because of how the strides are laid out.

Expand Down Expand Up @@ -632,7 +632,7 @@ Construction and Destruction

The recommended approach to multithreaded iteration is to
first create an iterator with the flags
:cdata:`NPY_ITER_NO_INNER_ITERATION`, :cdata:`NPY_ITER_RANGED`,
:cdata:`NPY_ITER_EXTERNAL_LOOP`, :cdata:`NPY_ITER_RANGED`,
:cdata:`NPY_ITER_BUFFERED`, :cdata:`NPY_ITER_DELAY_BUFALLOC`, and
possibly :cdata:`NPY_ITER_GROWINNER`. Create a copy of this iterator
for each thread (minus one for the first iterator). Then, take
Expand Down Expand Up @@ -687,10 +687,10 @@ Construction and Destruction
Returns ``NPY_SUCCEED`` or ``NPY_FAIL``.

.. cfunction:: int NpyIter_RemoveInnerLoop(NpyIter* iter)
.. cfunction:: int NpyIter_EnableExternalLoop(NpyIter* iter)

If RemoveCoords was used, you may want to specify the
flag :cdata:`NPY_ITER_NO_INNER_ITERATION`. This flag is not permitted
If :cfunc:`NpyIter_RemoveCoords` was called, you may want to enable the
flag :cdata:`NPY_ITER_EXTERNAL_LOOP`. This flag is not permitted
together with :cdata:`NPY_ITER_COORDS`, so this function is provided
to enable the feature after :cfunc:`NpyIter_RemoveCoords` is called.
This function also resets the iterator to its initial state.
Expand Down Expand Up @@ -860,11 +860,12 @@ Construction and Destruction
to the iterator constructor, and no call to one of the Reset
functions has been done yet, 0 otherwise.

.. cfunction:: npy_bool NpyIter_HasInnerLoop(NpyIter* iter)
.. cfunction:: npy_bool NpyIter_HasExternalLoop(NpyIter* iter)

Returns 1 if the iterator handles the inner loop,
or 0 if the caller needs to handle it. This is controlled
by the constructor flag :cdata:`NPY_ITER_NO_INNER_ITERATION`.
Returns 1 if the caller needs to handle the inner-most 1-dimensional
loop, or 0 if the iterator handles all looping. This is controlled
by the constructor flag :cdata:`NPY_ITER_EXTERNAL_LOOP` or
:cfunc:`NpyIter_EnableExternalLoop`.

.. cfunction:: npy_bool NpyIter_HasCoords(NpyIter* iter)

Expand Down Expand Up @@ -1023,7 +1024,7 @@ Functions For Iteration
/* use the addresses dataptr[0], ... dataptr[niter-1] */
} while(iternext(iter));
When :cdata:`NPY_ITER_NO_INNER_ITERATION` is specified, the typical
When :cdata:`NPY_ITER_EXTERNAL_LOOP` is specified, the typical
inner loop construct is as follows.

.. code-block:: c
Expand All @@ -1050,7 +1051,7 @@ Functions For Iteration
with fresh values, not incrementally updated.

If a compile-time fixed buffer is being used (both flags
:cdata:`NPY_ITER_BUFFERED` and :cdata:`NPY_ITER_NO_INNER_ITERATION`), the
:cdata:`NPY_ITER_BUFFERED` and :cdata:`NPY_ITER_EXTERNAL_LOOP`), the
inner size may be used as a signal as well. The size is guaranteed
to become zero when ``iternext()`` returns false, enabling the
following loop construct. Note that if you use this construct,
Expand Down Expand Up @@ -1113,7 +1114,7 @@ Functions For Iteration
.. cfunction:: char** NpyIter_GetDataPtrArray(NpyIter* iter)

This gives back a pointer to the ``niter`` data pointers. If
:cdata:`NPY_ITER_NO_INNER_ITERATION` was not specified, each data
:cdata:`NPY_ITER_EXTERNAL_LOOP` was not specified, each data
pointer points to the current data item of the iterator. If
no inner iteration was specified, it points to the first data
item of the inner loop.
Expand All @@ -1140,7 +1141,7 @@ Functions For Iteration
the flags :cdata:`NPY_ITER_C_INDEX` or :cdata:`NPY_ITER_F_INDEX`
were specified during construction.

When the flag :cdata:`NPY_ITER_NO_INNER_ITERATION` is used, the code
When the flag :cdata:`NPY_ITER_EXTERNAL_LOOP` is used, the code
needs to know the parameters for doing the inner loop. These
functions provide that information.

Expand Down
4 changes: 2 additions & 2 deletions numpy/core/code_generators/numpy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@
'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,
Expand Down
4 changes: 2 additions & 2 deletions numpy/core/include/numpy/ndarraytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/einsum.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 6880bea

Please sign in to comment.