Table of Contents

Class LegacyBuiltinDTypeMeta

Namespace
NumSharp
Assembly
NumSharp.dll

The DType class of a storage-backed NumSharp dtype — the 15 element types (plus the vestigial String), wrapped the way NumPy's dtypemeta_wrap_legacy_descriptor wraps its builtin descriptors into numpy.dtypes.*DType classes. Data-driven: the registry constructs one per NPTypeCode with its NumPy type number, kind, char, size, alignment and aliases; the behaviour slots are the builtin ones — the singleton is the default descriptor, and common_dtype(DTypeMeta) is NumPy's default_builtin_common_dtype over NumSharp's frozen promotion table (NumSharp.np._nptypemap_arr_arr), so every existing promote_types answer is reproduced bit-for-bit.

public sealed class LegacyBuiltinDTypeMeta : DTypeMeta
Inheritance
LegacyBuiltinDTypeMeta
Inherited Members

Remarks

Lane-sharing classes. NumPy keeps a class per C type, and several C types can have one width: Windows' int and long are both 32-bit (IntDType beside Int32DType), Linux's long and long long both 64-bit (LongLongDType beside Int64DType), and NumSharp's long double is a 64-bit double on every platform (LongDoubleDType beside Float64DType, CLongDoubleDType beside Complex128DType). Such a class stores its elements in the storage lane of its width (the kernels are the lane's) but does not OWN the lane: FromTypeCode(NPTypeCode) and FromScalarType(Type) keep returning the lane's own class, and an array keeps the lane-sharing descriptor only where it is carried explicitly (creation with that dtype, views, copies, casts).

NumPy calls two such classes EQUIVALENT (np.dtype('g') == np.dtype('d') on Windows, a cast between them is a no-op), and so does NumSharp: Equals(DType), BuiltinCastingImpl and the promotion table treat every two NumPy classes of one kind and size that way.

Methods

common_dtype(DTypeMeta)

NumPy's default_builtin_common_dtype: the NEP 50 Python-scalar rules first (a weak float adopts a float/complex class, a weak int adopts any numeric class, a weak complex lifts a real float to complex), then defer to the class with the larger type number, then the frozen promotion table.

public override DTypeMeta common_dtype(DTypeMeta other)

Parameters

other DTypeMeta

The other operand's class.

Returns

DTypeMeta

The common class, or null (NotImplemented) when the other class must answer.

default_descr()

NumPy's builtin default_descr: the singleton — a non-parametric class has exactly one canonical descriptor.

public override DType default_descr()

Returns

DType

singleton.

is_known_scalar_type(Type)

The slot is_known_scalar_type for a builtin class: the C# element type, and a C# array of it (np.array(int[]) is int32). NumPy's legacy slot (python_builtins_are_known_scalar_types) accepts Python's own scalars instead; C# has no such shared scalar set, so each class claims its element type.

public override bool is_known_scalar_type(Type type)

Parameters

type Type

The C# type of the scalar.

Returns

bool

True when type belongs to this class.