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
| 123 | * undo the other operation. |
| 124 | */ |
| 125 | NPY_NO_EXPORT void |
| 126 | PyArray_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 | |
| 163 | static inline void |
| 164 | multi_DECREF(PyObject **objects, npy_intp n) |
no test coverage detected