* Replaces the AXISDATA for the iop'th operand, broadcasting * the dimensions as necessary. Assumes the replacement array is * exactly the same shape as the original array used when * npy_fill_axisdata was called. * * If op_axes is not NULL, it should point to an ndim-sized * array. */
| 1941 | * array. |
| 1942 | */ |
| 1943 | static void |
| 1944 | npyiter_replace_axisdata( |
| 1945 | NpyIter *iter, int iop, PyArrayObject *op, |
| 1946 | int orig_op_ndim, const int *op_axes) |
| 1947 | { |
| 1948 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 1949 | int idim, ndim = NIT_NDIM(iter); |
| 1950 | int nop = NIT_NOP(iter); |
| 1951 | char *op_dataptr = PyArray_DATA(op); |
| 1952 | |
| 1953 | NpyIter_AxisData *axisdata0, *axisdata; |
| 1954 | npy_intp sizeof_axisdata; |
| 1955 | npy_int8 *perm; |
| 1956 | npy_intp baseoffset = 0; |
| 1957 | |
| 1958 | perm = NIT_PERM(iter); |
| 1959 | axisdata0 = NIT_AXISDATA(iter); |
| 1960 | sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop); |
| 1961 | |
| 1962 | /* |
| 1963 | * Replace just the strides which were non-zero, and compute |
| 1964 | * the base data address. |
| 1965 | */ |
| 1966 | axisdata = axisdata0; |
| 1967 | |
| 1968 | if (op_axes != NULL) { |
| 1969 | for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) { |
| 1970 | int i; |
| 1971 | npy_bool axis_flipped; |
| 1972 | npy_intp shape; |
| 1973 | |
| 1974 | /* Apply perm to get the original axis, and check if its flipped */ |
| 1975 | i = npyiter_undo_iter_axis_perm(idim, ndim, perm, &axis_flipped); |
| 1976 | |
| 1977 | i = npyiter_get_op_axis(op_axes[i], NULL); |
| 1978 | assert(i < orig_op_ndim); |
| 1979 | if (i >= 0) { |
| 1980 | shape = PyArray_DIM(op, i); |
| 1981 | if (shape != 1) { |
| 1982 | npy_intp stride = PyArray_STRIDE(op, i); |
| 1983 | if (axis_flipped) { |
| 1984 | NAD_STRIDES(axisdata)[iop] = -stride; |
| 1985 | baseoffset += stride*(shape-1); |
| 1986 | } |
| 1987 | else { |
| 1988 | NAD_STRIDES(axisdata)[iop] = stride; |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | else { |
| 1995 | for (idim = 0; idim < ndim; ++idim, NIT_ADVANCE_AXISDATA(axisdata, 1)) { |
| 1996 | int i; |
| 1997 | npy_bool axis_flipped; |
| 1998 | npy_intp shape; |
| 1999 | |
| 2000 | i = npyiter_undo_iter_axis_perm( |
no test coverage detected