-
Notifications
You must be signed in to change notification settings - Fork 52
RFC: add support for computing the element-wise minimum and maximum #667
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
@oleksandr-pavlyk commented: These can be implemented with So I measured it: >>> x = np.arange(100000)
>>> y = np.random.randint(0, 1000, size=100000)
>>> %timeit np.maximum(x, y)
91.1 µs ± 42.5 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
>>> %timeit np.where(x > y, x, y)
132 µs ± 180 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
>>> x = np.arange(100000).astype(np.float64)
>>> y = np.random.randint(0, 1000, size=100000).astype(np.float64)
>>> %timeit np.maximum(x, y)
93.2 µs ± 303 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
>>> %timeit np.where(x > y, x, y)
141 µs ± 194 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) Conclusions:
Based on the above, I am not convinced that it meets the bar for inclusion. On the other hand, these functions are used regularly and all libraries have an implementation, so perhaps it is simply convenient to include them anyway. Let's say I'm +0.5 for inclusion based on making the life of array-consuming library authors a bit easier. |
FWIW I get a 2x difference in your example and a 6x difference in NumPy if I make sure there is a 50% change of a flip each time (which, the way numpy operates, is a lot more work). The next thing is cache friendliness. The size above probably fits into L3 cache. Because if it doesn't (ignoring the boolean array itself), you have to 5 arrays vs. 3 arrays that need to go through memory, so a diffreence of ~1.66 is the best case (and likely) scenario usually. Maybe 1.7 best case is not much different from 40%, but... |
I think is a good idea, if only because |
Given the precedence we had regarding adding new APIs mainly/only for perf reasons, I am slightly inclined toward objection but not as strongly. I am more concerned about |
Being driven by the same concern as @leofang, I considered |
Discussed today: let's add these two functions under their current names,
|
This proposes adding support for computing the element-wise minimum and maximum values when provided two input arrays.
Overview
Based on API comparison data, maximum and minimum APIs are available in all array libraries. And each array library uses the same naming convention:
maximum
andminimum
.Prior art
maximum
minimum
Proposal
Note: as in the specified
min
andmax
, while conforming implementations may support complex number inputs, inequality comparisons of complex numbers is unspecified, and thus implementation-dependent.Questions
min
/minimum
andmax
/maximum
naming distinction clear enough, where the former are reductions and the latter are binary element-wise operations?Related
The text was updated successfully, but these errors were encountered: