-
Notifications
You must be signed in to change notification settings - Fork 432
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
Distribution::sample_iter changes #758
Conversation
It looks good. You might want It's not rand's job to teach people Rust of course, so this should not be over emphasized, but |
I added some little hints in the docs. |
The first example can be modified slightly:
The second caveat is that there is no The third caveat is the generic code which now doesn't know whether its internal RNG is a reference type, handle or full RNG, and thus must create a new reference to what may already be a reference. Quite likely the compiler can eliminate the double reference anyway, though it's hard to verify (was trying with godbolt.org but the whole usage was dead code; in practice it may depend on the usage). I'd like to accept this PR and make similar changes to Note that |
I tried adjusting fn sample<R: Rng>(&self, rng: R) -> T; First consequence: we have a lot of implementations of Second consequence: functions generic over any type of RNG and calling Third consequence: functions like The question then becomes: should we rely on the optimiser to avoid creating pointers to pointers unnecessarily? (Note this also applies the other way: currently Fourth consequence: lots of "use of moved value" errors within generic functions to solve by replacing To sum this up: I don't think we should do this without an addition to the language like Regarding fn sample_iter<'a, R>(self, rng: &'a mut R) -> DistIter<'a, Self, R, T>
where R: Rng + ?Sized, Self: Sized @huonw and @burdges may be interested to comment but I believe this analysis wraps up the issue for now. |
Right, fair enough. Could
It's rarely useful but occasionally someone might pass around an owned |
You mean such that |
Implements #602, #725. (In fact, the former makes the latter irrelevant.)
I am happy with the first commit (#725).
The second (#602) is a little controversial, and unfortunately does not match up with
fn sample
. See the comments.@fizyk20 @huonw @burdges review please?