Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Stable summation method for cumsum (add.reduce) #14909

Copy link
Copy link
Open
@robparrishqc

Description

@robparrishqc
Issue body actions

numpy (superb library - no slight intended here!) does not seem to support Kahan or butterfly summation in cumsum, which is critically important for accuracy in large arrays of numbers of similar magnitude.

Reproducing code example:

import numpy as np; print(np.cumsum(np.ones((2**28,), dtype=np.float32))[-1] - 2**28)

import numpy as np
print(np.cumsum(np.ones((2**28,), dtype=np.float32))[-1] - 2**28)
# Should be zero

Note that sum obviously uses butterfly summation:

print(np.sum(np.ones((2**28,), dtype=np.float32)) - 2**28)
# Is zero on any machine I can find

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.