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 two dtypes are actually references to the same object or if casting type is forced unsafe then always OK.
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.
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.
5 chars needed for cast to 'True' or 'False'
Element size should never be greater than 8 or less than 0 for integer type, but just in case...
Add character for sign symbol
Convert data array to list of objects since GetArrayParamsFromObject won't iterate over array.
We should never get here, but just in case someone adds a new flex dtype...
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().

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.
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(), and PyArray_CanCoerceScalar().

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