Struct NDIterRef
High-performance multi-operand iterator matching NumPy's nditer API.
public ref struct NDIterRef
- Inherited Members
Properties
Finished
Check if iteration is finished.
public bool Finished { get; }
Property Value
HasExternalLoop
Whether iterator has external loop.
public bool HasExternalLoop { get; }
Property Value
HasGrowInner
Whether iterator uses GROWINNER optimization for buffering.
public bool HasGrowInner { get; }
Property Value
HasIdentPerm
Check if the axis permutation is identity (no reordering). Mutually exclusive with NEGPERM - if NEGPERM is set, IDENTPERM is cleared.
public bool HasIdentPerm { get; }
Property Value
HasIndex
Check if iterator is tracking a flat index.
public bool HasIndex { get; }
Property Value
HasMultiIndex
Check if iterator is tracking multi-index.
public bool HasMultiIndex { get; }
Property Value
HasNegPerm
Check if any axes have negative permutation entries (flipped for memory-order iteration). When NEGPERM is set, GetMultiIndex reverses indices for those axes.
public bool HasNegPerm { get; }
Property Value
HasWriteMaskedOperand
True if any operand is flagged WRITEMASKED (and a corresponding ARRAYMASK exists).
public bool HasWriteMaskedOperand { get; }
Property Value
IsContiguous
Whether all operands are contiguous.
public bool IsContiguous { get; }
Property Value
IsParallelSafe
Whether the iteration range can be split across parallel workers without write hazards (see PARALLEL_SAFE): no REDUCE operand, and either no WRITE operands or exactly one whose potential overlap with inputs was resolved by COPY_IF_OVERLAP.
public bool IsParallelSafe { get; }
Property Value
IsRanged
Check if iterator is using ranged iteration.
public bool IsRanged { get; }
Property Value
IsReduction
Check if iteration includes reduction operands.
public bool IsReduction { get; }
Property Value
IterEnd
Get the current iteration range end.
public long IterEnd { get; }
Property Value
IterIndex
Current iteration index.
public long IterIndex { get; }
Property Value
IterRange
Get the current iteration range as (start, end) tuple.
public (long Start, long End) IterRange { get; }
Property Value
IterSize
Total iteration count.
public long IterSize { get; }
Property Value
IterStart
Get the current iteration range start.
public long IterStart { get; }
Property Value
MaskOp
Index of the ARRAYMASK operand (used by WRITEMASKED operands), or -1 if none. Matches NumPy's NIT_MASKOP(iter).
public int MaskOp { get; }
Property Value
NDim
Number of dimensions after coalescing.
public int NDim { get; }
Property Value
NOp
Number of operands.
public int NOp { get; }
Property Value
RawState
public NDIterState* RawState { get; }
Property Value
RequiresBuffering
Whether iterator requires buffering.
public bool RequiresBuffering { get; }
Property Value
Shape
Get the current iterator shape in original axis order. When MULTI_INDEX is set, returns shape in original axis order. When NEGPERM is set, handles flipped axes correctly. Otherwise returns internal (possibly coalesced) shape.
public long[] Shape { get; }
Property Value
- long[]
Methods
AdvancedNew(int, NDArray[], NDIterGlobalFlags, NPY_ORDER, NPY_CASTING, NDIterPerOpFlags[], NPTypeCode[]?, int, int[][]?, long[]?, long)
Create iterator with full control over all parameters. Equivalent to NumPy's NDIter_AdvancedNew.
public static NDIterRef AdvancedNew(int nop, NDArray[] op, NDIterGlobalFlags flags, NPY_ORDER order, NPY_CASTING casting, NDIterPerOpFlags[] opFlags, NPTypeCode[]? opDtypes = null, int opAxesNDim = -1, int[][]? opAxes = null, long[]? iterShape = null, long bufferSize = 0)
Parameters
nopintopNDArray[]flagsNDIterGlobalFlagsorderNPY_ORDERcastingNPY_CASTINGopFlagsNDIterPerOpFlags[]opDtypesNPTypeCode[]opAxesNDimintopAxesint[][]iterShapelong[]bufferSizelong
Returns
BufferedReduce<TKernel, TAccum>(TKernel)
Reduction variant that honors REDUCE + BUFFER: uses BufferedReduceAdvance() and IsFirstVisit(int) to initialize the accumulator once per output slot. This is the NumPy-parity path for axis reductions that span multiple output elements.
public void BufferedReduce<TKernel, TAccum>(TKernel kernel) where TKernel : struct, INDReducingInnerLoop<TAccum> where TAccum : unmanaged
Parameters
kernelTKernel
Type Parameters
TKernelTAccum
Copy()
Create an independent copy of the iterator at its current position. Matches NumPy's NDIter_Copy behavior. The copy has its own state and can be advanced independently.
public NDIterRef Copy()
Returns
CreateCompatibleStrides(long, scoped Span<long>)
Builds a set of strides that match the iterator's axis ordering for a hypothetical contiguous array (like the result of NPY_ITER_ALLOCATE). Matches NumPy's NDIter_CreateCompatibleStrides (nditer_api.c:1058).
Use case: match the shape/layout of an iterator while tacking on extra
dimensions (e.g., gradient vector per element, Hessian matrix).
If an array is created with these strides, adding itemsize
each iteration traverses the array matching the iterator.
Requirements:
- Iterator must be tracking a multi-index (HASMULTIINDEX flag).
- No axis may be flipped (NPY_ITER_DONT_NEGATE_STRIDES must have been used, or the iterator must have no negative-stride axes to flip).
public bool CreateCompatibleStrides(long itemsize, scoped Span<long> outStrides)
Parameters
itemsizelongBase stride (typically element size in bytes).
outStridesSpan<long>Output span of length ≥ NDim, one stride per axis in original array order (C-order).
Returns
DebugPrint()
Dumps iterator state to standard output. See DebugPrint(TextWriter).
public void DebugPrint()
DebugPrint(TextWriter)
Dumps a verbose textual representation of the iterator's internal state to the specified TextWriter. Matches NumPy's NDIter_DebugPrint (nditer_api.c:1402) format as closely as possible.
Output includes: ItFlags (decoded), NDim, NOp, IterSize/Start/End/Index, Perm, DTypes, DataPtrs, BaseOffsets, OpItFlags, BufferData, and per-axis data.
public void DebugPrint(TextWriter writer)
Parameters
writerTextWriter
DebugPrintToString()
Returns the debug dump as a string.
public string DebugPrintToString()
Returns
DetectExecutionPath()
Pick the right ExecutionPath for MixedType/Comparison kernel selection by scanning the post-coalesce stride picture.
public ExecutionPath DetectExecutionPath()
Returns
Dispose()
Deallocate iterator resources.
public void Dispose()
EnableExternalLoop()
Enable external loop handling.
public bool EnableExternalLoop()
Returns
EnsureBuffersReady()
Materialize DELAY_BUFALLOC buffers and prime the first window. No-op unless BUFFER+DELAYBUF are pending. NumPy requires an explicit Reset before iterating a delay-allocated iterator; NumSharp auto-ensures at the execution entry points instead.
public void EnsureBuffersReady()
ExecuteBinary(BinaryOp)
Run a binary ufunc over three operands [in0, in1, out]. Picks SimdFull / SimdScalarRight / SimdScalarLeft / SimdChunk / General based on the iterator's stride picture after coalescing.
public void ExecuteBinary(BinaryOp op)
Parameters
opBinaryOp
ExecuteComparison(ComparisonOp)
Element-wise comparison → bool output. Same 3-operand shape as ExecuteBinary but the output is always Boolean.
public void ExecuteComparison(ComparisonOp op)
Parameters
opComparisonOp
ExecuteCopy()
Same-type copy with broadcast. When both operands are contiguous
the kernel collapses to cpblk.
public void ExecuteCopy()
ExecuteElementWise(NPTypeCode[], Action<ILGenerator>, Action<ILGenerator>?, string)
Compile and run an element-wise kernel using user-supplied scalar and optional vector emit bodies. The factory wraps the bodies in a 4×-unrolled SIMD loop (when the operand types allow) plus a scalar-strided fallback for non-contiguous inner axes.
public void ExecuteElementWise(NPTypeCode[] operandTypes, Action<ILGenerator> scalarBody, Action<ILGenerator>? vectorBody, string cacheKey)
Parameters
operandTypesNPTypeCode[][input0, input1, ..., output] — one entry per iterator operand. Length must equal NOp.
scalarBodyAction<ILGenerator>Per-element IL body. On entry, stack holds the N input values (operand 0 deepest, operand N-1 on top). On exit, stack must hold exactly one value of the output dtype.
vectorBodyAction<ILGenerator>Per-vector IL body (optional). When supplied AND all operand dtypes are identical AND SIMD-capable, emitted as the fast path. Stack contract mirrors
scalarBodybut withVector{W}<T>in place of scalar values.cacheKeystringUnique identifier for this kernel.
ExecuteElementWiseBinary(NPTypeCode, NPTypeCode, NPTypeCode, Action<ILGenerator>, Action<ILGenerator>?, string)
Convenience: 2-input + 1-output (binary).
public void ExecuteElementWiseBinary(NPTypeCode lhs, NPTypeCode rhs, NPTypeCode outType, Action<ILGenerator> scalarBody, Action<ILGenerator>? vectorBody, string cacheKey)
Parameters
lhsNPTypeCoderhsNPTypeCodeoutTypeNPTypeCodescalarBodyAction<ILGenerator>vectorBodyAction<ILGenerator>cacheKeystring
ExecuteElementWiseTernary(NPTypeCode, NPTypeCode, NPTypeCode, NPTypeCode, Action<ILGenerator>, Action<ILGenerator>?, string)
Convenience: 3-input + 1-output (ternary, FMA-shaped).
public void ExecuteElementWiseTernary(NPTypeCode a, NPTypeCode b, NPTypeCode c, NPTypeCode outType, Action<ILGenerator> scalarBody, Action<ILGenerator>? vectorBody, string cacheKey)
Parameters
aNPTypeCodebNPTypeCodecNPTypeCodeoutTypeNPTypeCodescalarBodyAction<ILGenerator>vectorBodyAction<ILGenerator>cacheKeystring
ExecuteElementWiseUnary(NPTypeCode, NPTypeCode, Action<ILGenerator>, Action<ILGenerator>?, string)
Convenience: 1-input + 1-output (unary).
public void ExecuteElementWiseUnary(NPTypeCode inType, NPTypeCode outType, Action<ILGenerator> scalarBody, Action<ILGenerator>? vectorBody, string cacheKey)
Parameters
inTypeNPTypeCodeoutTypeNPTypeCodescalarBodyAction<ILGenerator>vectorBodyAction<ILGenerator>cacheKeystring
ExecuteExpression(NDExpr, NPTypeCode[], NPTypeCode, string?)
Compile and run an expression tree over the iterator's operands. The tree's leaves reference inputs by position (NDExpr.Input(i)) and constants; interior nodes combine them via primitive ops. The compiler produces the same style of kernel as ExecuteElementWise(NPTypeCode[], Action<ILGenerator>, Action<ILGenerator>?, string).
public void ExecuteExpression(NDExpr expression, NPTypeCode[] inputTypes, NPTypeCode outputType, string? cacheKey = null)
Parameters
expressionNDExprRoot of the expression tree.
inputTypesNPTypeCode[]Dtypes of the first N operands (all inputs). Length must equal NOp - 1.
outputTypeNPTypeCodeDtype of the last operand (the output).
cacheKeystringOptional cache key; if null, a key is derived from the tree's structural signature.
ExecuteGeneric<TKernel>(TKernel)
Struct-generic overload — the JIT devirtualizes and inlines the kernel call through the TKernel type parameter. Preferred when the kernel is known at call site.
Performance note: the single-iteration fast path (coalesced + EXLOOP or ONEITERATION) avoids the do/while + delegate call so the JIT can autovectorize the kernel body.
public void ExecuteGeneric<TKernel>(TKernel kernel) where TKernel : struct, INDInnerLoop
Parameters
kernelTKernel
Type Parameters
TKernel
ExecuteRawIL(Action<ILGenerator>, string, void*)
Compile and run a user-authored inner-loop kernel. The delegate
signature is NDInnerLoopFunc; the body must emit
its own ret. Cached by cacheKey, so the
IL generator is invoked exactly once per key.
public void ExecuteRawIL(Action<ILGenerator> emitBody, string cacheKey, void* auxdata = null)
Parameters
emitBodyAction<ILGenerator>cacheKeystringauxdatavoid*
Remarks
The caller is responsible for cacheKey uniqueness: two different IL bodies compiled under the same key will silently alias.
ExecuteReducing<TKernel, TAccum>(TKernel, TAccum)
Reducing variant. The accumulator is passed by reference; return
false from the kernel to abort (used by All/Any early exit).
public TAccum ExecuteReducing<TKernel, TAccum>(TKernel kernel, TAccum init) where TKernel : struct, INDReducingInnerLoop<TAccum> where TAccum : unmanaged
Parameters
kernelTKernelinitTAccum
Returns
- TAccum
Type Parameters
TKernelTAccum
ExecuteReduction<TResult>(ReductionOp)
Reduce a single operand to a scalar of type TResult.
If the iterator has BUFFER + REDUCE set, the double-loop reduction
schedule is used via BufferedReduce<TResult>. Otherwise
we let the IL kernel iterate the array directly.
public TResult ExecuteReduction<TResult>(ReductionOp op) where TResult : unmanaged
Parameters
opReductionOp
Returns
- TResult
Type Parameters
TResult
ExecuteScan(ReductionOp)
Cumulative scan (CumSum, CumProd) over [in, out].
public void ExecuteScan(ReductionOp op)
Parameters
opReductionOp
ExecuteUnary(UnaryOp)
Run a unary op over [in, out].
public void ExecuteUnary(UnaryOp op)
Parameters
opUnaryOp
ForEach(NDInnerLoopFunc, void*)
Drive the iterator with a user-supplied inner-loop kernel. Matches the pattern used by NumPy ufuncs in C:
do { inner(dataptrs, strides, count, aux); } while (iternext);
The iterator decides the semantics: • Fully coalesced + contiguous → 1 call covering IterSize elements. • EXTERNAL_LOOP → 1 call per outer index, count = inner dim size. • Buffered → 1 call per buffer fill, count = BufIterEnd. • Otherwise → 1 call per element, count = 1.
public void ForEach(NDInnerLoopFunc kernel, void* auxdata = null)
Parameters
kernelNDInnerLoopFuncauxdatavoid*
FreeState(NDIterState*)
Tear down a state pointer previously obtained from ReleaseState(). Mirrors Dispose()'s cleanup path but operates on a bare pointer so long-lived owners can free the state without reconstructing an NDIterRef.
public static void FreeState(NDIterState* state)
Parameters
stateNDIterState*
GetAxisStrideArray(int, scoped Span<long>)
Gets the array of strides for the specified axis, one stride per operand. Matches NumPy's NDIter_GetAxisStrideArray (nditer_api.c:1309).
If the iterator is tracking a multi-index, returns strides for the user-supplied
axis in original-array coordinates (perm is walked to locate the internal axis).
Otherwise returns strides for iteration axis axis in Fortran
order (fastest-changing axis first).
Strides are returned in BYTES (multiplying NumSharp's internal element-count strides by the operand's element size) to match NumPy's byte-stride convention.
public void GetAxisStrideArray(int axis, scoped Span<long> outStrides)
Parameters
axisintAxis index (0-based). With HASMULTIINDEX: original-array axis. Without: fastest-changing-first (Fortran) ordering.
outStridesSpan<long>Output span of length ≥ NOp; filled with byte strides.
GetDataPtr(int)
Get pointer to current data for operand. When buffering is enabled, returns pointer to buffer position. Otherwise returns pointer to source array position. Matches NumPy's dataptrs[i] access.
public void* GetDataPtr(int operand)
Parameters
operandint
Returns
- void*
GetDataPtrArray()
Get array of current data pointers.
public void** GetDataPtrArray()
Returns
- void**
GetDescrArray()
Get operand dtypes.
public NPTypeCode[] GetDescrArray()
Returns
GetIndex()
Get the current flat index. Requires C_INDEX or F_INDEX flag to be set during construction.
public long GetIndex()
Returns
GetInnerFixedStrideArray(scoped Span<long>)
Copies the array of strides that are fixed during iteration into outStrides.
Matches NumPy's NDIter_GetInnerFixedStrideArray (nditer_api.c:1357).
Buffered iterators copy BufStrides. Non-buffered iterators copy the innermost-axis stride from Strides and convert it to bytes.
public void GetInnerFixedStrideArray(scoped Span<long> outStrides)
Parameters
GetInnerLoopSizePtr()
Get pointer to inner loop size.
public long* GetInnerLoopSizePtr()
Returns
- long*
GetInnerStrideArray()
Get inner loop stride array.
public long* GetInnerStrideArray()
Returns
- long*
GetIterNext()
Get the iteration-advance function.
public NDIterNextFunc GetIterNext()
Returns
GetIterView(int)
Returns a view of the i-th operand with the iterator's internal axes ordering. A C-order iteration of this view is equivalent to the iterator's iteration order.
For example, if a 3D array was coalesced to 1D, this returns a 1D view. If axes were reordered for memory efficiency, this reflects that reordering.
Not available when buffering is enabled. Matches NumPy's NDIter_GetIterView behavior.
public NDArray GetIterView(int operand)
Parameters
operandintThe operand index (0 to NOp-1)
Returns
- NDArray
An NDArray view with the iterator's internal shape and strides
GetMultiIndex(scoped Span<long>)
Get the current multi-index (coordinates) in original axis order. Uses the Perm array to map internal coordinates to original array coordinates. When NEGPERM is set, flipped axes have negative perm entries and their coordinates are reversed (shape - coord - 1). Requires MULTI_INDEX flag to be set during construction.
public void GetMultiIndex(scoped Span<long> outCoords)
Parameters
GetMultiIndexFunc()
Returns a specialized delegate for computing multi-index. Matches NumPy's NDIter_GetGetMultiIndex. Throws on failure instead of returning null (thin wrapper over the out-errmsg overload).
public NDIterGetMultiIndexFunc GetMultiIndexFunc()
Returns
GetMultiIndexFunc(out string?)
Returns a specialized delegate for computing multi-index based on iterator flags. Matches NumPy's NDIter_GetGetMultiIndex (nditer_templ.c.src:481).
NumPy generates 12 specializations on (HASINDEX × IDENTPERM × NEGPERM × BUFFER). NumSharp dispatches to 3 variants (BUFFER and HASINDEX don't affect coords):
- IDENTPERM — direct copy of internal coords
- Positive perm — apply perm[] mapping
- NEGPERM — apply perm[] with flip decoding
The returned delegate takes raw NDIterState and a pointer to output coords.
public NDIterGetMultiIndexFunc? GetMultiIndexFunc(out string? errmsg)
Parameters
errmsgstringSet on failure; null on success.
Returns
- NDIterGetMultiIndexFunc
Delegate, or null if iterator is not tracking multi-index.
GetOperandArray()
Get operand arrays.
public NDArray[]? GetOperandArray()
Returns
- NDArray[]
GetTransferFlags()
Fetch the NDArrayMethodFlags (runtime) flags for all transfer functions (i.e. copy to buffer/casts). Matches NumPy's NDIter_GetTransferFlags (nditer_api.c:903). Decoded from the top 8 bits of ItFlags.
In .NET context, REQUIRES_PYAPI is never set — included for API parity only.
public NDArrayMethodFlags GetTransferFlags()
Returns
GetValue<T>(int)
Get current value for operand as T. When buffering with casting is enabled, reads from buffer (which has target dtype).
public T GetValue<T>(int operand = 0) where T : unmanaged
Parameters
operandint
Returns
- T
Type Parameters
T
GotoIndex(long)
Jump to a specific flat index position (C or F order based on construction flags). Requires C_INDEX or F_INDEX flag to be set during construction. Matches NumPy's NDIter_GotoIndex behavior. When NEGPERM is set, handles flipped axes correctly.
public void GotoIndex(long flatIndex)
Parameters
flatIndexlongThe flat index in C or F order (depending on flags)
GotoIterIndex(long)
Jump to a specific iteration index.
public void GotoIterIndex(long iterindex)
Parameters
iterindexlong
GotoMultiIndex(scoped ReadOnlySpan<long>)
Jump to a specific multi-index (coordinates) given in original axis order. Uses the Perm array to map original coordinates to internal iteration order. When NEGPERM is set, flipped axes have negative perm entries and their coordinates are reversed when mapping to internal coordinates. Requires MULTI_INDEX flag to be set during construction.
public void GotoMultiIndex(scoped ReadOnlySpan<long> coords)
Parameters
coordsReadOnlySpan<long>
InvokeMultiIndex(NDIterGetMultiIndexFunc, long*)
Invokes the specialized multi-index delegate with this iterator's internal state.
This mirrors NumPy's pattern: fn(iter, outcoords), where NumSharp's iterator
handle is a ref struct and the state is held internally.
public void InvokeMultiIndex(NDIterGetMultiIndexFunc fn, long* outCoords)
Parameters
fnNDIterGetMultiIndexFuncoutCoordslong*
InvokeMultiIndex(NDIterGetMultiIndexFunc, scoped Span<long>)
Span overload of InvokeMultiIndex(NDIterGetMultiIndexFunc, long*).
public void InvokeMultiIndex(NDIterGetMultiIndexFunc fn, scoped Span<long> outCoords)
Parameters
fnNDIterGetMultiIndexFuncoutCoordsSpan<long>
IsFirstVisit(int)
Check if this is the first visit to the current element of a reduction operand. This is used for initialization (e.g., set to 0 before summing).
For reduction operands (stride=0 on some axes), returns true when all coordinates on reduction axes are 0. Returns false when any coordinate on a reduction axis is non-zero (meaning we've already visited this output element from another input element).
For non-reduction operands, always returns true (every visit is "first").
Matches NumPy's NDIter_IsFirstVisit behavior.
public bool IsFirstVisit(int operand)
Parameters
operandint
Returns
IsOperandReduction(int)
Check if a specific operand is a reduction operand (has stride=0 for READWRITE).
public bool IsOperandReduction(int operand)
Parameters
operandint
Returns
Iternext()
Advance to next position and return whether more iterations remain. Matches NumPy's iternext() behavior. Returns true if more elements exist, false when iteration is complete.
When BUFFERED + REDUCE flags are set, uses the double-loop pattern from NumPy's npyiter_buffered_reduce_iternext (nditer_templ.c.src lines 131-210).
public bool Iternext()
Returns
MultiNew(int, NDArray[], NDIterGlobalFlags, NPY_ORDER, NPY_CASTING, NDIterPerOpFlags[], NPTypeCode[]?)
Create multi-operand iterator. Equivalent to NumPy's NDIter_MultiNew.
public static NDIterRef MultiNew(int nop, NDArray[] op, NDIterGlobalFlags flags, NPY_ORDER order, NPY_CASTING casting, NDIterPerOpFlags[] opFlags, NPTypeCode[]? opDtypes = null)
Parameters
nopintopNDArray[]flagsNDIterGlobalFlagsorderNPY_ORDERcastingNPY_CASTINGopFlagsNDIterPerOpFlags[]opDtypesNPTypeCode[]
Returns
New(NDArray, NDIterGlobalFlags, NPY_ORDER, NPY_CASTING, NPTypeCode?)
Create single-operand iterator. Equivalent to NumPy's NDIter_New.
public static NDIterRef New(NDArray op, NDIterGlobalFlags flags = NDIterGlobalFlags.None, NPY_ORDER order = NPY_ORDER.NPY_KEEPORDER, NPY_CASTING casting = NPY_CASTING.NPY_SAFE_CASTING, NPTypeCode? dtype = null)
Parameters
opNDArrayflagsNDIterGlobalFlagsorderNPY_ORDERcastingNPY_CASTINGdtypeNPTypeCode?
Returns
NewReduce(NDArray, NDArray, int, NDIterGlobalFlags)
Build a 2-operand REDUCE iterator over input reducing
the single axis axis into output.
output must already have the reduced shape
(input shape with axis removed) and be pre-seeded with
the reduction identity.
public static NDIterRef NewReduce(NDArray input, NDArray output, int axis, NDIterGlobalFlags extraFlags = NDIterGlobalFlags.None)
Parameters
inputNDArrayRead-only source operand.
outputNDArrayRead-write destination; reduced shape, identity-seeded.
axisintNormalized (non-negative) axis to reduce.
extraFlagsNDIterGlobalFlagsExtra global flags OR-ed onto REDUCE_OK|EXTERNAL_LOOP.
Returns
NewReduce(NDArray, NDArray, int[], NDIterGlobalFlags)
Multi-axis variant of NewReduce(NDArray, NDArray, int, NDIterGlobalFlags).
Every axis in axes is reduced (stride 0 in the output);
the remaining axes map to the output in ascending order. axes
must be normalized (non-negative) and contain no duplicates.
public static NDIterRef NewReduce(NDArray input, NDArray output, int[] axes, NDIterGlobalFlags extraFlags = NDIterGlobalFlags.None)
Parameters
inputNDArrayoutputNDArrayaxesint[]extraFlagsNDIterGlobalFlags
Returns
ReleaseState()
Transfer ownership of the underlying NDIterState pointer out of this NDIterRef. After the call, this instance's Dispose() is a no-op and the returned pointer becomes the caller's responsibility to free via FreeState(NDIterState*) (or equivalent manual teardown: FreeBuffers(ref NDIterState) when BUFFER is set, FreeDimArrays(), and Free(void*)).
Intended for callers that need to hold the iterator state across a non-ref-struct boundary (class fields, long-lived objects) where a ref struct can't live.
public NDIterState* ReleaseState()
Returns
RemoveAxis(int)
Remove axis from iteration (enables external loop for that axis). Matches NumPy's NDIter_RemoveAxis behavior.
public bool RemoveAxis(int axis)
Parameters
axisint
Returns
RemoveMultiIndex()
Remove multi-index tracking and enable coalescing. Matches NumPy's NDIter_RemoveMultiIndex behavior. Note: Resets iterator position to the beginning.
public bool RemoveMultiIndex()
Returns
Reset()
Reset iterator to the beginning. For windowed buffered iterators this flushes the pending window (NumPy flushes in NDIter_Reset too), materializes DELAY_BUFALLOC buffers, and primes the first window.
public bool Reset()
Returns
ResetBasePointers(NDArray[])
Convenience overload: resets base pointers using the data pointers of new NDArray operands. The new arrays must have the same shape, dtype, and layout as the original operands.
public bool ResetBasePointers(NDArray[] newOperands)
Parameters
newOperandsNDArray[]
Returns
ResetBasePointers(scoped ReadOnlySpan<nint>)
Resets the iterator to its initial state with new base data pointers. Matches NumPy's NDIter_ResetBasePointers (nditer_api.c:314).
For each operand, sets resetdataptr[iop] = baseptrs[iop] + baseoffsets[iop], where baseoffsets is the cumulative byte offset recorded by FlipNegativeStrides. Then repositions the iterator to IterStart.
The new arrays pointed to by baseptrs MUST have the exact same shape, dtype, and memory layout as the original operands. This is typically used in nested iteration (ufunc-style) where one iterator feeds data pointers to another.
Throws ArgumentException if baseptrs.Length != NOp.
public bool ResetBasePointers(scoped ReadOnlySpan<nint> baseptrs)
Parameters
baseptrsReadOnlySpan<nint>Array of new base data pointers, one per operand.
Returns
- bool
True on success.
ResetToIterIndexRange(long, long)
Reset iterator to a specific iteration range. Enables ranged iteration for parallel chunking.
public bool ResetToIterIndexRange(long start, long end)
Parameters
Returns
- bool
True if range is valid, false otherwise
SetValue<T>(T, int)
Set current value for operand. When buffering with casting is enabled, writes to buffer (which has target dtype).
public void SetValue<T>(T value, int operand = 0) where T : unmanaged
Parameters
valueToperandint
Type Parameters
T