NUMPY_API * Builds a set of strides which are the same as the strides of an * output array created using the NPY_ITER_ALLOCATE flag, where NULL * was passed for op_axes. This is for data packed contiguously, * but not necessarily in C or Fortran order. This should be used * together with NpyIter_GetShape and NpyIter_GetNDim. * * A use case for this function is to match the shape and layout
| 1036 | * Returns NPY_SUCCEED or NPY_FAIL. |
| 1037 | */ |
| 1038 | NPY_NO_EXPORT int |
| 1039 | NpyIter_CreateCompatibleStrides(NpyIter *iter, |
| 1040 | npy_intp itemsize, npy_intp *outstrides) |
| 1041 | { |
| 1042 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 1043 | int idim, ndim = NIT_NDIM(iter); |
| 1044 | int nop = NIT_NOP(iter); |
| 1045 | |
| 1046 | npy_intp sizeof_axisdata; |
| 1047 | NpyIter_AxisData *axisdata; |
| 1048 | npy_int8 *perm; |
| 1049 | |
| 1050 | if (!(itflags&NPY_ITFLAG_HASMULTIINDEX)) { |
| 1051 | PyErr_SetString(PyExc_RuntimeError, |
| 1052 | "Iterator CreateCompatibleStrides may only be called " |
| 1053 | "if a multi-index is being tracked"); |
| 1054 | return NPY_FAIL; |
| 1055 | } |
| 1056 | |
| 1057 | axisdata = NIT_AXISDATA(iter); |
| 1058 | sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop); |
| 1059 | |
| 1060 | perm = NIT_PERM(iter); |
| 1061 | for(idim = 0; idim < ndim; ++idim) { |
| 1062 | npy_bool flipped; |
| 1063 | npy_int8 axis = npyiter_undo_iter_axis_perm(idim, ndim, perm, &flipped); |
| 1064 | if (flipped) { |
| 1065 | PyErr_SetString(PyExc_RuntimeError, |
| 1066 | "Iterator CreateCompatibleStrides may only be called " |
| 1067 | "if DONT_NEGATE_STRIDES was used to prevent reverse " |
| 1068 | "iteration of an axis"); |
| 1069 | return NPY_FAIL; |
| 1070 | } |
| 1071 | else { |
| 1072 | outstrides[axis] = itemsize; |
| 1073 | } |
| 1074 | |
| 1075 | itemsize *= NAD_SHAPE(axisdata); |
| 1076 | NIT_ADVANCE_AXISDATA(axisdata, 1); |
| 1077 | } |
| 1078 | |
| 1079 | return NPY_SUCCEED; |
| 1080 | } |
| 1081 | |
| 1082 | /*NUMPY_API |
| 1083 | * Get the array of data pointers (1 per object being iterated) |
no test coverage detected