-
-
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
enable rand(::Union{AbstractSet,Associative}) #22228
Conversation
test/random.jl
Outdated
Base.convert(::Type{$G}, s::$A) = $G(s) | ||
Base.done(s::$G, state) = done(s.s, state) | ||
Base.next(s::$G, state) = next(s.s, state) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent's off here
base/random.jl
Outdated
constant complexity) is available (which is the case for `Dict`, | ||
`Set` and `IntSet`). For more than a few calls, use `rand(rng, | ||
collect(s))` instead (or `rand(rng, Dict(s))`, or `rand(rng, | ||
Set(s))`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the frequent parentheticals are a bit distracting here, the "(which is the case for ...)" is the only one that wouldn't work fine as just a normal part of the sentence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually even that would be fine as part of the sentence, IMO.
The complexity of
rand(rng, s::Union{Associative,AbstractSet})
is linear in the length ofs
, unless an optimized method with constant complexity is available, which is the case forDict
,Set
, andIntSet
. For more than a few calls, userand(rng, collect(s))
instead, orrand(rng, Dict(s))
orrand(rng, Set(s))
as appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thank you both, I updated. I also put this note after the examples, which seem more important to me in most of the cases.
Looks like this needs a rebase but then should be good to go. |
0a7c8a3
to
53e6f69
Compare
@@ -11,6 +11,8 @@ test set that throws on the first failure. Users can choose to wrap | |||
their tests in (possibly nested) test sets that will store results | |||
and summarize them at the end of the test set with `@testset`. | |||
""" | |||
:Test # cf. #22288 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess this commit should be squashed then, on merge if not before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say all commits can be squashed on merge, and I can squash before if prefered.
This was previously implemented only for concrete types from base (i.e.
Set
,IntSet
,Dict
).WIP as I don't manage to put some method definitions ofcf. #22288.GenericSet
andGenericDict
in test.jl (so I put them in test/random.jl in the meantime), someone has an idea?