NUMPY_API * Checks to see whether this is the first time the elements * of the specified reduction operand which the iterator points at are * being seen for the first time. The function returns * a reasonable answer for reduction operands and when buffering is * disabled. The answer may be incorrect for buffered non-reduction * operands. * * This function is intended to be used in EXTERNAL
| 781 | * the caller, and should be done outside of any inner loops. |
| 782 | */ |
| 783 | NPY_NO_EXPORT npy_bool |
| 784 | NpyIter_IsFirstVisit(NpyIter *iter, int iop) |
| 785 | { |
| 786 | npy_uint32 itflags = NIT_ITFLAGS(iter); |
| 787 | int idim, ndim = NIT_NDIM(iter); |
| 788 | int nop = NIT_NOP(iter); |
| 789 | |
| 790 | NpyIter_AxisData *axisdata; |
| 791 | npy_intp sizeof_axisdata; |
| 792 | |
| 793 | sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop); |
| 794 | axisdata = NIT_AXISDATA(iter); |
| 795 | |
| 796 | for (idim = 0; idim < ndim; ++idim) { |
| 797 | npy_intp coord = NAD_INDEX(axisdata); |
| 798 | npy_intp stride = NAD_STRIDES(axisdata)[iop]; |
| 799 | |
| 800 | /* |
| 801 | * If this is a reduction dimension and the coordinate |
| 802 | * is not at the start, it's definitely not the first visit |
| 803 | */ |
| 804 | if (stride == 0 && coord != 0) { |
| 805 | return 0; |
| 806 | } |
| 807 | |
| 808 | NIT_ADVANCE_AXISDATA(axisdata, 1); |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * In reduction buffering mode, there's a double loop being |
| 813 | * tracked in the buffer part of the iterator data structure. |
| 814 | * We only need to check the outer level of this two-level loop, |
| 815 | * because of the requirement that EXTERNAL_LOOP be enabled. |
| 816 | */ |
| 817 | if (itflags&NPY_ITFLAG_BUFFER) { |
| 818 | NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter); |
| 819 | /* The outer reduce loop */ |
| 820 | if (NBF_REDUCE_POS(bufferdata) != 0 && |
| 821 | NBF_REDUCE_OUTERSTRIDES(bufferdata)[iop] == 0) { |
| 822 | return 0; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | return 1; |
| 827 | } |
| 828 | |
| 829 | /*NUMPY_API |
| 830 | * Whether the iteration could be done with no buffering. |