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

Function PyArray_RawIterBaseInit

numpy/core/src/multiarray/iterators.c:126–163  ·  view source on GitHub ↗

* This is common initialization code between PyArrayIterObject and * PyArrayNeighborhoodIterObject * * Steals a reference to the array object which gets removed at deallocation, * if the iterator is allocated statically and its dealloc not called, it * can be thought of as borrowing the reference. */

Source from the content-addressed store, hash-verified

124 * can be thought of as borrowing the reference.
125 */
126NPY_NO_EXPORT void
127PyArray_RawIterBaseInit(PyArrayIterObject *it, PyArrayObject *ao)
128{
129 int nd, i;
130
131 nd = PyArray_NDIM(ao);
132 PyArray_UpdateFlags(ao, NPY_ARRAY_C_CONTIGUOUS);
133 if (PyArray_ISCONTIGUOUS(ao)) {
134 it->contiguous = 1;
135 }
136 else {
137 it->contiguous = 0;
138 }
139 it->ao = ao;
140 it->size = PyArray_SIZE(ao);
141 it->nd_m1 = nd - 1;
142 if (nd != 0) {
143 it->factors[nd-1] = 1;
144 }
145 for (i = 0; i < nd; i++) {
146 it->dims_m1[i] = PyArray_DIMS(ao)[i] - 1;
147 it->strides[i] = PyArray_STRIDES(ao)[i];
148 it->backstrides[i] = it->strides[i] * it->dims_m1[i];
149 if (i > 0) {
150 it->factors[nd-i-1] = it->factors[nd-i] * PyArray_DIMS(ao)[nd-i];
151 }
152 it->bounds[i][0] = 0;
153 it->bounds[i][1] = PyArray_DIMS(ao)[i] - 1;
154 it->limits[i][0] = 0;
155 it->limits[i][1] = PyArray_DIMS(ao)[i] - 1;
156 it->limits_sizes[i] = it->limits[i][1] - it->limits[i][0] + 1;
157 }
158
159 it->translate = &get_ptr_simple;
160 PyArray_ITER_RESET(it);
161
162 return;
163}
164
165static void
166array_iter_base_dealloc(PyArrayIterObject *it)

Callers 3

PyArray_XDECREFFunction · 0.85
PyArray_IterNewFunction · 0.85

Calls 4

PyArray_NDIMFunction · 0.85
PyArray_UpdateFlagsFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_STRIDESFunction · 0.85

Tested by

no test coverage detected