Skip to content
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

Add minmax and extrema #5275

Merged
merged 3 commits into from
Jan 2, 2014
Merged

Add minmax and extrema #5275

merged 3 commits into from
Jan 2, 2014

Conversation

lindahua
Copy link
Contributor

@lindahua lindahua commented Jan 1, 2014

Semantics:

extrema(x) = (minimum(x), maximum(x))
minmax(x, y) = (min(x, y), max(x, y))

Please let me know if there is any problem. I will add entries to helpdb & news.md after this is merged.

@lindahua
Copy link
Contributor Author

lindahua commented Jan 1, 2014

I would like this to be merged soon if there's no big issues.

@johnmyleswhite
Copy link
Member

+1

@nalimilan
Copy link
Member

Nice!

About the names, though: while it makes sense when you have understood the min/max vs. minimum/maximum naming convention, I don't find the extrema vs. minmax distinction terribly obvious at first sight. I'd support the use of a specific character to identify a function as element-wise, just like ! is used currently to mark functions modifying their inputs. Something like extrema() and extrema#(). (I think there are many cases where this rule could be useful.)

Or maybe just drop minmax()?

@lindahua
Copy link
Contributor Author

lindahua commented Jan 1, 2014

Here, minmax is only for two scalars. I did not add a vectorized version here, which I don't see as super necessary. A vectorized method for minmax can always be added later when we need it.

@johnmyleswhite
Copy link
Member

What's the use case for minmax?

@lindahua
Copy link
Contributor Author

lindahua commented Jan 2, 2014

minmax is sometimes used in geometric computation (e.g. aspect ratio or eccentricity) where you don't have prior knowledge as to which dimension is longer. It is often used in some internal implementation of math routines where you need to know the larger value and the smaller value. It is not used as frequently as min or max, it is quite handy sometimes.

@johnmyleswhite
Copy link
Member

Good enough for me. I'd say we should go ahead and merge this soon.

StefanKarpinski added a commit that referenced this pull request Jan 2, 2014
@StefanKarpinski StefanKarpinski merged commit 27c756c into JuliaLang:master Jan 2, 2014
@nalimilan
Copy link
Member

Ah, I missed the fact that minmax was only for two scalars. I guess there's less risk of confusion in that case. Though, why not extend extrema to take scalar varargs rather?

@lindahua
Copy link
Contributor Author

lindahua commented Jan 2, 2014

One of the key reason to motivate the use of extrema (instead of minmax) here is to use a different function name for reduction than that for binary operation, so as to avoid the confusion of min and max used to cause (that was why we finally decided to use minimum and maximum for reduction purpose, while keeping min and max as binary operations).

You may think about minmax and extrema as two functions for two different purposes. I don't think we need to use the same function name here.

@lindahua
Copy link
Contributor Author

lindahua commented Jan 2, 2014

There was a very long debate when we did the minimum/maximum business.

The general principle that we finally settled on is to use different function names for element-wise operations and reduction.

@nalimilan
Copy link
Member

Yeah. The difference here is that minmax only operates with scalars, so it's not element-wise. Anyway, not a big deal for me. I just wish we were able to find more explicit names...

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.

4 participants