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

Function PyArray_MapIterSwapAxes

numpy/core/src/multiarray/mapping.c:125–161  ·  view source on GitHub ↗

NUMPY_API * * Swap the axes to or from their inserted form. MapIter always puts the * advanced (array) indices first in the iteration. But if they are * consecutive, will insert/transpose them back before returning. * This is stored as `mit->consec != 0` (the place where they are inserted) * For assignments, the opposite happens: The values to be assigned are * transposed (getmap=1 instead

Source from the content-addressed store, hash-verified

123 * undo the other operation.
124 */
125NPY_NO_EXPORT void
126PyArray_MapIterSwapAxes(PyArrayMapIterObject *mit, PyArrayObject **ret, int getmap)
127{
128 PyObject *new;
129 PyArray_Dims permute;
130 npy_intp d[NPY_MAXDIMS];
131 PyArrayObject *arr;
132
133 permute.ptr = d;
134 permute.len = mit->nd;
135
136 /*
137 * arr might not have the right number of dimensions
138 * and need to be reshaped first by pre-pending ones
139 */
140 arr = *ret;
141 if (PyArray_NDIM(arr) != mit->nd) {
142 for (int i = 1; i <= PyArray_NDIM(arr); i++) {
143 permute.ptr[mit->nd-i] = PyArray_DIMS(arr)[PyArray_NDIM(arr)-i];
144 }
145 for (int i = 0; i < mit->nd-PyArray_NDIM(arr); i++) {
146 permute.ptr[i] = 1;
147 }
148 new = PyArray_Newshape(arr, &permute, NPY_ANYORDER);
149 Py_DECREF(arr);
150 *ret = (PyArrayObject *)new;
151 if (new == NULL) {
152 return;
153 }
154 }
155
156 _get_transpose(mit->nd_fancy, mit->consec, mit->nd, getmap, permute.ptr);
157
158 new = PyArray_Transpose(*ret, &permute);
159 Py_DECREF(*ret);
160 *ret = (PyArrayObject *)new;
161}
162
163static inline void
164multi_DECREF(PyObject **objects, npy_intp n)

Callers 4

array_subscriptFunction · 0.85
array_assign_subscriptFunction · 0.85
PyArray_MapIterNewFunction · 0.85
ufunc_atFunction · 0.85

Calls 5

PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_NewshapeFunction · 0.85
_get_transposeFunction · 0.85
PyArray_TransposeFunction · 0.85

Tested by

no test coverage detected