numpy  2.0.0
src/multiarray/convert_datatype.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT
PyArray_VectorUnaryFunc
PyArray_GetCastFunc (PyArray_Descr *descr, int type_num)
NPY_NO_EXPORT int PyArray_ObjectType (PyObject *op, int minimum_type)
NPY_NO_EXPORT PyArrayObject ** PyArray_ConvertToCommonType (PyObject *op, int *retn)
NPY_NO_EXPORT int PyArray_ValidType (int type)
NPY_NO_EXPORT npy_bool can_cast_scalar_to (PyArray_Descr *scal_type, char *scal_data, PyArray_Descr *to, NPY_CASTING casting)
NPY_NO_EXPORT void PyArray_AdaptFlexibleDType (PyObject *data_obj, PyArray_Descr *data_dtype, PyArray_Descr **flex_dtype)

Function Documentation

NPY_NO_EXPORT npy_bool can_cast_scalar_to ( PyArray_Descr scal_type,
char *  scal_data,
PyArray_Descr to,
NPY_CASTING  casting 
)
Like PyArray_CanCastArrayTo
An aligned memory buffer large enough to hold any type
If the scalar isn't a number, or the rule is stricter than NPY_SAFE_CASTING, use the straight type-based rules
If we've got a small unsigned scalar, and the 'to' type is not unsigned, then make it signed to allow the value to be cast more appropriately.

References _npy_type_promotion_table, PyArray_DescrFromType(), and type_num_unsigned_to_signed().

NPY_NO_EXPORT void PyArray_AdaptFlexibleDType ( PyObject *  data_obj,
PyArray_Descr data_dtype,
PyArray_Descr **  flex_dtype 
)
This function calls Py_DECREF on flex_dtype, and replaces it with a new dtype that has been adapted based on the values in data_dtype and data_obj. If the flex_dtype is not flexible, it leaves it as is.
The current flexible dtypes include NPY_STRING, NPY_UNICODE, NPY_VOID, and NPY_DATETIME with generic units.
This function calls Py_DECREF on flex_dtype, and replaces it with a new dtype that has been adapted based on the values in data_dtype and data_obj. If the flex_dtype is not flexible, it leaves it as is.
Usually, if data_obj is not an array, dtype should be the result given by the PyArray_GetArrayParamsFromObject function.
The data_obj may be NULL if just a dtype is is known for the source.
If *flex_dtype is NULL, returns immediately, without setting an exception. This basically assumes an error was already set previously.

System Message: WARNING/2 (<string>, line 10); backlink Inline emphasis start-string without end-string.
The current flexible dtypes include NPY_STRING, NPY_UNICODE, NPY_VOID, and NPY_DATETIME with generic units.
Flexible types with expandable size
First replace the flex dtype
Get a string-size estimate of the input. These are generallly the size needed, rounded up to a multiple of eight.
Flexible type with generic time unit that adapts
Detect the unit from the input's data

Referenced by get_nbo_datetime_to_string_transfer_function(), npyiter_check_per_op_flags(), and PyArray_CastToType().

NPY_NO_EXPORT PyArrayObject** PyArray_ConvertToCommonType ( PyObject *  op,
int *  retn 
)
Raises error when len(op) == 0
all scalars
we need to upconvert to type that handles both intype and stype also don't forcecast the scalars.
Make sure all arrays are actual array objects.
forcecast scalars
Get a cast function to cast from the input descriptor to the
output type_number (must be a registered data-type). Returns NULL if un-successful.

References PyArray_ArrFuncs::castdict, _PyArray_Descr::f, NpyCapsule_AsVoidPtr(), and NpyCapsule_Check().

NPY_NO_EXPORT int PyArray_ObjectType ( PyObject *  op,
int  minimum_type 
)
End deprecated
Return the typecode of the array a Python object would be converted to <blockquote> Returns the type number the result should have, or NPY_NOTYPE on error.</blockquote>

Referenced by _pyarray_correlate().

NPY_NO_EXPORT int PyArray_ValidType ( int  type)
Is the typenum valid?