* Fills in the AXISDATA for the 'nop' operands, broadcasting * the dimensionas as necessary. Also fills * in the ITERSIZE data member. * * If op_axes is not NULL, it should point to an array of ndim-sized * arrays, one for each op. * * Returns 1 on success, 0 on failure. */
| 1488 | * Returns 1 on success, 0 on failure. |
| 1489 | */ |
| 1490 | static int |
| 1491 | npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itflags, |
| 1492 | char **op_dataptr, |
| 1493 | const npy_uint32 *op_flags, int **op_axes, |
| 1494 | npy_intp const *itershape) |
| 1495 | { |
| 1496 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 1497 | int idim, ndim = NIT_NDIM(iter); |
| 1498 | int iop, nop = NIT_NOP(iter); |
| 1499 | int maskop = NIT_MASKOP(iter); |
| 1500 | |
| 1501 | int ondim; |
| 1502 | NpyIter_AxisData *axisdata; |
| 1503 | npy_intp sizeof_axisdata; |
| 1504 | PyArrayObject **op = NIT_OPERANDS(iter), *op_cur; |
| 1505 | npy_intp broadcast_shape[NPY_MAXDIMS]; |
| 1506 | |
| 1507 | /* First broadcast the shapes together */ |
| 1508 | if (itershape == NULL) { |
| 1509 | for (idim = 0; idim < ndim; ++idim) { |
| 1510 | broadcast_shape[idim] = 1; |
| 1511 | } |
| 1512 | } |
| 1513 | else { |
| 1514 | for (idim = 0; idim < ndim; ++idim) { |
| 1515 | broadcast_shape[idim] = itershape[idim]; |
| 1516 | /* Negative shape entries are deduced from the operands */ |
| 1517 | if (broadcast_shape[idim] < 0) { |
| 1518 | broadcast_shape[idim] = 1; |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | for (iop = 0; iop < nop; ++iop) { |
| 1523 | op_cur = op[iop]; |
| 1524 | if (op_cur != NULL) { |
| 1525 | npy_intp *shape = PyArray_DIMS(op_cur); |
| 1526 | ondim = PyArray_NDIM(op_cur); |
| 1527 | |
| 1528 | if (op_axes == NULL || op_axes[iop] == NULL) { |
| 1529 | /* |
| 1530 | * Possible if op_axes are being used, but |
| 1531 | * op_axes[iop] is NULL |
| 1532 | */ |
| 1533 | if (ondim > ndim) { |
| 1534 | PyErr_SetString(PyExc_ValueError, |
| 1535 | "input operand has more dimensions than allowed " |
| 1536 | "by the axis remapping"); |
| 1537 | return 0; |
| 1538 | } |
| 1539 | for (idim = 0; idim < ondim; ++idim) { |
| 1540 | npy_intp bshape = broadcast_shape[idim+ndim-ondim]; |
| 1541 | npy_intp op_shape = shape[idim]; |
| 1542 | |
| 1543 | if (bshape == 1) { |
| 1544 | broadcast_shape[idim+ndim-ondim] = op_shape; |
| 1545 | } |
| 1546 | else if (bshape != op_shape && op_shape != 1) { |
| 1547 | goto broadcast_error; |
no test coverage detected