Created
November 9, 2018 21:06
-
-
Save chelseatroy/b5497ae3ccf2afdf55f76805d43a9c2a to your computer and use it in GitHub Desktop.
Definition of the Numpy Iterator Struct from Beautiful Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct {<-------------------------immutable key value data store to iterate over given array | |
PyObject_HEAD | |
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