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

Function PyArray_IterAllButAxis

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

NUMPY_API * Get Iterator that iterates over all but one axis (don't use this with * PyArray_ITER_GOTO1D). The axis will be over-written if negative * with the axis having the smallest stride. */

Source from the content-addressed store, hash-verified

280 * with the axis having the smallest stride.
281 */
282NPY_NO_EXPORT PyObject *
283PyArray_IterAllButAxis(PyObject *obj, int *inaxis)
284{
285 PyArrayObject *arr;
286 PyArrayIterObject *it;
287 int axis;
288
289 if (!PyArray_Check(obj)) {
290 PyErr_SetString(PyExc_ValueError,
291 "Numpy IterAllButAxis requires an ndarray");
292 return NULL;
293 }
294 arr = (PyArrayObject *)obj;
295
296 it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);
297 if (it == NULL) {
298 return NULL;
299 }
300 if (PyArray_NDIM(arr)==0) {
301 return (PyObject *)it;
302 }
303 if (*inaxis < 0) {
304 int i, minaxis = 0;
305 npy_intp minstride = 0;
306 i = 0;
307 while (minstride == 0 && i < PyArray_NDIM(arr)) {
308 minstride = PyArray_STRIDE(arr,i);
309 i++;
310 }
311 for (i = 1; i < PyArray_NDIM(arr); i++) {
312 if (PyArray_STRIDE(arr,i) > 0 &&
313 PyArray_STRIDE(arr, i) < minstride) {
314 minaxis = i;
315 minstride = PyArray_STRIDE(arr,i);
316 }
317 }
318 *inaxis = minaxis;
319 }
320 axis = *inaxis;
321 /* adjust so that will not iterate over axis */
322 it->contiguous = 0;
323 if (it->size != 0) {
324 it->size /= PyArray_DIM(arr,axis);
325 }
326 it->dims_m1[axis] = 0;
327 it->backstrides[axis] = 0;
328
329 /*
330 * (won't fix factors so don't use
331 * PyArray_ITER_GOTO1D with this iterator)
332 */
333 return (PyObject *)it;
334}
335
336/*NUMPY_API
337 * Adjusts previously broadcasted iterators so that the axis with

Callers 7

PyArray_ByteswapFunction · 0.85
_new_sortlikeFunction · 0.85
_new_argsortlikeFunction · 0.85
PyArray_LexSortFunction · 0.85
PyArray_MatrixProduct2Function · 0.85
pack_bitsFunction · 0.85
unpack_bitsFunction · 0.85

Calls 4

PyArray_IterNewFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_STRIDEFunction · 0.85
PyArray_DIMFunction · 0.85

Tested by

no test coverage detected