8000 ENH: increase NPY_MAXARGS to 256 by juliantaylor · Pull Request #4840 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: increase NPY_MAXARGS to 256 #4840

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 2 commits into from

Conversation

juliantaylor
Copy link
Contributor

Allows larger numbers of arguments for nditer using functions. This can
be helpful for complex boolean expressions used in pytables.
Closes gh-4398

Allows larger numbers of arguments for nditer using functions. This can
be helpful for complex boolean expressions used in pytables.
Closes numpygh-4398
@juliantaylor
Copy link
Contributor Author

some functions use MAXARGS * MAXDIMS sized arrays so their stack usage increases by 8, but it should still be below 100kb which is probably still ok.
though we could replace those with heap allocations now that we have a optimized small memory allocator.

@juliantaylor
Copy link
Contributor Author

this increases the size of the PyArrayMultiIterObject which is public, luckily the structure using this size is at the end of the object so it should be abi compatible
we should probably move these objects into private space and deprecate direct access, I recall we had similar issues with the indexing rewrite

@njsmith
Copy link
Member
njsmith commented Jul 5, 2014

+1 for master.

For 1.9, how confident are we that this won't create new ABI breakage? If it's risky then we might want to wait until 1.10 rather than risk new breakage in beta2.

@juliantaylor
Copy link
Contributor Author

originally we wanted to put that into 1.8.1 but deemed it to risky. Unfortunately we forgot to add it to master earlier.
we already need a new beta for the indexing, so I don't think adding it to 1.9b2 should be a big issue.
The only way I see this causing issues if third party headers make use of this value in their public objects in a way that changing it breaks their abi. But if that is a problem we can't make this change at all.

@seberg
Copy link
Member
seberg commented Jul 5, 2014

Biggest worry I would have is some code snipplet accidentally assuming MAXARGS == MAXDIMS

@charris
Copy link
Member
charris commented Jul 10, 2014

@juliantaylor I'm going to put this in. Do you intend this for 1.9? If not the mention in the release notes should be omitted.

@juliantaylor
Copy link
Contributor Author

if you ask me its either put it into 1.9 or don't do it at all.
for 1.10 we could rewrite the iterator to not have any restriction at all.

@charris
Copy link
Member
charris commented Jul 10, 2014

I'd rather have it in 1.10 than 1.9 at this point. The question is whether the iterator will get rewritten. IIRC, @mwiebe had some comments about this in the misty past.

@juliantaylor
Copy link
Contributor Author

its not a large rewrite, just grepping for all occurences of MAXARGS and replacing it with a heap allocation, should be pretty simple

@charris
Copy link
Member
charris commented Jul 10, 2014

That sounds like the best solution then.

@juliantaylor
Copy link
Contributor Author

alright, I guess pandas worked around this a long time ago anyway

@juliantaylor
Copy link
Contributor Author

can we use variable sized C arrays in numpy now?
would simplify some parts of the rewrite.
the feature has been around for almost 25 years after all

@njsmith
Copy link
Member
njsmith commented Jul 10, 2014

You mean VLAs? Those are a C99 feature and MSVC hates C99...

On Thu, Jul 10, 2014 at 11:46 PM, Julian Taylor notifications@github.com
wrote:

can we use variable sized C arrays in numpy now?
would simplify some parts of the rewrite.
the feature has been around for almost 25 years after all


Reply to this email directly or view it on GitHub
#4840 (comment).

Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org

@juliantaylor
Copy link
Contributor Author

seems msvc still doesn't have them, so heap memory it is ...

@juliantaylor
Copy link
Contributor Author

this is how this would look like: https://github.com/juliantaylor/numpy/tree/no-max-args
kind of ugly without vlas, especially in the iterator parts that do not have the gil and thus a malloc is too expensive, luckily there seems to be only one of these.

how about having no limitation if your compiler doesn't suck? that would be really simple to do, just replace NPY_MAXARGS with NPY_NOP_VAR(name) which evaluates to 32 when compiled with msvc in most places, then we just need to replace the > MAXARGS checks with some large value to prevent stack smashing.

@charris
Copy link
Member
charris commented Jul 12, 2014

What does NPY_NOP_VAR do? It sounds like you aren't to happy with the heap version -- which would be easier to review if you made an actual PR ;) -- so what is your preference? It's a shame about vlas, GCC used to have those many years before C99, then dropped them. IIRC, the generated asm did not look that complicated.

@juliantaylor
Copy link
Contributor Author

gcc never dropped vlas
NPY_NOP_VAR would just be array[if no-vla: 32 else nop]

@njsmith
Copy link
Member
njsmith commented Jul 12, 2014

Would alloca or some tiny helper functions help here? Or even tmalloc, for
that matter?
On 13 Jul 2014 00:22, "Julian Taylor" notifications@github.com wrote:

