-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: reduce the overhead of the checks in the multinomial function #20636
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
Comments
Saving a click: this microbenchmark
gives these results:
The commit was part of the enormous PR #13163 to integrate randomgen into numpy. |
A very good and extensive analysis of the overhead is given by in the linked StackOverflow post linked to above, the analysis points to this line in Line 4249 in 7acb0fd
and this line as responsible for 20% more Line 4278 in 7acb0fd
The analysis also points out that calling multinomial 1,000,000 times for a single value in a tight loop is not a good design pattern. |
Changing the code to use the new Generator
produces the same result since the similar code exists in We could refactor |
The numpy/numpy/random/_common.pyx Lines 400 to 402 in 01079e2
I suspect the |
Remove python api calls from check_constraint xref numpy#20636
Fixing the performance of the array checker in a tidy manner is a lot harder since the type of the array being checked is not always the same, and so would need paths for different possible types. |
Just installed the latest numpy and it works like a charm, thank you all for the fix and the unexpected fast turnaround, really impressed! |
Closing since we improved what we can. @zephyr111 please open a new issue or reopen this one if you have an idea for more preformance improvements. |
Uh oh!
There was an error while loading. Please reload this page.
Proposed new feature or change:
Hello,
We have discovered a performance regression of the
numpy.random.multinomial
function for small arrays apparently caused by the commit 0f3dd06 which add new checks. The checks are expensive regarding their purpose (especially for small arrays). This can be reproduced with Python 3.9.9 on a x86-64 machine using both Windows and Linux. Is there a way to reduce the overhead of such checks?For more information, please read this Stack-Overflow post.
Thank you.
The text was updated successfully, but these errors were encountered: