numpy 2.0.0
src/multiarray/nditer_pywrap.c File Reference
#include "Python.h"
#include "structmember.h"
#include <numpy/ndarrayobject.h>
#include <numpy/npy_3kcompat.h>
#include "npy_config.h"

Data Structures

struct  NewNpyArrayIterObject_tag

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API
#define _MULTIARRAYMODULE

Typedefs

typedef struct
NewNpyArrayIterObject_tag 
NewNpyArrayIterObject

Functions

void npyiter_cache_values (NewNpyArrayIterObject *self)
static PyObject * npyiter_new (PyTypeObject *subtype, PyObject *args, PyObject *kwds)
static int NpyIter_GlobalFlagsConverter (PyObject *flags_in, npy_uint32 *flags)
static int npyiter_order_converter (PyObject *order_in, NPY_ORDER *order)
NPY_NO_EXPORT int PyArray_CastingConverter (PyObject *obj, NPY_CASTING *casting)
static int NpyIter_OpFlagsConverter (PyObject *op_flags_in, npy_uint32 *op_flags)
static int npyiter_convert_op_flags_array (PyObject *op_flags_in, npy_uint32 *op_flags_array, npy_intp nop)
static int npyiter_convert_dtypes (PyObject *op_dtypes_in, PyArray_Descr **op_dtypes, npy_intp nop)
static int npyiter_convert_op_axes (PyObject *op_axes_in, npy_intp nop, int **op_axes, int *oa_ndim)
static int npyiter_convert_ops (PyObject *op_in, PyObject *op_flags_in, PyArrayObject **op, npy_uint32 *op_flags, int *nop_out)
static int npyiter_init (NewNpyArrayIterObject *self, PyObject *args, PyObject *kwds)
NPY_NO_EXPORT PyObject * NpyIter_NestedIters (PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
static void npyiter_dealloc (NewNpyArrayIterObject *self)
static int npyiter_resetbasepointers (NewNpyArrayIterObject *self)
static PyObject * npyiter_reset (NewNpyArrayIterObject *self)
static PyObject * npyiter_copy (NewNpyArrayIterObject *self)
static PyObject * npyiter_iternext (NewNpyArrayIterObject *self)
static PyObject * npyiter_remove_axis (NewNpyArrayIterObject *self, PyObject *args)
static PyObject * npyiter_remove_multi_index (NewNpyArrayIterObject *self)
static PyObject * npyiter_enable_external_loop (NewNpyArrayIterObject *self)
static PyObject * npyiter_debug_print (NewNpyArrayIterObject *self)
NPY_NO_EXPORT PyObject * npyiter_seq_item (NewNpyArrayIterObject *self, Py_ssize_t i)
static PyObject * npyiter_value_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_operands_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_itviews_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_next (NewNpyArrayIterObject *self)
static PyObject * npyiter_shape_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_multi_index_get (NewNpyArrayIterObject *self)
static int npyiter_multi_index_set (NewNpyArrayIterObject *self, PyObject *value)
static PyObject * npyiter_index_get (NewNpyArrayIterObject *self)
static int npyiter_index_set (NewNpyArrayIterObject *self, PyObject *value)
static PyObject * npyiter_iterindex_get (NewNpyArrayIterObject *self)
static int npyiter_iterindex_set (NewNpyArrayIterObject *self, PyObject *value)
static PyObject * npyiter_iterrange_get (NewNpyArrayIterObject *self)
static int npyiter_iterrange_set (NewNpyArrayIterObject *self, PyObject *value)
static PyObject * npyiter_has_delayed_bufalloc_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_iterationneedsapi_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_has_multi_index_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_has_index_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_dtypes_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_ndim_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_nop_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_itersize_get (NewNpyArrayIterObject *self)
static PyObject * npyiter_finished_get (NewNpyArrayIterObject *self)
NPY_NO_EXPORT Py_ssize_t npyiter_seq_length (NewNpyArrayIterObject *self)
NPY_NO_EXPORT PyObject * npyiter_seq_slice (NewNpyArrayIterObject *self, Py_ssize_t ilow, Py_ssize_t ihigh)
NPY_NO_EXPORT int npyiter_seq_ass_item (NewNpyArrayIterObject *self, Py_ssize_t i, PyObject *v)
static int npyiter_seq_ass_slice (NewNpyArrayIterObject *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
static PyObject * npyiter_subscript (NewNpyArrayIterObject *self, PyObject *op)
static int npyiter_ass_subscript (NewNpyArrayIterObject *self, PyObject *op, PyObject *value)

Variables

static PyMethodDef npyiter_methods []
static PyMemberDef npyiter_members []
static PyGetSetDef npyiter_getsets []
NPY_NO_EXPORT PySequenceMethods npyiter_as_sequence
NPY_NO_EXPORT PyMappingMethods npyiter_as_mapping
NPY_NO_EXPORT PyTypeObject NpyIter_Type

Define Documentation

#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API
#define PY_SSIZE_T_CLEAN

Typedef Documentation


Function Documentation

static int npyiter_ass_subscript ( NewNpyArrayIterObject self,
PyObject *  op,
PyObject *  value 
) [static]

Referenced by npyiter_seq_ass_slice().

void npyiter_cache_values ( NewNpyArrayIterObject self)

iternext and get_multi_index functions
Internal data pointers
The read/write settings

static int npyiter_convert_dtypes ( PyObject *  op_dtypes_in,
PyArray_Descr **  op_dtypes,
npy_intp  nop 
) [static]

If the input isn't a tuple of dtypes, try converting it as-is to a dtype, and replicating to all operands.
Try converting the object to a descr

static int npyiter_convert_op_axes ( PyObject *  op_axes_in,
npy_intp  nop,
int **  op_axes,
int *  oa_ndim 
) [static]

Copy the tuples into op_axes
numpy.newaxis is None

static int npyiter_convert_op_flags_array ( PyObject *  op_flags_in,
npy_uint32 *  op_flags_array,
npy_intp  nop 
) [static]

If the first item is a string, try as one set of flags

static int npyiter_convert_ops ( PyObject *  op_in,
PyObject *  op_flags_in,
PyArrayObject **  op,
npy_uint32 *  op_flags,
int *  nop_out 
) [static]
Converts the operand array and op_flags array into the form NpyIter_AdvancedNew needs. Sets nop, and on success, each op[i] owns a reference to an array object.

nop and op
This is converted to an array after op flags are retrieved
Is converted to an array after op flags are retrieved
op_flags
By default, make NULL operands writeonly and flagged for allocation, and everything else readonly. To write to a provided operand, you must specify the write flag manually.
Now that we have the flags - convert all the ops to arrays

References NPY_ITER_READONLY.

static PyObject* npyiter_copy ( NewNpyArrayIterObject self) [static]
Makes a copy of the iterator. Note that the nesting is not copied.

Allocate the iterator
Copy the C iterator
Cache some values for the member functions to use

static void npyiter_dealloc ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_debug_print ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_dtypes_get ( NewNpyArrayIterObject self) [static]

Referenced by npyiter_seq_ass_slice().

static PyObject* npyiter_enable_external_loop ( NewNpyArrayIterObject self) [static]

EnableExternalLoop invalidates cached values
EnableExternalLoop also resets the iterator

static PyObject* npyiter_finished_get ( NewNpyArrayIterObject self) [static]

Referenced by npyiter_seq_ass_slice().

static int NpyIter_GlobalFlagsConverter ( PyObject *  flags_in,
npy_uint32 *  flags 
) [static]

accept unicode input
Use switch statements to quickly isolate the right flag

static PyObject* npyiter_has_delayed_bufalloc_get ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_has_index_get ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_has_multi_index_get ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_index_get ( NewNpyArrayIterObject self) [static]
static int npyiter_index_set ( NewNpyArrayIterObject self,
PyObject *  value 
) [static]

If there is nesting, the nested iterators should be reset

References NpyIter_HasMultiIndex().

static int npyiter_init ( NewNpyArrayIterObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Set the dtypes and ops to all NULL to start
op and op_flags
op_request_dtypes
op_axes
Initialize to point to the op_axes arrays
Cache some values for the member functions to use
Release the references we got to the ops and dtypes

static PyObject* npyiter_iterationneedsapi_get ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_iterindex_get ( NewNpyArrayIterObject self) [static]
static int npyiter_iterindex_set ( NewNpyArrayIterObject self,
PyObject *  value 
) [static]

If there is nesting, the nested iterators should be reset

static PyObject* npyiter_iternext ( NewNpyArrayIterObject self) [static]

If there is nesting, the nested iterators should be reset

static PyObject* npyiter_iterrange_get ( NewNpyArrayIterObject self) [static]
static int npyiter_iterrange_set ( NewNpyArrayIterObject self,
PyObject *  value 
) [static]

If there is nesting, the nested iterators should be reset

References NpyIter_GetNOp(), NpyIter_HasDelayedBufAlloc(), and NpyIter_HasExternalLoop().

static PyObject* npyiter_itersize_get ( NewNpyArrayIterObject self) [static]

Referenced by npyiter_seq_ass_slice().

static PyObject* npyiter_itviews_get ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_multi_index_get ( NewNpyArrayIterObject self) [static]
static int npyiter_multi_index_set ( NewNpyArrayIterObject self,
PyObject *  value 
) [static]

If there is nesting, the nested iterators should be reset

static PyObject* npyiter_ndim_get ( NewNpyArrayIterObject self) [static]

Referenced by npyiter_seq_ass_slice().

NPY_NO_EXPORT PyObject* NpyIter_NestedIters ( PyObject *  NPY_UNUSEDself,
PyObject *  args,
PyObject *  kwds 
)

axes
This check is very important, without it out of bounds data accesses are possible.
op and op_flags
Set the dtypes to all NULL to start as well
op_request_dtypes
For broadcasting allocated arrays
Clear any unnecessary ALLOCATE flags, so we can use them to indicate exactly the allocated outputs. Also, separate the inner loop flags.
Clear any flags allowing copies or output allocation for the inner loop.
If buffering is enabled and copying is not, clear the nbo_aligned flag and strip the data type for the outer loops.
Only the inner loop gets the buffering and no inner flags
All the operands' op_axes are the same, except for allocated outputs.
printf("n"); for (iop = 0; iop < nop; ++iop) {

System Message: ERROR/3 (<string>, line 4) Unexpected indentation.

<blockquote>

npy_intp i;

for (i = 0; i < nested_naxes[inest]; ++i) {
printf("d ", (int)op_axes_nop[iop][i]);
System Message: WARNING/2 (<string>, line 8) Definition list ends without a blank line; unexpected unindent.
} printf("n"); </blockquote>

System Message: WARNING/2 (<string>, line 10) Block quote ends without a blank line; unexpected unindent.
}
Allocate the iterator
Cache some values for the member functions to use
If there are any allocated outputs or any copies were made, adjust op so that the other iterators use the same ones.
Clear any flags allowing copies for the rest of the iterators
Clear the common dtype flag for the rest of the iterators
Release our references to the ops and dtypes
Set up the nested child references
Indicates which iterator to reset with new base pointers each iteration step.
Need to do a nested reset so all the iterators point at the right data

Referenced by _vec_string_no_args().

static PyObject* npyiter_new ( PyTypeObject *  subtype,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* npyiter_next ( NewNpyArrayIterObject self) [static]

Use the started flag for the Python iteration protocol to work when buffering is enabled.
If there is nesting, the nested iterators should be reset

static PyObject* npyiter_nop_get ( NewNpyArrayIterObject self) [static]

Referenced by npyiter_seq_ass_slice().

static PyObject* npyiter_operands_get ( NewNpyArrayIterObject self) [static]
static int NpyIter_OpFlagsConverter ( PyObject *  op_flags_in,
npy_uint32 *  op_flags 
) [static]

accept unicode input
Use switch statements to quickly isolate the right flag

static int npyiter_order_converter ( PyObject *  order_in,
NPY_ORDER order 
) [static]
TODO: Use PyArray_OrderConverter once 'K' is added there

accept unicode input

static PyObject* npyiter_remove_axis ( NewNpyArrayIterObject self,
PyObject *  args 
) [static]

RemoveAxis invalidates cached values
RemoveAxis also resets the iterator

References NpyIter_GetIterView(), and NpyIter_GetNOp().

static PyObject* npyiter_remove_multi_index ( NewNpyArrayIterObject self) [static]

RemoveMultiIndex invalidates cached values
RemoveMultiIndex also resets the iterator

References NPY_SUCCEED, and npyiter_resetbasepointers().

static PyObject* npyiter_reset ( NewNpyArrayIterObject self) [static]

If there is nesting, the nested iterators should be reset

static int npyiter_resetbasepointers ( NewNpyArrayIterObject self) [static]
NPY_NO_EXPORT int npyiter_seq_ass_item ( NewNpyArrayIterObject self,
Py_ssize_t  i,
PyObject *  v 
)

TODO - there should be a better way than this...

Referenced by npyiter_seq_ass_slice().

NPY_NO_EXPORT PyObject * npyiter_seq_item ( NewNpyArrayIterObject self,
Py_ssize_t  i 
)

If the iterator is going over every element, return array scalars

Referenced by npyiter_seq_ass_slice().

NPY_NO_EXPORT Py_ssize_t npyiter_seq_length ( NewNpyArrayIterObject self)

Referenced by npyiter_seq_ass_slice().

NPY_NO_EXPORT PyObject* npyiter_seq_slice ( NewNpyArrayIterObject self,
Py_ssize_t  ilow,
Py_ssize_t  ihigh 
)

Referenced by npyiter_seq_ass_slice().

static PyObject* npyiter_shape_get ( NewNpyArrayIterObject self) [static]
static PyObject* npyiter_subscript ( NewNpyArrayIterObject self,
PyObject *  op 
) [static]

Referenced by npyiter_seq_ass_slice().

static PyObject* npyiter_value_get ( NewNpyArrayIterObject self) [static]

Return an array or tuple of arrays with the values

NPY_NO_EXPORT int PyArray_CastingConverter ( PyObject *  obj,
NPY_CASTING casting 
)
Convert any Python object, obj, to an NPY_CASTING enum.
TODO: Move elsewhere

Referenced by einsum_sub_op_from_lists().


Variable Documentation

NPY_NO_EXPORT PyMappingMethods npyiter_as_mapping
Initial value:
 {






    (inquiry)npyiter_seq_length,          

    (binaryfunc)npyiter_subscript,        
    (objobjargproc)npyiter_ass_subscript, 
}

Referenced by npyiter_seq_ass_slice().

NPY_NO_EXPORT PySequenceMethods npyiter_as_sequence

Referenced by npyiter_seq_ass_slice().

PyGetSetDef npyiter_getsets[] [static]
PyMemberDef npyiter_members[] [static]
Initial value:
 {
    {NULL, 0, 0, 0, NULL},
}
PyMethodDef npyiter_methods[] [static]
Initial value:
 {
    {"reset", (PyCFunction)npyiter_reset, METH_NOARGS, NULL},
    {"copy", (PyCFunction)npyiter_copy, METH_NOARGS, NULL},
    {"__copy__", (PyCFunction)npyiter_copy, METH_NOARGS, NULL},
    {"iternext", (PyCFunction)npyiter_iternext, METH_NOARGS, NULL},
    {"remove_axis", (PyCFunction)npyiter_remove_axis, METH_VARARGS, NULL},
    {"remove_multi_index", (PyCFunction)npyiter_remove_multi_index,
                METH_NOARGS, NULL},
    {"enable_external_loop", (PyCFunction)npyiter_enable_external_loop,
                METH_NOARGS, NULL},
    {"debug_print", (PyCFunction)npyiter_debug_print, METH_NOARGS, NULL},
    {NULL, NULL, 0, NULL},
}
NPY_NO_EXPORT PyTypeObject NpyIter_Type

Referenced by npyiter_seq_ass_slice().