numpy  2.0.0
src/multiarray/scalartypes.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT void initialize_casting_tables (void)
NPY_NO_EXPORT void initialize_numeric_types (void)
NPY_NO_EXPORT void format_longdouble (char *buf, size_t buflen, npy_longdouble val, unsigned int prec)
NPY_NO_EXPORT void gentype_struct_free (void *ptr, void *arg)
NPY_NO_EXPORT int is_anyscalar_exact (PyObject *obj)
NPY_NO_EXPORT int _typenum_fromtypeobj (PyObject *type, int user)
NPY_NO_EXPORT void * scalar_value (PyObject *scalar, PyArray_Descr *descr)

Variables

NPY_NO_EXPORT unsigned char _npy_can_cast_safely_table [NPY_NTYPES][NPY_NTYPES]
NPY_NO_EXPORT signed char _npy_scalar_kinds_table [NPY_NTYPES]
NPY_NO_EXPORT signed char _npy_type_promotion_table [NPY_NTYPES][NPY_NTYPES]
NPY_NO_EXPORT signed char _npy_smallest_type_of_kind_table [NPY_NSCALARKINDS]
NPY_NO_EXPORT signed char _npy_next_larger_type_table [NPY_NTYPES]

Function Documentation

NPY_NO_EXPORT int _typenum_fromtypeobj ( PyObject *  type,
int  user 
)
Search any registered types
NPY_NO_EXPORT void format_longdouble ( char *  buf,
size_t  buflen,
npy_longdouble  val,
unsigned int  prec 
)
NPY_NO_EXPORT void gentype_struct_free ( void *  ptr,
void *  arg 
)
Default for built-in types is object scalar
Default for next largest type is -1, signalling no bigger
Compile-time loop of scalar kinds
begin repeat
#NAME = BOOL,
BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#
#BIGGERTYPE = -1,
NPY_SHORT, NPY_USHORT, NPY_INT, NPY_UINT, NPY_LONG, NPY_ULONG, NPY_LONGLONG, NPY_ULONGLONG, -1, -1, NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE, -1, NPY_CDOUBLE, NPY_CLONGDOUBLE, -1#
#SCKIND = BOOL,
(INTNEG, INTPOS)*5, FLOAT*4, COMPLEX*3#
end repeat*
Identity
Bool -> <Anything> except datetime (since
it conceptually has no zero)
<Anything> -> Object
<Anything> -> Void
Compile-time loop of casting rules
begin repeat
#FROM_NAME = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
LONG, ULONG, LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#
#FROM_BASENAME = BYTE, BYTE, SHORT, SHORT, INT, INT,
LONG, LONG, LONGLONG, LONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, FLOAT, DOUBLE, LONGDOUBLE#
#from_isint = 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0#
#from_isuint = 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 0, 0, 0, 0, 0, 0#
#from_isfloat = 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0, 0#
#from_iscomplex = 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1#
Allow casts from any integer to the TIMEDELTA type
begin repeat1
#TO_NAME = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
LONG, ULONG, LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#
#TO_BASENAME = BYTE, BYTE, SHORT, SHORT, INT, INT,
LONG, LONG, LONGLONG, LONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, FLOAT, DOUBLE, LONGDOUBLE#
#to_isint = 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0#
#to_isuint = 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 0, 0, 0, 0, 0, 0#
#to_isfloat = 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0, 0#
#to_iscomplex = 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1#
NOTE: _FROM_BSIZE and _TO_BSIZE are the sizes of the "base type"
which is the same as the size of the type except for complex, where it is the size of the real type.
end repeat1*
end repeat*
Now that the _can_cast_safely table is finished, we can use it to build the _type_promotion table
Don't let number promote to string/unicode/void/datetime/timedelta
Promoting these types requires examining their contents
Except they can convert to OBJECT
Don't let number promote to string/unicode/void
If there's no kind (void/string/etc)
Start with the type of larger kind
Try the next larger type of this kind
If there is no larger, try a larger kind
Use -1 to signal no promoted type found

Referenced by test_interrupt().

need to add dummy versions with filled-in nb_index in-order for PyType_Ready to fill in .__index__() method also fill array_type_as_number struct with reasonable defaults
begin repeat
name = byte, short, int, long, longlong, ubyte, ushort,
uint, ulong, ulonglong#
#NAME = Byte, Short, Int, Long, LongLong, UByte, UShort,
UInt, ULong, ULongLong#
end repeat*
begin repeat
name = half, float, double, longdouble,
cfloat, cdouble, clongdouble#
#NAME = Half, Float, Double, LongDouble,
CFloat, CDouble, CLongDouble#
end repeat*
begin repeat
#NAME= Number, Integer, SignedInteger, UnsignedInteger, Inexact,
Floating, ComplexFloating, Flexible, Character#
end repeat*
begin repeat
name = bool, byte, short, int, long, longlong, ubyte, ushort, uint,
ulong, ulonglong, half, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object, datetime, timedelta#
#NAME = Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt,
ULong, ULongLong, Half, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object, Datetime, Timedelta#
end repeat*
begin repeat
name = bool, byte, short, ubyte, ushort, uint, ulong, ulonglong,
half, float, longdouble, cfloat, clongdouble, void, object, datetime, timedelta#
#NAME = Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong,
Half, Float, LongDouble, CFloat, CLongDouble, Void, Object, Datetime, Timedelta#
end repeat*
begin repeat
name = cfloat, clongdouble# #NAME = CFloat, CLongDouble#
end repeat*
begin repeat
name = repr, str#
end repeat*
These need to be coded specially because getitem does not return a normal Python type
begin repeat
name = int, float, repr, str# kind = tp_as_number->nb*2, tp*2#
end repeat*
begin repeat
name = long, hex, oct# kind = tp_as_number->nb*3#
end repeat*

Referenced by test_interrupt().

NPY_NO_EXPORT int is_anyscalar_exact ( PyObject *  obj)
NPY_NO_EXPORT void* scalar_value ( PyObject *  scalar,
PyArray_Descr descr 
)
Must be a user-defined type --- check to see which scalar it inherits from.
Unsigned Integer
Inexact
ComplexFloating
Use the alignment flag to figure out where the data begins after a PyObject_HEAD
now round-up to the nearest alignment value

References _CHK, _IFCASE, _OBJ, _PyArray_Descr::alignment, Bool, CASE, NPY_STRING, NPY_UNICODE, NPY_VOID, PyArray_DescrFromScalar(), and _PyArray_Descr::type_num.


Variable Documentation

Internal look-up tables
This table describes safe casting for small type numbers, and is used by PyArray_CanCastSafely.
This table gives the type of the same kind, but next in the sequence of sizes.
end repeat*
This table maps the built-in type numbers to their scalar type numbers. Note that signed integers are mapped to INTNEG_SCALAR, which is different than what PyArray_ScalarKind returns.

Referenced by PyArray_Concatenate().

This table maps a scalar kind (excluding NPY_NOSCALAR) to the smallest type number of that kind.

Referenced by PyArray_CanCastScalar().

This table gives the smallest-size and smallest-kind type to which the input types may be safely cast, according to _npy_can_cast_safely.