-
-
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
keys(::Generator) for find* and arg* #34674
Comments
If you have a specific code change suggestion, why don't you go directly to PR? |
Well, I didn't expect such a far-reaching change to go without discussion. But I can open a PR aswell. |
This is maybe ok, but what I would want |
So, to get it right, that's the actual proposal right now (?):
arg* will consistently return only the 2nd argument: Thus: """
argmax(f, iter)
returns the element of `iter` which maximizes `f`. No `keys(iter)` required.
argmax(iter)
returns the key which is associated with the largest value. Requires `keys(iter)` to be defined.
""" Even though that shift of index-level feels confusing at the first moment and not consistent between 1- and 2-arg version it is the right way IMO: The 2-arg version is the natural definition from mathematics. Take that as given. The 1-arg version by itself doesn't make much sense because it is just an iterable of values. Thus, we try to fill in the best meaning we can come up with for the 1-arg version.
|
I think another way to look at is that we have two kinds of methods argmax(f, domain)
argmax(f) where the second kind of method (including
By the way, it would be nice to extend this to |
I just realized what I wrote is not really solving the issue of I think it's much more straight forward to convince people for supporting |
Bump: While in general We may also consider adding |
Yes I think so; it's like the difference between |
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 <[email protected]> Co-authored-by: Takafumi Arakaki <[email protected]>
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 <[email protected]> Co-authored-by: Takafumi Arakaki <[email protected]>
Tl;Dr:
Add
to Base.
Partially related to my comment in #34368 (comment) regarding the support of traits on generators.
Currently there is no way to use find* on generators. Reason is that there is no keys function:
But since generators are said to be the lazy variant of
map
andmap
preserves the indices it would be good to define that missingkeys
method.That would allow for some very generic
findmax(iter)
andargmax(iter)
as arbitrary lazy maps are allowed while maintaining good performance and low memory footprint.Edit: adding the missing find* and arg* with custom transform functions would be appreciated aswell to allow for the convenient do-block notation.
The text was updated successfully, but these errors were encountered: