numpy  2.0.0
src/multiarray/conversion_utils.c File Reference
#include <Python.h>
#include "structmember.h"
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "npy_config.h"
#include "npy_pycompat.h"
#include "common.h"
#include "arraytypes.h"
#include "conversion_utils.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

Functions

NPY_NO_EXPORT int PyArray_Converter (PyObject *object, PyObject **address)
NPY_NO_EXPORT int PyArray_OutputConverter (PyObject *object, PyArrayObject **address)
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_AxisConverter (PyObject *obj, int *axis)
NPY_NO_EXPORT int PyArray_ConvertMultiAxis (PyObject *axis_in, int ndim, npy_bool *out_axis_flags)
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_OrderConverter (PyObject *object, NPY_ORDER *val)
NPY_NO_EXPORT int PyArray_ClipmodeConverter (PyObject *object, NPY_CLIPMODE *val)
NPY_NO_EXPORT int PyArray_ConvertClipmodeSequence (PyObject *object, NPY_CLIPMODE *modes, int n)
NPY_NO_EXPORT int PyArray_CastingConverter (PyObject *obj, NPY_CASTING *casting)
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)

Variables

NPY_NO_EXPORT int evil_global_disable_warn_O4O8_flag = 0

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

NPY_NO_EXPORT int PyArray_AxisConverter ( PyObject *  obj,
int *  axis 
)
Get axis from an object (possibly None) -- a converter function, <blockquote> See also PyArray_ConvertMultiAxis, which also handles a tuple of axes.</blockquote>

References NPY_FAIL, and NPY_SUCCEED.

Referenced by PyArray_Dump().

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_CastingConverter ( PyObject *  obj,
NPY_CASTING casting 
)
Convert any Python object, obj, to an NPY_CASTING enum.

Referenced by _prepend_ones(), and PyArray_ConvertClipmodeSequence().

NPY_NO_EXPORT int PyArray_ClipmodeConverter ( PyObject *  object,
NPY_CLIPMODE val 
)
Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP
NPY_NO_EXPORT int PyArray_ConvertClipmodeSequence ( PyObject *  object,
NPY_CLIPMODE modes,
int  n 
)
Convert an object to an array of n NPY_CLIPMODE values.
This is intended to be used in functions where a different mode could be applied to each axis, like in ravel_multi_index.
Get the clip mode(s)

References PyArray_CastingConverter().

NPY_NO_EXPORT int PyArray_Converter ( PyObject *  object,
PyObject **  address 
)

Useful function for conversion when used with PyArg_ParseTuple

System Message: WARNING/2 (<string>, line 1)
Title overline too short.

 Useful function for conversion when used with PyArg_ParseTuple
 
Useful to pass as converter function for O& processing in PyArgs_ParseTuple. <blockquote>
This conversion function can be used with the "O&" argument for PyArg_ParseTuple. It will immediately return an object of array type or will convert to a NPY_ARRAY_CARRAY any other object.
If you use PyArray_Converter, you must DECREF the array when finished as you get a new reference to it. </blockquote>

References NPY_FAIL.

Referenced by _prepend_ones().

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 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_OrderConverter ( PyObject *  object,
NPY_ORDER val 
)
Convert an object to FORTRAN / C / ANY / KEEP
Leave the desired default from the caller for NULL/Py_None

Referenced by array_stddev(), and PyArray_SearchsideConverter().

NPY_NO_EXPORT int PyArray_OutputConverter ( PyObject *  object,
PyArrayObject **  address 
)
Useful to pass as converter function for O& processing in
PyArgs_ParseTuple for output arrays

Referenced by array_compress(), and PyArray_Dump().

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.