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

static int PyArray_PyIntAsInt_ErrMsg (PyObject *o, const char *msg) NPY_GCC_NONNULL(2)
static npy_intp PyArray_PyIntAsIntp_ErrMsg (PyObject *o, const char *msg) NPY_GCC_NONNULL(2)
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_SelectkindConverter (PyObject *obj, NPY_SELECTKIND *selectkind)
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 npy_intp PyArray_IntpFromIndexSequence (PyObject *seq, npy_intp *vals, npy_intp maxvals)
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_SUCCEED.

NPY_NO_EXPORT int PyArray_BoolConverter ( PyObject *  object,
npy_bool val 
)
Convert an object to true / false
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

References NPY_FAIL.

NPY_NO_EXPORT int PyArray_ByteorderConverter ( PyObject *  obj,
char *  endian 
)
Convert object to endian
NPY_NO_EXPORT int PyArray_CastingConverter ( PyObject *  obj,
NPY_CASTING casting 
)
Convert any Python object, obj, to an NPY_CASTING enum.

References PyArray_PyIntAsIntp_ErrMsg().

Referenced by _array_fromobject().

NPY_NO_EXPORT int PyArray_ClipmodeConverter ( PyObject *  object,
NPY_CLIPMODE val 
)
Convert an object to NPY_RAISE / NPY_CLIP / NPY_WRAP

Referenced by array_fill().

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)
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 _array_fromobject().

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
Special case letting axis={-1,0} slip through for scalars, for backwards compatibility reasons.
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 an integer number
After the deprecation the PyNumber_Check could be replaced by PyIndex_Check. FIXME 1.9 ?
NPY_NO_EXPORT npy_intp PyArray_IntpFromIndexSequence ( PyObject *  seq,
npy_intp vals,
npy_intp  maxvals 
)
PyArray_IntpFromIndexSequence Returns the number of dimensions or -1 if an error occurred. vals must be large enough to hold maxvals. Opposed to PyArray_IntpFromSequence it uses and returns npy_intp for the number of values.
Check to see if sequence is a single integer first. or, can be made into one

References NPY_BOOL, NPY_FLOAT16, NPY_FLOATINGLTR, NPY_GENBOOLLTR, NPY_SIGNEDLTR, and NPY_UNSIGNEDLTR.

NPY_NO_EXPORT int PyArray_IntpFromSequence ( PyObject *  seq,
npy_intp vals,
int  maxvals 
)
PyArray_IntpFromSequence
Returns the number of integers converted or -1 if an error occurred. vals must be large enough to hold maxvals
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
2015-12-14, 1.11
2015-12-14, 1.11
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_cumprod(), and array_dot().

NPY_NO_EXPORT int PyArray_PyIntAsInt ( PyObject *  o)
static int PyArray_PyIntAsInt_ErrMsg ( PyObject *  o,
const char *  msg 
) [static]

Other conversion functions

This assumes that NPY_SIZEOF_INTP >= NPY_SIZEOF_INT
static npy_intp PyArray_PyIntAsIntp_ErrMsg ( PyObject *  o,
const char *  msg 
) [static]
Be a bit stricter and not allow bools. np.bool_ is also disallowed as Boolean arrays do not currently support index.

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Unknown target name: "np.bool".
Since it is the usual case, first check if o is an integer. This is an exact check, since otherwise __index__ is used.
No overflow is possible, so we can just return
The most general case. PyNumber_Index(o) covers everything including arrays. In principle it may be possible to replace the whole function by PyIndex_AsSSize_t after deprecation.
Only replace TypeError's here, which are the normal errors.

<

silence unused warning

Referenced by PyArray_CastingConverter().

NPY_NO_EXPORT int PyArray_SearchsideConverter ( PyObject *  obj,
void *  addr 
)
Convert object to searchsorted side

References NPY_SUCCEED.

NPY_NO_EXPORT int PyArray_SelectkindConverter ( PyObject *  obj,
NPY_SELECTKIND selectkind 
)
Convert object to select kind

References NPY_FAIL, NPY_SEARCHLEFT, NPY_SEARCHRIGHT, NPY_SUCCEED, PyBytes_AsString, and side().

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.
2012-02-04, 1.7, not sure when this can be removed

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.