numpy  2.0.0
src/multiarray/nditer_templ.c.src File Reference
#include "nditer_impl.h"

Defines

#define NPY_ITERATOR_IMPLEMENTATION_CODE

Functions

static int
npyiter_iternext_itflags
tag_itflags _dims tag_ndim
_iters 
tag_nop (NpyIter *iter)
static int npyiter_buffered_iternext (NpyIter *iter)
static int npyiter_iternext_sizeone (NpyIter *iter)
NPY_NO_EXPORT
NpyIter_IterNextFunc
NpyIter_GetIterNext (NpyIter *iter, char **errmsg)
static void
npyiter_get_multi_index_itflags 
tag_itflags (NpyIter *iter, npy_intp *out_multi_index)
NPY_NO_EXPORT
NpyIter_GetMultiIndexFunc
NpyIter_GetGetMultiIndex (NpyIter *iter, char **errmsg)

Define Documentation

Indicate that this .c file is allowed to include the header

Function Documentation

static int npyiter_buffered_iternext ( NpyIter iter) [static]
end repeat*
iternext function that handles the buffering part
int ndim = NIT_NDIM(iter);
If the iterator handles the inner loop, need to increment all the indices and pointers
Increment within the buffer
Write back to the arrays
Check if we're past the end
Increment to the next buffer
Prepare the next buffers and set iterend/size

References tag_itflags(), and tag_nop().

end repeat*
Compute a specialized get_multi_index function for the iterator <blockquote> If errmsg is non-NULL, it should point to a variable which will receive the error message, and no Python exception will be set. This is so that the function can be called from code not holding the GIL.</blockquote>
These flags must be correct
Only these flags affect the iterator memory layout or the get_multi_index behavior. IDENTPERM and NEGPERM are mutually exclusive, so that reduces the number of cases slightly.
begin repeat
#const_itflags = 0,
NPY_ITFLAG_HASINDEX, NPY_ITFLAG_IDENTPERM, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM, NPY_ITFLAG_NEGPERM, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM, NPY_ITFLAG_BUFFER, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_BUFFER, NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER, NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER#
tag_itflags = 0, IND, IDP, INDuIDP, NEGP, INDuNEGP,
BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF#
end repeat*
The switch above should have caught all the possibilities.
Compute the specialized iteration function for an iterator <blockquote> If errmsg is non-NULL, it should point to a variable which will receive the error message, and no Python exception will be set. This is so that the function can be called from code not holding the GIL.</blockquote>
When there is just one iteration and buffering is disabled the iternext function is very simple.
If buffering is enabled.
Ignore all the flags that don't affect the iterator memory layout or the iternext function. Currently only HASINDEX, EXLOOP, and RANGE affect them here.
Switch statements let the compiler optimize this most effectively
The combinations HASINDEX|EXLOOP and RANGE|EXLOOP are excluded by the New functions
begin repeat
#const_itflags = 0,
NPY_ITFLAG_HASINDEX, NPY_ITFLAG_EXLOOP, NPY_ITFLAG_RANGE, NPY_ITFLAG_RANGE|NPY_ITFLAG_HASINDEX#
System Message: WARNING/2 (<string>, line 7) Definition list ends without a blank line; unexpected unindent.

tag_itflags = 0, IND, NOINN, RNG, RNGuIND#

begin repeat1
#const_ndim = 1, 2# #tag_ndim = 1, 2#
begin repeat2
#const_nop = 1, 2# tag_nop = 1, 2#
end repeat2*
Not specialized on nop
end repeat1*
Not specialized on ndim
begin repeat1
#const_nop = 1, 2# tag_nop = 1, 2#
end repeat1*
Not specialized on nop
end repeat*
The switch above should have caught all the possibilities.

Referenced by apply_business_day_count(), and business_day_offset().

static int npyiter_iternext_sizeone ( NpyIter iter) [static]
end repeat2*
end repeat1*
end repeat*
Specialization of iternext for when the iteration size is 1
static void npyiter_get_multi_index_itflags tag_itflags ( NpyIter iter,
npy_intp out_multi_index 
) [static]
SPECIALIZED getindex functions
begin repeat
#const_itflags = 0,
NPY_ITFLAG_HASINDEX, NPY_ITFLAG_IDENTPERM, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM, NPY_ITFLAG_NEGPERM, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM, NPY_ITFLAG_BUFFER, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_BUFFER, NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_IDENTPERM|NPY_ITFLAG_BUFFER, NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER, NPY_ITFLAG_HASINDEX|NPY_ITFLAG_NEGPERM|NPY_ITFLAG_BUFFER#
tag_itflags = 0, IND, IDP, INDuIDP, NEGP, INDuNEGP,
BUF, INDuBUF, IDPuBUF, INDuIDPuBUF, NEGPuBUF, INDuNEGPuBUF#

Referenced by npyiter_buffered_iternext().

static int npyiter_buffered_reduce_iternext_iters tag_nop ( NpyIter iter) [static]
SPECIALIZED iternext functions that handle the non-buffering part
begin repeat
#const_itflags = 0,
NPY_ITFLAG_HASINDEX, NPY_ITFLAG_EXLOOP, NPY_ITFLAG_RANGE, NPY_ITFLAG_RANGE|NPY_ITFLAG_HASINDEX#
System Message: WARNING/2 (<string>, line 7) Definition list ends without a blank line; unexpected unindent.

tag_itflags = 0, IND, NOINN, RNG, RNGuIND#

begin repeat1
#const_ndim = 1, 2, NPY_MAXDIMS# #tag_ndim = 1, 2, ANY#
begin repeat2
#const_nop = 1, 2, NPY_MAXDIMS# tag_nop = 1, 2, ANY#
Specialized iternext (&#64;const_itflags&#64;,&#64;tag_ndim&#64;,&#64;tag_nop&#64;)
end repeat2*
end repeat1*
end repeat*
begin repeat
#const_nop = 1, 2, 3, 4, NPY_MAXDIMS# tag_nop = 1, 2, 3, 4, ANY#
Iternext function that handles the reduction buffering part. This is done with a double loop to avoid frequent re-buffering.
Increment index 1
Increment pointer 1
Reset the 1st index to 0
Reset the 1st pointer to the value of the 2nd
Increment index 2
Increment pointer 2
Reset the 1st and 2nd indices to 0
Reset the 1st and 2nd pointers to the value of the 3nd
Increment the index
Increment the pointer
Reset the indices and pointers of all previous axisdatas
Reset the index to 0
Reset the pointer to the updated value

<

ndim != 2

<

ndim != 1
int ndim = NIT_NDIM(iter);
If the iterator handles the inner loop, need to increment all the indices and pointers
Increment within the buffer
The outer increment for the reduce double loop
Save the previously used data pointers
Write back to the arrays
Check if we're past the end
Increment to the next buffer
Prepare the next buffers and set iterend/size

Referenced by npyiter_buffered_iternext().