Class DTypeRegistry
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The table of live DTypeMeta classes and their casting implementations — NumPy's
_builtin_descrs / typenum_to_dtypemeta / _PyArray_MapPyTypeToDType rolled into one static
registry. Lookups by NPTypeCode, C# scalar Type, NumPy type number and class name
(aliases included); Register(DTypeMeta) admits a new class (a Stage C/D dtype, a user dtype) without
touching the kernel switches — the class registers its code and its casts, and the promotion/casting
engines pick it up.
public static class DTypeRegistry
- Inheritance
-
DTypeRegistry
- Inherited Members
Remarks
Static initialisation builds the 15 numeric storage classes, the two fixed-width string classes
(Bytes and Str, sharing the String lane), the two datetime
classes, the three NEP 50 scalar classes, their singleton descriptors, and the casting implementations NumPy
registers in PyArray_InitializeNumericCasts / PyArray_InitializeDatetimeCasts /
PyArray_InitializeStringCasts. It touches no np static state, so it cannot cycle with the
np static constructor; the promotion TABLE (NumSharp.np._nptypemap_arr_arr) is consulted lazily at
call time.
Threading. No lookup takes a lock. The three keyed tables are ConcurrentDictionary<TKey, TValue>s, the code table is read with Read<T>(ref readonly T), and All copies an array that each registration replaces instead of changing. Only Register(DTypeMeta) takes NumSharp.DTypeRegistry._lock: it checks the type number, the name, every alias and the storage code before it writes any table, and two registrations must not interleave between their checks and their writes. A lookup that runs during a registration sees each table either before or after its write, so a new class can be found by its type number a moment before it can be found by its name.
Properties
All
Every registered class (builtins, datetime pair, the abstract scalar classes, user classes), in registration order.
public static IReadOnlyList<DTypeMeta> All { get; }
Property Value
- IReadOnlyList<DTypeMeta>
A new array on every read, taken without a lock: the caller may keep or change it, and a registration that runs meanwhile is either wholly in it or not in it.
Bool
public static LegacyBuiltinDTypeMeta Bool { get; }
Property Value
Bytes
np.dtypes.BytesDType — fixed-width bytes (S, type number 18, one byte per character). Shares the
String storage lane with Str but owns neither that code nor a C# type,
so it is reached by name only ("S5", bytes_).
public static StringDTypeMeta Bytes { get; }
Property Value
CInt
The class of NumPy's C int (np.intc, char 'i', type number 5): on LLP64 (Windows) its own
lane-sharing class IntDType (scalar class numpy.intc) beside Int32, which is the C
long there; on LP64 the Int32 class itself (int32 IS the C int).
public static LegacyBuiltinDTypeMeta CInt { get; }
Property Value
CLongDouble
np.dtypes.CLongDoubleDType — NumPy's complex long double class (type number 16, char 'G',
scalar class numpy.clongdouble), sharing the Complex lane (two 8-byte parts);
equivalent to Complex128.
public static LegacyBuiltinDTypeMeta CLongDouble { get; }
Property Value
CLongLong
The class of NumPy's C long long (np.longlong, char 'q', type number 9): on LP64 (Linux,
macOS) its own lane-sharing class LongLongDType (scalar class numpy.longlong) beside
Int64, which is the C long there; on LLP64 the Int64 class itself.
public static LegacyBuiltinDTypeMeta CLongLong { get; }
Property Value
CUInt
The class of NumPy's C unsigned int (np.uintc, char 'I', type number 6): UIntDType on LLP64, UInt32 on LP64 (see CInt).
public static LegacyBuiltinDTypeMeta CUInt { get; }
Property Value
CULongLong
The class of NumPy's C unsigned long long (np.ulonglong, char 'Q', type number 10): ULongLongDType on LP64, UInt64 on LLP64 (see CLongLong).
public static LegacyBuiltinDTypeMeta CULongLong { get; }
Property Value
Char
NumSharp-only: char (type number 257, the user-defined range; promotes as uint16). Its
dtype.char is 'u', a letter of its own (see Decimal): PEP 3118's code for a 2-byte
UCS-2 character, which a char array's memoryview already reports as its format, and Python's array-module code
for a wide character (array('u'), 2 bytes on Windows). NumPy reads 'u' only as the unsigned
KIND ('u2'), never alone (np.dtype("u") is "not understood"); NumPy's 'c' is the one-byte
string S1.
public static LegacyBuiltinDTypeMeta Char { get; }
Property Value
Complex128
public static LegacyBuiltinDTypeMeta Complex128 { get; }
Property Value
DateTime64
np.dtypes.DateTime64DType.
public static DatetimeDTypeMeta DateTime64 { get; }
Property Value
Decimal
NumSharp-only: decimal (type number 256, the user-defined range). Its dtype.char is
'A', a letter of its own as NumPy's user dtypes have one (rational's is 'r'): no NumPy
type, kind letter or PEP 3118 format uses it, so NumPy's parser does not read it back
(np.dtype("A") is "not understood") and ported code that classifies by character
(np.typecodes, np.mintypecode) never takes decimal for another dtype.
public static LegacyBuiltinDTypeMeta Decimal { get; }
Property Value
Double
public static LegacyBuiltinDTypeMeta Double { get; }
Property Value
Half
public static LegacyBuiltinDTypeMeta Half { get; }
Property Value
Int16
public static LegacyBuiltinDTypeMeta Int16 { get; }
Property Value
Int32
public static LegacyBuiltinDTypeMeta Int32 { get; }
Property Value
Int64
public static LegacyBuiltinDTypeMeta Int64 { get; }
Property Value
Int8
public static LegacyBuiltinDTypeMeta Int8 { get; }
Property Value
LongDouble
np.dtypes.LongDoubleDType — NumPy's C long double class (type number 13, char 'g',
scalar class numpy.longdouble), a lane-sharing class over the Double lane: 8
bytes on every platform, as on NumPy's win-amd64 build (NumSharp has no extended precision; Linux NumPy's is an
80-bit type in 16 bytes). Equivalent to Double (np.dtype('g') == np.dtype('d')), but its
own class: np.issubdtype(np.float64, np.longdouble) is False.
public static LegacyBuiltinDTypeMeta LongDouble { get; }
Property Value
PyComplex
NEP 50's _PyComplexDType — the class of a weak C# Complex literal.
public static PyScalarDTypeMeta PyComplex { get; }
Property Value
PyFloat
NEP 50's _PyFloatDType — the class of a weak C# floating literal.
public static PyScalarDTypeMeta PyFloat { get; }
Property Value
PyLong
NEP 50's _PyLongDType — the class of a weak C# integer literal.
public static PyScalarDTypeMeta PyLong { get; }
Property Value
Single
public static LegacyBuiltinDTypeMeta Single { get; }
Property Value
Str
np.dtypes.StrDType — fixed-width Unicode (U, type number 19, one UCS-4 code point per character).
The canonical class of the String storage lane and of string.
public static StringDTypeMeta Str { get; }
Property Value
TimeDelta64
np.dtypes.TimeDelta64DType.
public static DatetimeDTypeMeta TimeDelta64 { get; }
Property Value
UInt16
public static LegacyBuiltinDTypeMeta UInt16 { get; }
Property Value
UInt32
public static LegacyBuiltinDTypeMeta UInt32 { get; }
Property Value
UInt64
public static LegacyBuiltinDTypeMeta UInt64 { get; }
Property Value
UInt8
public static LegacyBuiltinDTypeMeta UInt8 { get; }
Property Value
VString
np.dtypes.StringDType — the NEP 55 variable-width string class (kind 'T', type number 2056). It
shares the String lane with Str / Bytes but owns neither the
code nor a C# type, and it has no singleton: descriptors come from StringDType(bool),
StringDType(object, bool) and np.dtype("T"), a fresh one each time.
public static VStringDTypeMeta VString { get; }
Property Value
Methods
AddCastingImpl(CastingImpl)
Registers a casting implementation on its source class — NumPy's PyArray_AddCastingImplementation.
public static void AddCastingImpl(CastingImpl impl)
Parameters
implCastingImpl
FromName(string)
The class named name ("Int32DType") or one of its aliases ("IntDType"), or null.
public static DTypeMeta FromName(string name)
Parameters
namestring
Returns
FromScalarType(Type)
The class of a C# scalar Type (NEP 41's np.dtype[np.float64] / NumPy's
PyArray_DiscoverDTypeFromScalarType): typeof(double) → Double. Array types map to
their element type (np.array(int[]) is int32). Null when the type is not a NumSharp scalar.
public static DTypeMeta FromScalarType(Type type)
Parameters
typeType
Returns
FromTypeCode(NPTypeCode)
The class whose storage discriminator is typeCode — behind every
From(NPTypeCode). Takes no lock.
public static DTypeMeta FromTypeCode(NPTypeCode typeCode)
Parameters
typeCodeNPTypeCodeThe storage code.
Returns
FromTypeNum(int)
The class with NumPy type number typeNum, or null.
public static DTypeMeta FromTypeNum(int typeNum)
Parameters
typeNumint
Returns
Register(DTypeMeta)
Registers a new DType class (a user dtype). Its type number, name and aliases must be unused; a class with storage must carry an unused NPTypeCode. Casting implementations are added separately with AddCastingImpl(CastingImpl).
public static void Register(DTypeMeta meta)
Parameters
metaDTypeMetaThe class to register.
Remarks
The only member that takes a lock: NumSharp.DTypeRegistry._lock keeps two registrations from interleaving between their checks and their writes. Lookups never wait for it.
Exceptions
- ArgumentNullException
metais null.- InvalidOperationException
The type number, the name or an alias is already registered, or the storage code is outside the code table or already registered. Nothing is registered then, so the class can be registered once its conflict is fixed.