Table of Contents

Class PyScalarDTypeMeta

Namespace
NumSharp
Assembly
NumSharp.dll

NumPy's abstract DType classes for Python scalars — numpy.dtypes._PyLongDType, _PyFloatDType, _PyComplexDType (abstractdtypes.c). They are how NEP 50 "weak" promotion works: a literal contributes only its abstract CLASS to result_type (no descriptor, so no value or width), and the class's CommonDType(DTypeMeta) lets the other operand's dtype win within its kind (int8 + 300 → int8, float32 + 1e300 → float32) while still lifting across kinds (int8 + 1.5 → float64). A literal that survives alone falls back to the class default (int64 / float64 / complex128).

public sealed class PyScalarDTypeMeta : DTypeMeta
Inheritance
PyScalarDTypeMeta
Inherited Members

Remarks

C# has no Python-literal/NumPy-scalar split, so the mapping is by TYPE (the house NEP 50 rule): the integer primitives, float/double and Complex are weak; bool, char, Half, decimal and every NDArray (0-d included) are strong.

Properties

PyKind

Which literal category this class stands for.

public PyScalarKind PyKind { get; }

Property Value

PyScalarKind

Methods

CommonDType(DTypeMeta)

Ports of int_common_dtype / float_common_dtype / complex_common_dtype. The builtin classes handle most pairs themselves (their common_dtype is asked FIRST and answers for a literal of their own or a lower kind); these implement the remaining directions: a weak int with bool is the default integer, a weak float or complex with an integer or bool class is float64 / complex128, and two abstract classes resolve to the higher category. The NumSharp-only storage classes (Decimal, Char) are treated as the numeric builtins they masquerade as — Char is an unsigned integer here, so result_type(char_array, 1.5) is float64 exactly like uint16 — rather than through NumPy's opaque-user-dtype fallback; a genuinely foreign legacy class still takes that fallback (promote with the smallest concrete type of the literal's category and let it decide).

public override DTypeMeta CommonDType(DTypeMeta other)

Parameters

other DTypeMeta

Returns

DTypeMeta

DefaultDescr()

The default descriptor a lone literal resolves to: int64 (NumPy's intp), float64, complex128.

public override DType DefaultDescr()

Returns

DType

IsKnownScalarType(Type)

Weak literals map onto the C# primitives of their category.

public override bool IsKnownScalarType(Type type)

Parameters

type Type

Returns

bool