gcc never dropped vlas
NPY_NOP_VAR would just be array[if no-bla: 32 else nop]


Reply to this email directly or view it on GitHub
#4840 (comment).

@juliantaylor
8000
Copy link
Contributor Author

clang doesn't implement alloca, for good reason, its very dangerous to use and vla's have obsoleted most usecases of it.

@charris
Copy link
Member
charris commented Jul 13, 2014

gcc never dropped vlas

I remember using them back in the 80's or there abouts, and at some point, maybe after C89, the same code gave a compilation error. VLAs were certainly not part of any C spec at that point but as a newcomer from Fortran I appreciated them.

@charris
Copy link
Member
charris commented Jul 14, 2014

But to as to the suggestion to make use of VLAs, that sounds like a clean way to do things. It looks like gcc, clang, and icc support them and msvc will be no worse than before.

@njsmith
Copy link
Member
njsmith commented Jul 14, 2014

I guess I'm a little wary about whether supporting extra arguments but only
on some platforms is actually useful to users, or if we're just another
portability trap we're adding. (Remembering that most projects test only on
non-windows etc.) Msvc's non-support of vlas is effectively permanent from
our point of view (even if they add support now it's no use to us), so this
isn't just a temporary thing either.
On 14 Jul 2014 05:26, "Charles Harris" notifications@github.com wrote:

But to as to the suggestion to make use of VLAs, that sounds like a clean
way to do things. It looks like gcc, clang, and icc support them and msvc
will be no worse than before.


Reply to this email directly or view it on GitHub
#4840 (comment).

@charris
Copy link
Member
charris commented Jul 14, 2014

@njsmith My thinking is that common numpy distributions will use gcc or intel, and the wheels on pypi will also be built with gcc. I also suspect that msvc will support them sometime in the next couple of years, protests to the contrary, so the problem will eventually be solved by the passage of time. Vlas are, I think, cleaner than malloc for this use, and if the vlas allow for adjustable size on the fly that would be a plus when there are small numbers of dimensions. That said, I don't know exactly how Julian intends to use them and we could just put this PR in as an alternative.

@njsmith
Copy link
Member
njsmith commented Jul 14, 2014

It doesn't matter if msvc adds a feature tomorrow, we're still stuck
supporting VS 2008 until we drop 2.7 support, and VS 2010 until we drop 3.4
:-(. Unless we drop msvc support entirely and standardize on mingw, I
guess, which isn't obviously a terrible plan and might be a good one.
Though would take a lot of work to push through even if it is a good plan.

On Mon, Jul 14, 2014 at 5:51 AM, Charles Harris notifications@github.com
wrote:

@njsmith https://github.com/njsmith My thinking is that common numpy
distributions will use gcc or intel, and the wheels on pypi will also be
built with gcc. I also suspect that msvc will support them sometime in the
next couple of years, protests to the contrary, so the problem will
eventually be solved by the passage of time. Vlas are, I think, cleaner
than malloc for this use, and if the vlas allow for adjustable size on the
fly that would be a plus when there are small numbers of dimensions. That
said, I don't know exactly how Julian intends to use them and we could just
put this PR in as an alternative.


Reply to this email directly or view it on GitHub
#4840 (comment).

Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org

@rgommers
Copy link
Member

2010 support we don't have to drop, it's already broken. But why might dropping MSVC be a good idea? I'm not a Windows user, but my impression is that MSVC is more popular than gcc on Windows.

@charris
Copy link
Member
charris commented Jul 14, 2014

@rgommers msvc would work just fine, but the maximum number of arguments would be limited to the current 32. I think that would affect a small number of people, and they would have a fallback it they needed more arguments.

@rgommers
Copy link
Member

yeah, I got that from the discussion. which is why I wondered who benefits from entirely dropping MSVC users (except us, because of slightly less maintenance work).

@charris
Copy link
Member
charris commented Jul 14, 2014

@rgommers I don't understand what you mean by dropping msvc users.

@juliantaylor
Copy link
Contributor Author

fwiw the branch I posted which would also work with msvc is already almost all you need for more nditer args missing is only more ufunc args but I don't think that is as important. But there is just a bug somewhere which is only triggered for large amounts of arguments, probably some typo in my attempt at avoiding too many mallocs. I haven't spent much time debugging it yet but if someone sees the issue let me know and I might finish it up.

< 9E88 /include-fragment>
@rgommers
Copy link
Member

@charris I was responding to the comment right above from Nathaniel:

Unless we drop msvc support entirely and standardize on mingw, I guess, 
which isn't obviously a *terrible* plan and *might* be a good one.

(and typo, "users" --> "support")

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.

Increase NPY_MAXARGS to more than 32
5 participants
0