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

Function NpyIter_GetAxisStrideArray

numpy/core/src/multiarray/nditer_api.c:1293–1328  ·  view source on GitHub ↗

NUMPY_API * Gets the array of strides for the specified axis. * If the iterator is tracking a multi-index, gets the strides * for the axis specified, otherwise gets the strides for * the iteration axis as Fortran order (fastest-changing axis first). * * Returns NULL if an error occurs. */

Source from the content-addressed store, hash-verified

1291 * Returns NULL if an error occurs.
1292 */
1293NPY_NO_EXPORT npy_intp *
1294NpyIter_GetAxisStrideArray(NpyIter *iter, int axis)
1295{
1296 npy_uint32 itflags = NIT_ITFLAGS(iter);
1297 int idim, ndim = NIT_NDIM(iter);
1298 int nop = NIT_NOP(iter);
1299
1300 npy_int8 *perm = NIT_PERM(iter);
1301 NpyIter_AxisData *axisdata = NIT_AXISDATA(iter);
1302 npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
1303
1304 if (axis < 0 || axis >= ndim) {
1305 PyErr_SetString(PyExc_ValueError,
1306 "axis out of bounds in iterator GetStrideAxisArray");
1307 return NULL;
1308 }
1309
1310 if (itflags&NPY_ITFLAG_HASMULTIINDEX) {
1311 /* Reverse axis, since the iterator treats them that way */
1312 axis = ndim-1-axis;
1313
1314 /* First find the axis in question */
1315 for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) {
1316 if (perm[idim] == axis || -1 - perm[idim] == axis) {
1317 return NAD_STRIDES(axisdata);
1318 }
1319 }
1320 }
1321 else {
1322 return NAD_STRIDES(NIT_INDEX_AXISDATA(axisdata, axis));
1323 }
1324
1325 PyErr_SetString(PyExc_RuntimeError,
1326 "internal error in iterator perm");
1327 return NULL;
1328}
1329
1330/*NUMPY_API
1331 * Get an array of strides which are fixed. Any strides which may

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected