Skip to content

RFC: stop using scikit-learn stable_cumsum and instead use np/xp.cumsum directly #31533

@ogrisel

Description

@ogrisel

As discussed in https://github.com/scikit-learn/scikit-learn/pull/30878/files#r2142562746, our current stable_cumsum function brings very little value to the user: it does extra computation to check that np.allclose(np.sum(x), np.cumsum(x)[-1]) and raises a warning otherwise. However, in most cases, users can do nothing about the warning.

Furthermore, as seen in the CI of #30878, the array API compatible libraries we test against do not have the same numerical stability behavior for sum and cumsum, so it makes it challenging to write a test for the occurrence of this warning that is consistent across libraries.

So I would rather not waste the overhead of computing np.sum(x) and just always directly call np.cumsum or xp.cumsum and deprecate sklearn.utils.extmath.stable_cumsum.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions