Class NDIter
Static iterator helper methods (backward compatible API).
NUMSHARP DIVERGENCE: These methods support unlimited dimensions via dynamic allocation. Dimension arrays are allocated on demand and freed after use.
public static class NDIter
- Inheritance
-
NDIter
- Inherited Members
Methods
Advance(long*, long*, long*, int, ref long)
public static void Advance(long* shape, long* strides, long* coords, int ndim, ref long offset)
Parameters
CoalesceAxes(ref NDIterState, long*, long*, long*)
public static void CoalesceAxes(ref NDIterState state, long* shape, long* srcStrides, long* dstStrides)
Parameters
stateNDIterStateshapelong*srcStrideslong*dstStrideslong*
Copy(UnmanagedStorage, UnmanagedStorage)
Copy src into dst with full
support for broadcast, stride, and cross-dtype conversion.
- Same dtype (the common case) routes through the SIMD-accelerated TryCopySameType(UnmanagedStorage, UnmanagedStorage) IL copy kernel — broadcast and arbitrary strides are absorbed by the coalesced iteration state.
- Cross dtype falls through to a per-element cast loop (CopyStridedToStridedWithCast(void*, long*, NPTypeCode, void*, long*, NPTypeCode, long*, int, long)) reusing the same broadcast/coalescing state.
Drop-in replacement for the legacy MultiIterator.Assign(dst, src):
matches its broadcast-src-to-dst-shape semantics and its cast-on-write
behavior (read src as src.TypeCode, convert, write dst.TypeCode).
public static void Copy(UnmanagedStorage dst, UnmanagedStorage src)
Parameters
dstUnmanagedStoragesrcUnmanagedStorage
Exceptions
- NumSharpException
If
dstis not writeable (e.g., broadcast view).
Copy(NDArray, NDArray)
Copy src into dst with full
support for broadcast, stride, and cross-dtype conversion.
- Same dtype (the common case) routes through the SIMD-accelerated TryCopySameType(UnmanagedStorage, UnmanagedStorage) IL copy kernel — broadcast and arbitrary strides are absorbed by the coalesced iteration state.
- Cross dtype falls through to a per-element cast loop (CopyStridedToStridedWithCast(void*, long*, NPTypeCode, void*, long*, NPTypeCode, long*, int, long)) reusing the same broadcast/coalescing state.
Drop-in replacement for the legacy MultiIterator.Assign(dst, src):
matches its broadcast-src-to-dst-shape semantics and its cast-on-write
behavior (read src as src.TypeCode, convert, write dst.TypeCode).
public static void Copy(NDArray dst, NDArray src)
Parameters
Exceptions
- NumSharpException
If
dstis not writeable (e.g., broadcast view).
CopyAs(NPTypeCode, NDArray, char, TensorEngine)
The unified allocate-and-fill core for copying, retyping, and casting. Allocates a
fresh array of dstType whose physical layout follows
order (NumPy C/F/A/K resolved via NumSharp.OrderResolver),
then fills it from src through the in-place Copy(NDArray, NDArray)
primitive. Every elementwise concern — broadcast, arbitrary strides, transpose, and
cross-dtype conversion — is absorbed by the NDIter copy core, so a single call covers
ndarray.copy(), astype(), and Clone() alike.
public static NDArray CopyAs(NPTypeCode dstType, NDArray src, char order = 'K', TensorEngine engine = null)
Parameters
dstTypeNPTypeCodedtype of the result (equal to
src's dtype for a plain copy/retype).srcNDArraysource array of any layout (contiguous, sliced, strided, broadcast, transposed, scalar, empty).
orderchar'C' (row-major), 'F' (column-major), 'A' ('F' iff src is F-contiguous and not C), or 'K' (default; KEEPORDER — mirror src contiguity, matching NumPy astype order='K').
engineTensorEnginetensor engine assigned to the result; defaults to
src's engine.
Returns
- NDArray
A freshly allocated, owning array of
dstTypeholding src's values.
Exceptions
- ArgumentNullException
srcis null.
CreateCopyState(UnmanagedStorage, UnmanagedStorage)
Create state for copy operation. IMPORTANT: Caller must call state.FreeDimArrays() when done!
public static NDIterState CreateCopyState(UnmanagedStorage src, UnmanagedStorage dst)
Parameters
srcUnmanagedStoragedstUnmanagedStorage
Returns
CreateReductionState(UnmanagedStorage)
Create state for reduction operation. IMPORTANT: Caller must call state.FreeDimArrays() when done!
public static NDIterState CreateReductionState(UnmanagedStorage src)
Parameters
srcUnmanagedStorage
Returns
IsContiguous(long*, long*, int)
public static bool IsContiguous(long* shape, long* strides, int ndim)
Parameters
Returns
ReduceBool<T, TKernel>(UnmanagedStorage)
public static bool ReduceBool<T, TKernel>(UnmanagedStorage src) where T : unmanaged where TKernel : struct, INDBooleanReductionKernel<T>
Parameters
srcUnmanagedStorage
Returns
Type Parameters
TTKernel
ReduceBool<T, TKernel>(NDArray)
public static bool ReduceBool<T, TKernel>(NDArray src) where T : unmanaged where TKernel : struct, INDBooleanReductionKernel<T>
Parameters
srcNDArray
Returns
Type Parameters
TTKernel
TryCopySameType(UnmanagedStorage, UnmanagedStorage)
public static bool TryCopySameType(UnmanagedStorage dst, UnmanagedStorage src)
Parameters
dstUnmanagedStoragesrcUnmanagedStorage
Returns
TryCopySameType(NDArray, NDArray)
public static bool TryCopySameType(NDArray dst, NDArray src)
Parameters
Returns
UpdateLayoutFlags(ref NDIterState, long*, long*, long*)
public static void UpdateLayoutFlags(ref NDIterState state, long* shape, long* srcStrides, long* dstStrides)
Parameters
stateNDIterStateshapelong*srcStrideslong*dstStrideslong*