-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
argmax should support generators #27612
Comments
What does argmax even mean for an unordered iterable collection like Set? |
That's a good point. When this function was called Actually, I just tried |
Looks like |
The following 1-liner is sufficient to implement this proposal: (edit: nope! Please read here instead) |
Maybe that's a bad idea, since Alternatively, one could have a specialized definition for |
|
Ok that was definitely madness. Sorry for the stream of consciousness (like watching a car crash in slow motion?). After sleeping on it, I think what is needed is this:
With this, we get a perfectly reasonable definition for Unlike before, this actually works on a slightly less trivial example such as This works because
yields
Returning to the question of "what does argmax even mean for an unordered iterable collection like Set?", I think ordering doesn't matter. Mathematically, argmax is defined on a set without any need for ordering, so I think my new proposed solution actually aligns quite well to the mathematical sense. |
Argmax isn’t normally defined on a set by itself, I thought? |
Sorry for the confusion. Assuming Edit: I have updated my first post above to clarify what I am proposing. I'm not trying to define |
This would also set things up perfectly for #27613, which is what originally led me to this. |
This is largely orthogonal #27613. |
I agree that defining argmax for generators makes sense, whereas defining it for arbitrary iterators does not make sense to me. |
As long as there is a key that corresponds to the element I think |
Agreed! Currently, the docs say |
The conclusion on the triage call is that |
Nicely put! It's clear now why |
Fixes JuliaLang#27613. Related: JuliaLang#27639, JuliaLang#27612, JuliaLang#34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR.
Fixes JuliaLang#27613. Related: JuliaLang#27639, JuliaLang#27612, JuliaLang#34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR.
Fixes JuliaLang#27613. Related: JuliaLang#27639, JuliaLang#27612, JuliaLang#34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR.
Fixes JuliaLang#27613. Related: JuliaLang#27639, JuliaLang#27612, JuliaLang#34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR.
Fixes JuliaLang#27613. Related: JuliaLang#27639, JuliaLang#27612, JuliaLang#34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR.
Defines a descending total order, `isgreater` (not exported), where unordered values like NaNs and missing are last. This makes defining min, argmin, etc, simpler and more consistent. Also adds 2-arg versions of findmax/min, argmax/min. Defines and exports the `isunordered` predicate for testing whether a value is unordered like NaN and missing. Fixes #27613. Related: #27639, #27612, #34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR. Co-authored-by: Jameson Nash <jameson@juliacomputing.com> Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
Defines a descending total order, `isgreater` (not exported), where unordered values like NaNs and missing are last. This makes defining min, argmin, etc, simpler and more consistent. Also adds 2-arg versions of findmax/min, argmax/min. Defines and exports the `isunordered` predicate for testing whether a value is unordered like NaN and missing. Fixes JuliaLang#27613. Related: JuliaLang#27639, JuliaLang#27612, JuliaLang#34674. Thanks to @tkf, @StefanKarpinski and @drewrobson for their assistance with this PR. Co-authored-by: Jameson Nash <jameson@juliacomputing.com> Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
I noticed that
maximum(i for i = 1:10)
works butargmax(i for i=1:10)
does not. This seems inconsistent.Edit: I am proposing that
argmax(f(x) for x ∈ itr)
should work and return anx
initr
that maximizesf(x)
, which is quite literally the mathematical definition of argmax. I have proposed a simple way to implement this here.(originally proposed here)
The text was updated successfully, but these errors were encountered: