8000 API: Bump NPY_MAXDIMS to 64 and NPY_MAXARGS to 128 by seberg · Pull Request #24072 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Bump NPY_MAXDIMS to 64 and NPY_MAXARGS to 128 #24072

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

Closed
wants to merge 3 commits into from

Conversation

seberg
Copy link
Member
@seberg seberg commented Jun 28, 2023

Both come up often enough, there was once a PR to bump NPY_MAXARGS to 256, but right now I thought, maybe try this and someone else can bump it more ;). (of course bumping requires a major release, though).

This increases stack usage and the size of some objects (mainly iterators) of course, otherwise I don't really expect much of an impact, there are a couple of places where this type of arrays are fully zeroed out, but even the worst case should be a very small (few percent) slowdown.

Effect:

  • Downstream should be using this the same as we are: as stack space. So this increases their stack space, but otherwise does nothing (it is also increased if you run against NumPy 1.x).
  • In theory, downstream might be doing other things, these should lead to reasonable errors though (i.e. NumPy rejecting a 64 dimensional array when running with NumPy 1.x).
  • Worst case: A third party could use NPY_MAXDIMS in a struct in their headers. This would be problematic if their downstream compiles with NumPy 1.x still.

I think it is realistic that this does nothing except bumping the stack use a bit, although I guess it is not unlikely that some downstream libs may not support 64 dims right away.

(I wouldn't mind adjusting some of the places where these are used to use alloca, e.g. in ufuncs we almost always have 2, but always have huge working stack area).


The discussion then suggested 256, and this was the old PR: #4840

I am not sure, for MAXDIMs, removing the limit entirely is hard, for MAXARGS, it seems like much more to do than back in the day, but at least for the iterator probably not so bad. I.e. it would be nice to not have MAXARGS at all (or maybe have it, but only to switch between stack allocation and malloc.

Until then, does just bumping seem good, should we go with 256. I honestly have no opinion, I did this first remembering it was higher, then saw they suggested 256...

@seberg
Copy link
Member Author
seberg commented Jun 28, 2023

Ah, I forgot the worst case initially. Added to the release notes also, but if a downstream library uses NPY_MAXDIMS in its public headers, the library and its users could end up compiling with a different NumPy version. Such a library would have to hardcode the old value, or find a transition way/force downstream to recompile.

However, I could only see a few usages of NPY_MAXDIMS in headers and they didn't look like public headers.

@mattip
Copy link
Member
mattip commented Jun 29, 2023

If we are already touching this, I would be in favor of removing the use of a fixed size altogether. The only places we really need this constant are when allocating a temporary buffer for some calculations on the strides. Currently this is a static allocation on the stack, it could be done dynamically instead. In __new__ we know the size we need to allocate so we could just allocate what we need.

@mattip
Copy link
Member
mattip commented Jun 29, 2023

Maybe there should be some artificial upper limit so people do not do crazy things, say 1024.

@seberg
Copy link
Member Author
seberg commented Jun 29, 2023

I don't disagree, but don't really want to dive into it right now. I would just remove the NPY_MAXARGS bump, and limit to maxdims then.

Something the old PR fails to mention, though: This breaks iteration ABI, the legacy iterate has to stay limited to 32 dims (which will affect some functions).

@seberg
Copy link
Member Author
seberg commented Jun 29, 2023

Going to just close this for now. Maybe the solution is to just remove both NPY_MAXDIMS entirely (and introduce a new one for the public header usages that have to remain ABI stable). Although I wouldn't mind just bumping NPY_MAXDIMS and keep using it, since there is a lot of MAXDIMS and less MAXARGS.
(I still think the two might be mixed up in a place or two, but don't want to worry about it)

@seberg seberg closed this Jun 29, 2023
@rgommers
Copy link
Member

Cross-linking to #5744; this topic was moved forward for NumPy 2.0.

@seberg seberg deleted the maxargs branch December 18, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants
0