numpy  2.0.0
src/multiarray/conversion_utils.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT int PyArray_IntpConverter (PyObject *obj, PyArray_Dims *seq)
NPY_NO_EXPORT int PyArray_BufferConverter (PyObject *obj, PyArray_Chunk *buf)
NPY_NO_EXPORT int PyArray_BoolConverter (PyObject *object, npy_bool *val)
NPY_NO_EXPORT int PyArray_ByteorderConverter (PyObject *obj, char *endian)
NPY_NO_EXPORT int PyArray_SortkindConverter (PyObject *obj, NPY_SORTKIND *sortkind)
NPY_NO_EXPORT int PyArray_SearchsideConverter (PyObject *obj, void *addr)
NPY_NO_EXPORT int PyArray_PyIntAsInt (PyObject *o)
NPY_NO_EXPORT npy_intp PyArray_PyIntAsIntp (PyObject *o)
NPY_NO_EXPORT int PyArray_IntpFromSequence (PyObject *seq, npy_intp *vals, int maxvals)
NPY_NO_EXPORT int PyArray_TypestrConvert (int itemsize, int gentype)
NPY_NO_EXPORT PyObject * PyArray_IntTupleFromIntp (int len, npy_intp *vals)
NPY_NO_EXPORT int PyArray_ConvertMultiAxis (PyObject *axis_in, int ndim, npy_bool *out_axis_flags)

Variables

NPY_NO_EXPORT int evil_global_disable_warn_O4O8_flag

Function Documentation

NPY_NO_EXPORT int PyArray_BoolConverter ( PyObject *  object,
npy_bool val 
)
Convert an object to true / false

Referenced by array_can_cast_safely().

NPY_NO_EXPORT int PyArray_BufferConverter ( PyObject *  obj,
PyArray_Chunk buf 
)
Get buffer chunk from object <blockquote>
this function takes a Python object which exposes the (single-segment) buffer interface and returns a pointer to the data segment
You should increment the reference count by one of buf->base if you will hang on to a reference
You only get a borrowed reference to the object. Do not free the memory... </blockquote>
Point to the base of the buffer object if present
NPY_NO_EXPORT int PyArray_ByteorderConverter ( PyObject *  obj,
char *  endian 
)
Convert object to endian

References NPY_SWAP.

NPY_NO_EXPORT int PyArray_ConvertMultiAxis ( PyObject *  axis_in,
int  ndim,
npy_bool out_axis_flags 
)
Converts an axis parameter into an ndim-length C-array of boolean flags, True for each axis specified.
If obj is None, everything is set to True. If obj is a tuple, each axis within the tuple is set to True. If obj is an integer, just that axis is set to True.
Converts an axis parameter into an ndim-length C-array of boolean flags, True for each axis specified.
If obj is None or NULL, everything is set to True. If obj is a tuple, each axis within the tuple is set to True. If obj is an integer, just that axis is set to True.
None means all of the axes
A tuple of which axes
Try to interpret axis as an integer
TODO: PyNumber_Index would be good to use here
Special case letting axis={-1,0} slip through for scalars, for backwards compatibility reasons.

References NPY_FAIL.

NPY_NO_EXPORT int PyArray_IntpConverter ( PyObject *  obj,
PyArray_Dims seq 
)
Get intp chunk from sequence <blockquote>
This function takes a Python sequence object and allocates and fills in an intp array with the converted values.
Remember to free the pointer seq.ptr when done using PyDimMem_FREE(seq.ptr)** </blockquote>
Check to see if it is a number

Referenced by get_decsrcref_fields_transfer_function().

NPY_NO_EXPORT int PyArray_IntpFromSequence ( PyObject *  seq,
npy_intp vals,
int  maxvals 
)
PyArray_IntpFromSequence
Returns the number of dimensions or -1 if an error occurred. vals must be large enough to hold maxvals
Check to see if sequence is a single integer first. or, can be made into one
Check wether there was an error - if the error was an overflow, raise a ValueError instead to be more helpful
Check wether there was an error - if the error was an overflow, raise a ValueError instead to be more helpful
NPY_NO_EXPORT PyObject* PyArray_IntTupleFromIntp ( int  len,
npy_intp vals 
)
Lifted from numarray
TODO: not documented
PyArray_IntTupleFromIntp
NPY_NO_EXPORT int PyArray_PyIntAsInt ( PyObject *  o)

Other conversion functions

NPY_NO_EXPORT int PyArray_SearchsideConverter ( PyObject *  obj,
void *  addr 
)
NPY_NO_EXPORT int PyArray_SortkindConverter ( PyObject *  obj,
NPY_SORTKIND sortkind 
)
Convert object to sort kind
NPY_NO_EXPORT int PyArray_TypestrConvert ( int  itemsize,
int  gentype 
)
Typestr converter
For 'O4' and 'O8', let it pass, but raise a deprecation warning. For all other cases, raise an exception by leaving newtype unset.

Variable Documentation

WARNING: This flag is a bad idea, but was the only way to both
  1. Support unpickling legacy pickles with object types.
  2. Deprecate (and later disable) usage of O4 and O8
The key problem is that the pickled representation unpickles by directly calling the dtype constructor, which has no way of knowing that it is in an unpickle context instead of a normal context without evil global state like we create here.