Class BuiltinCastingImpl
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The cast between two storage-backed builtin classes (NumPy's add_numeric_cast, convert_datatype.c).
Its Casting is computed the way NumPy computes spec.casting: the same class →
equiv (a copy or byte swap); safe when the frozen promotion table says
promote(from, to) == to (NumPy's _npy_can_cast_safely_table); otherwise same_kind when the
source kind orders at or below the destination kind (b < u < i < f < c), else unsafe.
These are exactly the rules np.can_cast(NPTypeCode, NPTypeCode) always applied, so the builtin answers
are unchanged; the class pair now owns them.
public sealed class BuiltinCastingImpl : CastingImpl
- Inheritance
-
BuiltinCastingImpl
- Inherited Members
Remarks
One deliberate departure: NumPy also calls two DIFFERENT classes with the same kind and size equivalent
(intc vs long on Windows), which would make NumSharp's Char and UInt16 an
equiv pair. They are distinct storage types with distinct kernels, so only the identical class is
equiv here; Char ↔ UInt16 is safe one way and same_kind the other, as before.
The loop is not provided by this object — the engine drives its IL cast kernels directly (Stage A).
Properties
Casting
The minimal safety of this numeric cast — NumPy's add_numeric_cast value (equiv within a class,
safe when the promotion table maps (from, to) back onto to, same_kind along the
b < u < i < f < c kind order, else unsafe). Computed on FIRST READ, not at registration:
the promotion table is np._nptypemap_arr_arr, built by np's static constructor, and np's
field initializers (np.float64 is a DType) are what first construct
DTypeRegistry — so reading the table while the registry registers the 15×15 impls would observe
it before it exists. The value is a constant, so the lazy evaluation is unobservable (a benign race at worst
computes it twice).
public override NPY_CASTING Casting { get; }
Property Value
Methods
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 override NPY_CASTING ResolveDescriptors(DType[] givenDescrs, DType[] loopDescrs, out long viewOffset)
Parameters
Returns
Exceptions
- TypeError
The descriptors cannot be resolved (NumPy returns -1 with an error set).