Implement Standard and Uniform for Wrapping<T>#436
Merged
Conversation
Member
|
Okay, I get the motivation for implementing @vks want to review? |
Contributor
Author
|
Yes, I don't mind if this PR remains open for a while. But the commit that
moves the bound checks would be good to get in, as it adds an additional
requirement for implementers. Shall I split it out?
|
dhardy
reviewed
May 10, 2018
dhardy
left a comment
Member
There was a problem hiding this comment.
The first four commits are fine; you could repost the last commit (or two if prefered) in another PR if you like.
Shame the wrapping impl needs a lot more code.
| } | ||
| } | ||
|
|
||
| impl<T> Distribution<Wrapping<T>> for Standard where Standard: Distribution<T> { |
| // calculations at compile-time. | ||
| fn new(low: Self::X, high: Self::X) -> Self { | ||
| assert!(low < high, | ||
| "Uniform::new_inclusive called with `low >= high`"); |
Contributor
Author
|
Removed the last commit, and edited two others as you commented on. The commit implementing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This turned out to be a bit messier than I hoped...
The range checks are now moved to the
UniformSamplerimplementations, as discussed in #433 (comment).For wrapping types I wanted to have the range wrap around if
low > high. This turned out to need a slightly different way to calculate the range and zone. Because it is simpler, I also adjusted the normal integer implementation.I tried to share the code between
UniformIntandUniformWrapping, but didn't find a nice way. One option is to abstract things away into another trait (pitdicker@6c21536), which is ugly. Implementing it directly by changing the macro was also not easy, because of the converting back-and-forth toWrappingtypes. So the code is now just mostly duplicated.Fixes #168.