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

define keys for Base.Generator #35151

Closed
wants to merge 2 commits into from
Closed

define keys for Base.Generator #35151

wants to merge 2 commits into from

Conversation

KlausC
Copy link
Contributor

@KlausC KlausC commented Mar 18, 2020

IMO findmin(sin(x) for x in 0:10) should return same as findmin([sin(x) for x in 0:10]),
without allocating. Currently the first call throws a MethodError.

This PR inserts key(::Base.Generator) in order to achieve that.
As a consequence also pairs(::Generator), findmin(::Genearator), findmax(::Generator) are working as expected.

julia> @btime findmin(sin(x) for x = 1:10^6)
  21.901 ms (0 allocations: 0 bytes)
(-0.9999999999848337, 52174)

julia> @btime findmin([sin(x) for x = 1:10^6])
  25.945 ms (2 allocations: 7.63 MiB)
(-0.9999999999848337, 52174)

@fredrikekre
Copy link
Member

See #34678 (which actually has another definition of keys(::Generator)).

@KlausC
Copy link
Contributor Author

KlausC commented Mar 18, 2020

I retire this one in favour of #34678 . Sorry for the inconvenience.

@KlausC KlausC closed this Mar 18, 2020
@KlausC KlausC deleted the krc/generatorkeys branch March 19, 2020 09:32
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.

2 participants