MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_MultiIndexGetItem

Function PyArray_MultiIndexGetItem

numpy/core/src/multiarray/item_selection.c:3056–3076  ·  view source on GitHub ↗

* Gets a single item from the array, based on a single multi-index * array of values, which must be of length PyArray_NDIM(self). */

Source from the content-addressed store, hash-verified

3054 * array of values, which must be of length PyArray_NDIM(self).
3055 */
3056NPY_NO_EXPORT PyObject *
3057PyArray_MultiIndexGetItem(PyArrayObject *self, const npy_intp *multi_index)
3058{
3059 int idim, ndim = PyArray_NDIM(self);
3060 char *data = PyArray_DATA(self);
3061 npy_intp *shape = PyArray_SHAPE(self);
3062 npy_intp *strides = PyArray_STRIDES(self);
3063
3064 /* Get the data pointer */
3065 for (idim = 0; idim < ndim; ++idim) {
3066 npy_intp shapevalue = shape[idim];
3067 npy_intp ind = multi_index[idim];
3068
3069 if (check_and_adjust_index(&ind, shapevalue, idim, NULL) < 0) {
3070 return NULL;
3071 }
3072 data += ind * strides[idim];
3073 }
3074
3075 return PyArray_GETITEM(self, data);
3076}
3077
3078/*
3079 * Sets a single item in the array, based on a single multi-index

Callers 1

array_toscalarFunction · 0.85

Calls 6

PyArray_NDIMFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_SHAPEFunction · 0.85
PyArray_STRIDESFunction · 0.85
check_and_adjust_indexFunction · 0.85
PyArray_GETITEMFunction · 0.85

Tested by

no test coverage detected