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

Function PyArray_MultiIndexSetItem

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

* Sets a single item in the array, based on a single multi-index * array of values, which must be of length PyArray_NDIM(self). * * Returns 0 on success, -1 on failure. */

Source from the content-addressed store, hash-verified

3082 * Returns 0 on success, -1 on failure.
3083 */
3084NPY_NO_EXPORT int
3085PyArray_MultiIndexSetItem(PyArrayObject *self, const npy_intp *multi_index,
3086 PyObject *obj)
3087{
3088 int idim, ndim = PyArray_NDIM(self);
3089 char *data = PyArray_DATA(self);
3090 npy_intp *shape = PyArray_SHAPE(self);
3091 npy_intp *strides = PyArray_STRIDES(self);
3092
3093 /* Get the data pointer */
3094 for (idim = 0; idim < ndim; ++idim) {
3095 npy_intp shapevalue = shape[idim];
3096 npy_intp ind = multi_index[idim];
3097
3098 if (check_and_adjust_index(&ind, shapevalue, idim, NULL) < 0) {
3099 return -1;
3100 }
3101 data += ind * strides[idim];
3102 }
3103
3104 return PyArray_Pack(PyArray_DESCR(self), data, obj);
3105}

Callers 1

array_setscalarFunction · 0.85

Calls 7

PyArray_NDIMFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_SHAPEFunction · 0.85
PyArray_STRIDESFunction · 0.85
check_and_adjust_indexFunction · 0.85
PyArray_PackFunction · 0.85
PyArray_DESCRFunction · 0.85

Tested by

no test coverage detected