Table of Contents

Class LegacyWrappingCastingImpl

Namespace
NumSharp
Assembly
NumSharp.dll

A cast whose safety is fixed per class pair with the plain descriptor resolution — NumPy's PyArray_AddLegacyWrapping_CastingImpl, used for the numeric ↔ datetime/timedelta casts (every cast to or from datetime64 is unsafe; an integer or bool casts safely to timedelta64, a 64-bit unsigned one only same_kind, a float or complex only unsafely) and for the casts OUT of a string class into a numeric class or timedelta64 (always unsafe: text parses into a number).

public sealed class LegacyWrappingCastingImpl : CastingImpl
Inheritance
LegacyWrappingCastingImpl
Inherited Members

Methods

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

The loop of the casts OUT of a fixed-width text class into a numeric storage class - NumPy's legacy STRING_to_@TYPE@ / UNICODE_to_@TYPE@ wrapped in NPY_LOWLEVEL_BUFFER_BLOCKSIZE blocks (ParseRun(byte*, long, bool, int, byte*, long, NPTypeCode, long, Span<byte>, TextReprStyle)): each text parsed by CPython's int() / float() / complex() (a bool target takes the text's truth value), a block of 128 committed only when every element of it parsed, the error quoting the element's NumPy scalar (np.str_('x')). The numeric ↔ datetime casts this class also registers have no storage yet: they keep the base, which raises.

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

Parameters

context ArrayMethodContext

The resolved descriptors: [0] the text (its class and width), [1] the number (its lane).

aligned bool

Unused: the loop reads and writes unaligned elements.

strides long[]

Unused: the loop takes the strides of each call.

flags NDArrayMethodFlags

Receives the method's flags.

Returns

NDInnerLoopFunc

The loop: [0] the text run, [1] the number run, byte strides.

Exceptions

NotSupportedException

A pair other than text into a numeric storage class (a datetime cast before Stage C).

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

NumPy's 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.

public override NPY_CASTING resolve_descriptors(DType[] givenDescrs, DType[] loopDescrs, out long viewOffset)

Parameters

givenDescrs DType[]

The operand descriptors, inputs first; an output entry may be null.

loopDescrs DType[]

Receives the descriptors the loop runs on, one per operand.

viewOffset long

The byte offset at which the operation is a plain VIEW (0 for a no-op cast between identical descriptors), or NoView.

Returns

NPY_CASTING

The cast safety of running the loop on loopDescrs.

Exceptions

TypeError

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