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

Result of numpy.sum with float32 input is float64 #152

Closed
mdhaber opened this issue Jun 17, 2024 · 2 comments · Fixed by #166
Closed

Result of numpy.sum with float32 input is float64 #152

mdhaber opened this issue Jun 17, 2024 · 2 comments · Fixed by #166

Comments

@mdhaber
Copy link

mdhaber commented Jun 17, 2024

IIUC the standard states that input dtype is to be preserved for floating point types when dtype is unspecified.

dtype - data type of the returned array. If None, the returned array must have the same data type as x, unless x has an integer data type

However,

from array_api_compat import numpy as np
x = np.arange(10, dtype=np.float32)
np.sum(x).dtype  # dtype('float64')
@asmeurer
Copy link
Member

This is part of #127. This was changed in 2023.12. I don't see a need to keep the previously standardized behavior intact. Unfortunately, I haven't yet started work on updating array-api-compat for 2023.12, but I plan to start that work now.

@mdhaber
Copy link
Author

mdhaber commented Jun 24, 2024

Interesting. I didn't notice that the old standard required that the output dtype be the default floating point type. Glad that was changed!

lucascolley pushed a commit to scipy/scipy that referenced this issue Jul 15, 2024
…d='ebrahimi'` (#21194)

* TST: stats.differential_entropy: add dtype test

* MAINT: stats.differential_entropy: fix issue with integer input

* MAINT: stats.differential_entropy: prevent dtype changes due to data-apis/array-api-compat#152

* Apply suggestions from code review

[skip circle]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants