On Fri, Aug 18, 2023 at 4:59 AM Ronald van Elburg <r.a.j.van.elburg@hetnet.nl> wrote:
I was trying to get a feel for how often the work around occurs. I found three clear examples in Scipy and one unclear case. One case in holoviews. Two in numpy. One from soundappraisal's code base.

See also my comment from back in 2020: https://github.com/numpy/numpy/pull/14542#issuecomment-586494608

Anyone interested in this enhancement is encouraged to review the discussion in that pull request (https://github.com/numpy/numpy/pull/14542), and an earlier issue from 2015: https://github.com/numpy/numpy/issues/6044


Next to prepending to the output, I also see prepending to the input as a workaround.

Some examples of workarounds:

scipy: (prepending to the output)


    row_offsets = np.append(0, np.cumsum(brow_lengths))
    col_offsets = np.append(0, np.cumsum(bcol_lengths))


    indptr = np.zeros(num_cols + 1, dtype=idx_dtype)
    indptr[1:offset_len+1] = np.cumsum(mask.sum(axis=0))


    indptr = np.zeros(N + 1, dtype=ITYPE)
    indptr[1:] = mask.sum(1).cumsum()

    Not sure whether this is also an example:

        # Now fill in the values. We cannot use cumsum, unfortunately.
        val = 0.0 if minj == 0 else 1.0
        for jj in range(maxj - minj):
            j = jj + minj
            val = (A[jj + minj - lastminj] * i + val * j) / (i + j)
            A[jj] = val

holoviews: (prepending to the input)

    # We add a zero in the begging for the cumulative sum
    points = np.zeros((areas_in_radians.shape[0] + 1))
    points[1:] = areas_in_radians
    points = points.cumsum()

numpy (prepending to the input):

    numpy/numpy/lib/_iotools.py :

    idx = np.cumsum([0] + list(delimiter))


    cw = np.concatenate((zero, sw.cumsum()))

soundappraisal own code: (prepending to the output)

    def get_cumulativepixelareas(whiteboard):
        whiteboard['cumulativepixelareas'] = \
                np.concatenate((np.array([0, ]), np.cumsum(whiteboard['pixelareas'])))
        return True
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-leave@python.org
Member address: warren.weckesser@gmail.com