Table of Contents

Class ArrayMethod

Namespace
NumSharp
Assembly
NumSharp.dll

NEP 43's ArrayMethod — ONE object per (input DTypes → output DTypes) implementation of an operation: it resolves the loop descriptors for the given operand descriptors (ResolveDescriptors(DType[], DType[], out long)) and hands out the strided inner loop that runs them (GetStridedLoop(ArrayMethodContext, bool, long[], out NDArrayMethodFlags)). Casts are the first family (CastingImpl); ufunc loops for a new dtype register the same way (Stage C) instead of adding a case NPTypeCode.X: to the IL generators.

public abstract class ArrayMethod
Inheritance
ArrayMethod
Derived
Inherited Members

Remarks

The loop contract is NDInnerLoopFunc — NumSharp's existing analog of NumPy's PyUFuncGenericFunction / PyArrayMethod_StridedLoop — so NDIter drives a registered loop without a new driver. Casting is the method's MINIMAL cast safety (NumPy's PyArrayMethodObject.casting): PyArray_CheckCastSafety short-circuits on it and only calls ResolveDescriptors(DType[], DType[], out long) when the requested rule is stricter.

Constructors

ArrayMethod(string, int, int, NPY_CASTING, NDArrayMethodFlags, IReadOnlyList<DTypeMeta>)

protected ArrayMethod(string name, int nin, int nout, NPY_CASTING casting, NDArrayMethodFlags flags, IReadOnlyList<DTypeMeta> dtypes)

Parameters

name string
nin int
nout int
casting NPY_CASTING
flags NDArrayMethodFlags
dtypes IReadOnlyList<DTypeMeta>

Fields

NoView

The view_offset value meaning "this cast is not a view" (NumPy's NPY_MIN_INTP).

public const long NoView = -9223372036854775808

Field Value

long

Properties

Casting

The minimal cast safety this method guarantees for ANY descriptors of its DTypes (-1 in NumPy means "must resolve"; here NPY_UNSAFE_CASTING plays that role). A per-method constant; virtual so an implementation whose value is derived from a table that may not be built yet when the method is REGISTERED (the builtin numeric casts read np's frozen promotion table, and np's own type initializer can be what constructs DTypeRegistry) can compute it on first read instead.

public virtual NPY_CASTING Casting { get; }

Property Value

NPY_CASTING

DTypes

The DType classes of the operands, inputs first then outputs.

public IReadOnlyList<DTypeMeta> DTypes { get; }

Property Value

IReadOnlyList<DTypeMeta>

Flags

The method flags (unaligned support, floating-point-error behaviour, …).

public NDArrayMethodFlags Flags { get; }

Property Value

NDArrayMethodFlags

NIn

Number of input operands.

public int NIn { get; }

Property Value

int

NOut

Number of output operands.

public int NOut { get; }

Property Value

int

Name

The method name ("numeric_cast", "datetime_casts", …) — NumPy's name.

public string Name { get; }

Property Value

string

Methods

GetStridedLoop(ArrayMethodContext, bool, long[], out NDArrayMethodFlags)

get_strided_loop: the inner loop for the resolved context and the given fixed strides. Stage A registers no loops here — the engine still drives its own IL cast kernels directly — so the base implementation raises NotSupportedException naming the missing piece; Stage C overrides it for the datetime loops.

public virtual NDInnerLoopFunc GetStridedLoop(ArrayMethodContext context, bool aligned, long[] strides, out NDArrayMethodFlags flags)

Parameters

context ArrayMethodContext
aligned bool
strides long[]
flags NDArrayMethodFlags

Returns

NDInnerLoopFunc

ResolveDescriptors(DType[], DType[], out long)

resolve_descriptors: given the operand descriptors (an output entry may be null — "please pick"), fills loopDescrs with the descriptors the loop will actually run on and returns the cast safety of doing so. viewOffset is the byte offset at which the operation is a plain VIEW (0 for a no-op cast between identical descriptors), or NoView.

public abstract NPY_CASTING ResolveDescriptors(DType[] givenDescrs, DType[] loopDescrs, out long viewOffset)

Parameters

givenDescrs DType[]
loopDescrs DType[]
viewOffset long

Returns

NPY_CASTING

Exceptions

TypeError

The descriptors cannot be resolved (NumPy returns -1 with an error set).

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.