8000 PoC: Try 0d preservation by seberg · Pull Request #52 · seberg/numpy · GitHub
[go: up one dir, main page]

Skip to content

PoC: Try 0d preservation #52

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

PoC: Try 0d preservation #52

wants to merge 8 commits into from

Conversation

seberg
Copy link
Owner
@seberg seberg commented May 12, 2025

Implements an older PoC to try preserving scalars in NumPy. It doesn't pass all tests, but it passes most (the test failures remaining are mostly bug-fixes around object arrays, but...).

This is in response to scientific-python/summit-2025#38. Since the change to NumPy (for the first part here!) isn't the blocker for a while now IMO, the blocker is to properly assess downstream impact.
(That was of course not always the case, there are many fixes in the past 2 years that enabled this.)


The simple rule is, if any input is already an array, the output should also be an array.
The one extension is that axis=None for reductions should return scalars. Some may argue that last rule, but None is special enough, and it doesn't even matter if you like it or not, because the main point is that arr.sum() won't change behavior.
(Gufuncs that remove axes will effectively always return arrays here, which may not always be desired.)


It also adds a last commit to enable NUMPY_DISLIKE_SCALARS=1, if set, NumPy will never return scalars (this is probably even true for a lot of scalar math, so that is a problem).
To be clear, while I am happy to agree that anything makes sense to try. I don't believe in this being feasible.

Since that doesn't work at all, it adds an arr.to_scalar() method, that does the same as arr[()] did previously.

seberg added 8 commits May 11, 2025 15:51
Signed-off-by: Sebastian Berg <sebastianb@nvidia.com>
< 8000 svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-git-commit">
Many remaining ones are around object arrays returning arguably
better (less "NumPy") results, but probably not all :)
I don't believe in this (I mean as an option, I suppose who cares,
but that isn't actually useful if you can never transition, IMO).

But, it should be at least tried a bit, so...
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 this pull request may close these issues.

1 participant
0