Skip to content

Commit 27987d2

Browse files
committed
ENH: iter: Add ability to do buffered iteration of reductions
This also tightens the error checking of reduction operations. Now if you want to allow a reduction, you must specify NPY_ITER_REDUCE_OK.
1 parent f6c5df8 commit 27987d2

File tree

4 files changed

+396
-113
lines changed

4 files changed

+396
-113
lines changed

numpy/core/include/numpy/ndarraytypes.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -887,14 +887,16 @@ typedef void (*NpyIter_GetCoords_Fn )(NpyIter *iter,
887887
#define NPY_ITER_REFS_OK 0x00000020
888888
/* Zero-sized operands should be permitted, iteration checks IterSize for 0 */
889889
#define NPY_ITER_ZEROSIZE_OK 0x00000040
890+
/* Permits reductions (size-0 stride with dimension size > 1) */
891+
#define NPY_ITER_REDUCE_OK 0x00000080
890892
/* Enables sub-range iteration */
891-
#define NPY_ITER_RANGED 0x00000080
893+
#define NPY_ITER_RANGED 0x00000100
892894
/* Enables buffering */
893-
#define NPY_ITER_BUFFERED 0x00000100
895+
#define NPY_ITER_BUFFERED 0x00000200
894896
/* When buffering is enabled, grows the inner loop if possible */
895-
#define NPY_ITER_GROWINNER 0x00000200
897+
#define NPY_ITER_GROWINNER 0x00000400
896898
/* Delay allocation of buffers until first Reset* call */
897-
#define NPY_ITER_DELAY_BUFALLOC 0x00000400
899+
#define NPY_ITER_DELAY_BUFALLOC 0x00000800
898900

899901
/*** Per-operand flags that may be passed to the iterator constructors ***/
900902

@@ -919,7 +921,7 @@ typedef void (*NpyIter_GetCoords_Fn )(NpyIter *iter,
919921
/* If an operand is allocated, don't use any subtype */
920922
#define NPY_ITER_NO_SUBTYPE 0x02000000
921923
/* Require that the dimension match the iterator dimensions exactly */
922-
#define NPY_ITER_NO_BROADCAST 0x04000000
924+
#define NPY_ITER_NO_BROADCAST 0x08000000
923925

924926
#define NPY_ITER_GLOBAL_FLAGS 0x0000ffff
925927
#define NPY_ITER_PER_OP_FLAGS 0xffff0000

0 commit comments

Comments
 (0)