numpy
2.0.0
|
#include "nditer_impl.h"
#define NPY_ITERATOR_IMPLEMENTATION_CODE |
#define NPY_NO_DEPRECATED_API NPY_API_VERSION |
NPY_NO_EXPORT int npyiter_allocate_buffers | ( | NpyIter * | iter, |
char ** | errmsg | ||
) |
References PyArray_TransferStridedToNDim().
Referenced by NpyIter_EnableExternalLoop().
static npy_intp npyiter_checkreducesize | ( | NpyIter * | iter, |
npy_intp | count, | ||
npy_intp * | reduce_innersize, | ||
npy_intp * | reduce_outerdim | ||
) | [static] |
NPY_NO_EXPORT void npyiter_coalesce_axes | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT void npyiter_copy_from_buffers | ( | NpyIter * | iter | ) |
Referenced by NpyIter_EnableExternalLoop().
NPY_NO_EXPORT void npyiter_copy_to_buffers | ( | NpyIter * | iter, |
char ** | prev_dataptrs | ||
) |
Referenced by NpyIter_EnableExternalLoop().
NPY_NO_EXPORT int NpyIter_CreateCompatibleStrides | ( | NpyIter * | iter, |
npy_intp | itemsize, | ||
npy_intp * | outstrides | ||
) |
output array created using the NPY_ITER_ALLOCATE flag, where NULL was passed for op_axes. This is for data packed contiguously, but not necessarily in C or Fortran order. This should be used together with NpyIter_GetShape and NpyIter_GetNDim.
A use case for this function is to match the shape and layout of the iterator and tack on one or more dimensions. For example, in order to generate a vector per input value for a numerical gradient, you pass in ndim*itemsize for itemsize, then add another dimension to the end with size ndim and stride itemsize. To do the Hessian matrix, you do the same thing but add two dimensions, or take advantage of the symmetry and pack it into 1 dimension with a particular encoding.
This function may only be called if the iterator is tracking a multi-index and if NPY_ITER_DONT_NEGATE_STRIDES was used to prevent an axis from being iterated in reverse order.
If an array is created with this method, simply adding 'itemsize' for each iteration will traverse the new array matching the iterator.
Returns NPY_SUCCEED or NPY_FAIL.
NPY_NO_EXPORT void NpyIter_DebugPrint | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT int NpyIter_EnableExternalLoop | ( | NpyIter * | iter | ) |
References NPY_FAIL, NPY_SUCCEED, npyiter_allocate_buffers(), npyiter_copy_from_buffers(), npyiter_copy_to_buffers(), and npyiter_goto_iterindex().
Referenced by npyiter_reset().
NPY_NO_EXPORT npy_intp* NpyIter_GetAxisStrideArray | ( | NpyIter * | iter, |
int | axis | ||
) |
If the iterator is tracking a multi-index, gets the strides for the axis specified, otherwise gets the strides for the iteration axis as Fortran order (fastest-changing axis first).
Returns NULL if an error occurs.
NPY_NO_EXPORT npy_intp NpyIter_GetBufferSize | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT char** NpyIter_GetDataPtrArray | ( | NpyIter * | iter | ) |
Referenced by apply_business_day_count(), and business_day_offset().
NPY_NO_EXPORT PyArray_Descr** NpyIter_GetDescrArray | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT npy_intp* NpyIter_GetIndexPtr | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT char** NpyIter_GetInitialDataPtrArray | ( | NpyIter * | iter | ) |
directly into the arrays (never pointing to a buffer), for starting unbuffered iteration. This always returns the addresses for the iterator position as reset to iterator index 0.
These pointers are different from the pointers accepted by NpyIter_ResetBasePointers, because the direction along some axes may have been reversed, requiring base offsets.
This function may be safely called without holding the Python GIL.
NPY_NO_EXPORT void NpyIter_GetInnerFixedStrideArray | ( | NpyIter * | iter, |
npy_intp * | out_strides | ||
) |
change during iteration receive the value NPY_MAX_INTP. Once the iterator is ready to iterate, call this to get the strides which will always be fixed in the inner loop, then choose optimized inner loop functions which take advantage of those fixed strides.
This function may be safely called without holding the Python GIL.
NPY_NO_EXPORT npy_intp* NpyIter_GetInnerLoopSizePtr | ( | NpyIter * | iter | ) |
Referenced by apply_business_day_count(), and business_day_offset().
NPY_NO_EXPORT npy_intp* NpyIter_GetInnerStrideArray | ( | NpyIter * | iter | ) |
Referenced by apply_business_day_count(), and business_day_offset().
NPY_NO_EXPORT npy_intp NpyIter_GetIterIndex | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT void NpyIter_GetIterIndexRange | ( | NpyIter * | iter, |
npy_intp * | istart, | ||
npy_intp * | iend | ||
) |
NPY_NO_EXPORT npy_intp NpyIter_GetIterSize | ( | NpyIter * | iter | ) |
Referenced by apply_business_day_count(), business_day_offset(), and npyiter_reset().
NPY_NO_EXPORT PyArrayObject* NpyIter_GetIterView | ( | NpyIter * | iter, |
npy_intp | i | ||
) |
References NPY_MAX_INTP.
NPY_NO_EXPORT int NpyIter_GetNDim | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT int NpyIter_GetNOp | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT PyArrayObject** NpyIter_GetOperandArray | ( | NpyIter * | iter | ) |
Referenced by apply_business_day_count(), and business_day_offset().
NPY_NO_EXPORT void NpyIter_GetReadFlags | ( | NpyIter * | iter, |
char * | outreadflags | ||
) |
NPY_NO_EXPORT int NpyIter_GetShape | ( | NpyIter * | iter, |
npy_intp * | outshape | ||
) |
otherwise gets the shape of the iteration as Fortran-order (fastest-changing index first).
The reason Fortran-order is returned when a multi-index is not enabled is that this is providing a direct view into how the iterator traverses the n-dimensional space. The iterator organizes its memory from fastest index to slowest index, and when a multi-index is enabled, it uses a permutation to recover the original order.
Returns NPY_SUCCEED or NPY_FAIL.
References NPY_ARRAY_UPDATE_ALL, NPY_ARRAY_WRITEABLE, NPY_MAXDIMS, PyArray_DESCR, PyArray_NewFromDescr(), PyArray_SetBaseObject(), PyArray_Type, and PyArray_UpdateFlags().
NPY_NO_EXPORT void NpyIter_GetWriteFlags | ( | NpyIter * | iter, |
char * | outwriteflags | ||
) |
NPY_NO_EXPORT void npyiter_goto_iterindex | ( | NpyIter * | iter, |
npy_intp | iterindex | ||
) |
Referenced by NpyIter_EnableExternalLoop().
NPY_NO_EXPORT int NpyIter_GotoIndex | ( | NpyIter * | iter, |
npy_intp | flat_index | ||
) |
to the specified index.
Returns NPY_SUCCEED on success, NPY_FAIL on failure.
NPY_NO_EXPORT int NpyIter_GotoIterIndex | ( | NpyIter * | iter, |
npy_intp | iterindex | ||
) |
which matches the iteration order of the iterator.
Returns NPY_SUCCEED on success, NPY_FAIL on failure.
NPY_NO_EXPORT int NpyIter_GotoMultiIndex | ( | NpyIter * | iter, |
npy_intp * | multi_index | ||
) |
correct number of entries for 'ndim'. It is only valid when NPY_ITER_MULTI_INDEX was passed to the constructor. This operation fails if the multi-index is out of bounds.
Returns NPY_SUCCEED on success, NPY_FAIL on failure.
NPY_NO_EXPORT npy_bool NpyIter_HasExternalLoop | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT npy_bool NpyIter_HasIndex | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT npy_bool NpyIter_HasMultiIndex | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT npy_bool NpyIter_IsBuffered | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT npy_bool NpyIter_IsFirstVisit | ( | NpyIter * | iter, |
int | iop | ||
) |
of the specified reduction operand which the iterator points at are being seen for the first time. The function returns a reasonable answer for reduction operands and when buffering is disabled. The answer may be incorrect for buffered non-reduction operands.
This function is intended to be used in EXTERNAL_LOOP mode only, and will produce some wrong answers when that mode is not enabled.
If this function returns true, the caller should also check the inner loop stride of the operand, because if that stride is 0, then only the first element of the innermost external loop is being visited for the first time.
NPY_NO_EXPORT npy_bool NpyIter_IsGrowInner | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT int NpyIter_RemoveAxis | ( | NpyIter * | iter, |
int | axis | ||
) |
was set for iterator creation, and does not work if buffering is enabled. This function also resets the iterator to its initial state.
Returns NPY_SUCCEED or NPY_FAIL.
NPY_NO_EXPORT int NpyIter_RemoveMultiIndex | ( | NpyIter * | iter | ) |
NPY_NO_EXPORT int NpyIter_Reset | ( | NpyIter * | iter, |
char ** | errmsg | ||
) |
NPY_NO_EXPORT int NpyIter_ResetBasePointers | ( | NpyIter * | iter, |
char ** | baseptrs, | ||
char ** | errmsg | ||
) |
This function requires great caution.
If errmsg is non-NULL, it should point to a variable which will receive the error message, and no Python exception will be set. This is so that the function can be called from code not holding the GIL.
NPY_NO_EXPORT int NpyIter_ResetToIterIndexRange | ( | NpyIter * | iter, |
npy_intp | istart, | ||
npy_intp | iend, | ||
char ** | errmsg | ||
) |