Table of Contents

Enum NDIterFlags

Namespace
NumSharp.Backends.Iteration
Assembly
NumSharp.dll

Iterator-level flags. Conceptually matches NumPy's NPY_ITFLAG_* constants.

NOTE: Bit positions differ from NumPy's implementation:

  • NumPy uses bits 0-7 for IDENTPERM, NEGPERM, HASINDEX, etc.
  • NumSharp reserves bits 0-7 for legacy compatibility flags (SourceBroadcast, SourceContiguous, DestinationContiguous)
  • NumPy-equivalent flags are shifted to bits 8-15

This layout maintains backward compatibility with existing NumSharp code while adding NumPy parity flags. The semantic meaning of each flag matches NumPy, only the bit positions differ.

[Flags]
public enum NDIterFlags : uint

Fields

None = 0
SourceBroadcast = 1

Source operand has broadcast dimensions (stride=0).

SourceContiguous = 2

Source operand is contiguous after coalescing.

DestinationContiguous = 4

Destination operand is contiguous after coalescing.

IDENTPERM = 256

The axis permutation is identity.

NEGPERM = 512

The permutation has negative entries (flipped axes).

HASINDEX = 1024

Iterator is tracking a flat index.

HASMULTIINDEX = 2048

Iterator is tracking a multi-index.

FORCEDORDER = 4096

Iteration order was forced on construction.

EXLOOP = 8192

Inner loop is handled outside the iterator.

RANGE = 16384

Iterator is ranged (subset iteration).

BUFFER = 32768

Iterator uses buffering.

GROWINNER = 65536

Grow the buffered inner loop when possible.

ONEITERATION = 131072

Single iteration, can specialize iternext.

DELAYBUF = 262144

Delay buffer allocation until first Reset.

REDUCE = 524288

Iteration includes reduction operands.

REUSE_REDUCE_LOOPS = 1048576

Reduce loops don't need recalculation.

BUFREDUCE = 2097152

The buffered iteration runs NumPy's reduce DOUBLE LOOP: npyiter_find_buffering_setup chose the outer reduce dimension as the core / outer split, so each buffer fill is walked as up to ReduceOuterSize inner loops of CoreSize elements, the pointers stepping by ReduceOuterStrides between them (npyiter_buffered_reduce_iternext).

This is what NumPy's NPY_ITFLAG_REDUCE means AFTER the buffering setup, which clears that flag when the chosen split does not use the reduce loop. NumSharp keeps REDUCE as the construction's answer ("an operand is reduced") because IsReduction, the parallel-safety decision and IsFirstVisit(int) read it, and records the setup's answer here. Set only together with BUFFER.

CONTIGUOUS = 8

All operands are contiguous (SIMD eligible).

GATHER_ELIGIBLE = 16

Can use AVX2 gather for strided access.

PARALLEL_SAFE = 64

The iteration range can be split across parallel workers without write hazards. Set at construction when there is no REDUCE operand (cross-iteration accumulation on a shared slot) and either no WRITE operands at all, or exactly one WRITE operand whose potential overlap with the inputs was resolved by COPY_IF_OVERLAP processing (forced copy + write-back on Dispose). Consumed by the parallel ForEach work (roadmap Wave 6.2).