Table of Contents

Class NDIter

Namespace
NumSharp.Backends.Iteration
Assembly
NumSharp.dll

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

shape long*
strides long*
coords long*
ndim int
offset long

CoalesceAxes(ref NDIterState, long*, long*, long*)

public static void CoalesceAxes(ref NDIterState state, long* shape, long* srcStrides, long* dstStrides)

Parameters

state NDIterState
shape long*
srcStrides long*
dstStrides long*

Copy(UnmanagedStorage, UnmanagedStorage)

Copy src into dst with full support for broadcast, stride, and cross-dtype conversion.

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

dst UnmanagedStorage

The destination array (written in place).

src UnmanagedStorage

The source array; broadcast to dst's shape.

Remarks

NDAnchoredAttribute: the copy runs storage to storage, and a storage does not hold its buffer (the NDArray's ARC reference does), so once src.Storage is read nothing in this frame keeps a caller's temporary source alive — the lifetime oracle's gap LT09 (every cross-dtype TensorEngine.Cast and np.copyto came through here). The weaver roots both arrays until the copy returns.

Exceptions

ArgumentNullException

dst or src is null.

ValueError

If dst is not writeable (e.g., broadcast view) — NumPy's "… is read-only".

Copy(NDArray, NDArray)

Copy src into dst with full support for broadcast, stride, and cross-dtype conversion.

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

dst NDArray

The destination array (written in place).

src NDArray

The source array; broadcast to dst's shape.

Remarks

NDAnchoredAttribute: the copy runs storage to storage, and a storage does not hold its buffer (the NDArray's ARC reference does), so once src.Storage is read nothing in this frame keeps a caller's temporary source alive — the lifetime oracle's gap LT09 (every cross-dtype TensorEngine.Cast and np.copyto came through here). The weaver roots both arrays until the copy returns.

Exceptions

ArgumentNullException

dst or src is null.

ValueError

If dst is not writeable (e.g., broadcast view) — NumPy's "… is read-only".

CopyAs(DType, 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(DType dstType, NDArray src, char order = 'K', TensorEngine engine = null)

Parameters

dstType DType

dtype DESCRIPTOR of the result (equal to src's for a plain copy/retype). A descriptor, not a type code, because a fixed-width string's width lives on it (<U5); an NPTypeCode converts implicitly for the numeric lanes.

src NDArray

source array of any layout (contiguous, sliced, strided, broadcast, transposed, scalar, empty).

order char

'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').

engine TensorEngine

tensor engine assigned to the result; defaults to src's engine.

Returns

NDArray

A freshly allocated, owning array of dstType holding src's values.

Remarks

NDAnchoredAttribute: the fill reads src's storage, so the weaver roots it until the copy returns — a caller that casts a temporary (engine.Cast(np.arange(n), ...)) cannot lose it mid-copy (see Copy(NDArray, NDArray)).

Exceptions

ArgumentNullException

src is 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

src UnmanagedStorage
dst UnmanagedStorage

Returns

NDIterState

CreateReductionState(UnmanagedStorage)

Create state for reduction operation. IMPORTANT: Caller must call state.FreeDimArrays() when done!

public static NDIterState CreateReductionState(UnmanagedStorage src)

Parameters

src UnmanagedStorage

Returns

NDIterState

IsContiguous(long*, long*, int)

public static bool IsContiguous(long* shape, long* strides, int ndim)

Parameters

shape long*
strides long*
ndim int

Returns

bool

ReduceBool<T, TKernel>(UnmanagedStorage)

public static bool ReduceBool<T, TKernel>(UnmanagedStorage src) where T : unmanaged where TKernel : struct, INDBooleanReductionKernel<T>

Parameters

src UnmanagedStorage

Returns

bool

Type Parameters

T
TKernel

ReduceBool<T, TKernel>(NDArray)

public static bool ReduceBool<T, TKernel>(NDArray src) where T : unmanaged where TKernel : struct, INDBooleanReductionKernel<T>

Parameters

src NDArray

Returns

bool

Type Parameters

T
TKernel

TryCopySameType(UnmanagedStorage, UnmanagedStorage)

public static bool TryCopySameType(UnmanagedStorage dst, UnmanagedStorage src)

Parameters

dst UnmanagedStorage
src UnmanagedStorage

Returns

bool

TryCopySameType(NDArray, NDArray)

public static bool TryCopySameType(NDArray dst, NDArray src)

Parameters

dst NDArray
src NDArray

Returns

bool

UpdateLayoutFlags(ref NDIterState, long*, long*, long*)

public static void UpdateLayoutFlags(ref NDIterState state, long* shape, long* srcStrides, long* dstStrides)

Parameters

state NDIterState
shape long*
srcStrides long*
dstStrides long*