-
-
Notifications
You must be signed in to change notification settings - Fork 11k
median() is slower than partition(..., n//2)[n//2] #18298
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
|
Fair point, but I'd guess partitioning two elements should not take more than twice the time it takes to partition just one element(?), and the overhead is much more than twofold for small arrays. |
Yah, sorry, I guess your focus was really the overheads. There are many reasons for the fairly large overheads, the main one: One thing, I have been looking at (by now, I am mostly interested in it because it caused me to cleanup ufunc code in the process to be honest), is to generally reduce overheads of some functions ( Another big thing might be to speed up More limited to
Median is a bit of a complex beast, so not sure how easy these are. |
For arrays up to ~1e6 elements, calling median() is slower that calling partition(..., n//2) followed by getting the (n//2)th element. In fact, there seems to be so much overhead in median() that it's even slower than sorting the whole array and getting the (n//2)th element for arrays up to ~1e3 elements.
Reproducing code example:
(I cheated a bit and only test odd-size arrays here, but for even-size arrays, the overhead for partition() would be no more than ~1.5x (partition to get the (n//2)th element and then the min of all elements above that to get the (n//2+1)th.)
NumPy/Python version information:
The text was updated successfully, but these errors were encountered: