Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upcast unsigned integer dtypes in cumsum and cumprod #9594

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

peterzsohar
Copy link

@peterzsohar peterzsohar commented May 28, 2024

This PR is a very basic attempt to deal with the following issue (example in #9592 ):

The cumsum and cumprod array methods only partially follow the numpy implementation.
They upcast signed integer and boolean dtypes but not unsigned integer dtypes.
This is in contrast to the current numpy and previous numba behavior. (Pre 0.57 it worked correctly but then numpy functions/methods were refactored to use overloads.)

To embrace ,,Numba tries to bug-for-bug replicate NumPy'' (source) I propose to use np.int_ and np.uint for the return dtype because that seems to be consistent with np.cumsum and np.cumprod behavior on all platforms.

I added a test case (for both signed and unsigned integers) that would catch overflown results with both cumsum and cumprod.

Close #9592

@sklam sklam added the NumPy 2.0 Related to NumPy 2.0 support label May 28, 2024
@sklam sklam added this to the 0.61.0-rc1 milestone May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NumPy 2.0 Related to NumPy 2.0 support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cumprod method doesn't upcast unsigned integer array
2 participants