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

Function check_and_adjust_index

numpy/core/src/multiarray/common.h:103–128  ·  view source on GitHub ↗

* Returns -1 and sets an exception if *index is an invalid index for * an array of size max_item, otherwise adjusts it in place to be * 0 <= *index < max_item, and returns 0. * 'axis' should be the array axis that is being indexed over, if known. If * unknown, use -1. * If _save is NULL it is assumed the GIL is taken * If _save is not NULL it is assumed the GIL is not taken and it * is acqu

Source from the content-addressed store, hash-verified

101 * is acquired in the case of an error
102 */
103static inline int
104check_and_adjust_index(npy_intp *index, npy_intp max_item, int axis,
105 PyThreadState * _save)
106{
107 /* Check that index is valid, taking into account negative indices */
108 if (NPY_UNLIKELY((*index < -max_item) || (*index >= max_item))) {
109 NPY_END_THREADS;
110 /* Try to be as clear as possible about what went wrong. */
111 if (axis >= 0) {
112 PyErr_Format(PyExc_IndexError,
113 "index %"NPY_INTP_FMT" is out of bounds "
114 "for axis %d with size %"NPY_INTP_FMT,
115 *index, axis, max_item);
116 } else {
117 PyErr_Format(PyExc_IndexError,
118 "index %"NPY_INTP_FMT" is out of bounds "
119 "for size %"NPY_INTP_FMT, *index, max_item);
120 }
121 return -1;
122 }
123 /* adjust negative indices */
124 if (*index < 0) {
125 *index += max_item;
126 }
127 return 0;
128}
129
130/*
131 * Returns -1 and sets an exception if *axis is an invalid axis for

Callers 13

array_toscalarFunction · 0.85
array_setscalarFunction · 0.85
npy_fasttake_implFunction · 0.85
PyArray_PutToFunction · 0.85
parse_index_entryFunction · 0.85
iter_subscript_intFunction · 0.85
iter_ass_sub_intFunction · 0.85
iter_ass_subscriptFunction · 0.85
get_item_pointerFunction · 0.85
get_view_from_indexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected