Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Definition of the Numpy Iterator Struct from Beautiful Code
typedef struct {<-------------------------immutable key value data store to iterate over given array
int nd_m1;<------------------------number of dimensions in array minus 1
npy_intp index;<-------------------counter for element that iterator is at
npy_intp size;<--------------------number of elements in array
npy_intp coords[NPY_MAXDIMS];<-----the N-dimensional location of the current element
npy_intp dims_m1[NPY_MAXDIMS];<----number of elements along each dimension minus 1
npy_intp strides[NPY_MAXDIMS];<----number of bytes separating the elements in each dimension
npy_intp backstrides[NPY_MAXDIMS];<number of bytes to subtract to return to beginning of dimension
npy_intp factors[NPY_MAXDIMS];<----for converting from 1D index to N-dimensional coords in 1D arrays
PyArrayObject *ao;<----------------pointer to the underlying array this iterator is built from
char *dataptr;<--------------------pointer to the (first byte of) the current value of the array
npy_bool contiguous;<--------------TRUE (1) if the array elements are all next to each other in memory
} PyArrayIterObject;<------------------name of struct object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment