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, longdouble val, unsigned int prec)
NPY_NO_EXPORT void gentype_struct_free (void *ptr, void *arg)
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,
longdouble  val,
unsigned int  prec 
)
NPY_NO_EXPORT void gentype_struct_free ( void *  ptr,
void *  arg 
)
NPY_NO_EXPORT void initialize_casting_tables ( void  )
end repeat*

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>
DateTime sits out for these...
<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#
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
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
Special case date-time

Referenced by _vec_string().

NPY_NO_EXPORT void initialize_numeric_types ( void  )

begin repeat
#NAME= Number, Integer, SignedInteger, UnsignedInteger, Inexact,
Floating, ComplexFloating, Flexible, Character, TimeInteger#
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 _vec_string().

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.

Referenced by gentype_interface_get().


Variable Documentation

NPY_NO_EXPORT unsigned char _npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES]
Internal look-up tables

Referenced by PyArray_CastAnyTo().

NPY_NO_EXPORT signed char _npy_next_larger_type_table[NPY_NTYPES]
NPY_NO_EXPORT signed char _npy_scalar_kinds_table[NPY_NTYPES]

Referenced by _signbit_set().

NPY_NO_EXPORT signed char _npy_smallest_type_of_kind_table[NPY_NSCALARKINDS]
NPY_NO_EXPORT signed char _npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES]