Skip to content

Rename "range" to "uniform"#395

Merged
dhardy merged 7 commits intorust-random:masterfrom
vks:uniform
Apr 18, 2018
Merged

Rename "range" to "uniform"#395
dhardy merged 7 commits intorust-random:masterfrom
vks:uniform

Conversation

@vks
Copy link
Copy Markdown
Contributor

@vks vks commented Apr 12, 2018

  • gen_range was not changed.
  • The types are still available under their deprecated, old names.

Fixes #393.

@vks
Copy link
Copy Markdown
Contributor Author

vks commented Apr 12, 2018

I reexported Uniform as Range, but this was not done when Uniform was renamed to Standard. It is impossible to support both. Should I just remove the compatibility reexports?

@pitdicker
Copy link
Copy Markdown
Contributor

To be honest I feel like this PR is a bit premature, but I'm not really sure what to say. @dhardy, can I leave things to you 😄?

I believe if we want to have Uniform, it should purely be an addition. Uniform should be a wrapper around Range or visa versa.

I reexported Uniform as Range, but this was not done when Uniform was renamed to Standard. It is impossible to support both. Should I just remove the compatibility reexports?

We don't need compatibility reexports for the Uniform to Standard rename, because there never really was a release that included Uniform. But Range has been there for years.

@vks
Copy link
Copy Markdown
Contributor Author

vks commented Apr 12, 2018

I believe if we want to have Uniform, it should purely be an addition. Uniform should be a wrapper around Range or visa versa.

Why? They are basically the same. I could imagine to have type aliases.

We don't need compatibility reexports for the Uniform to Standard rename, because there never really was a release that included Uniform. But Range has been there for years.

👍

@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 15, 2018

I like the name Uniform a little more myself, but there doesn't seem to be an absolute answer.

Either way there are a few other changes in this PR we want (finishing the rename from Uniform → Standard).

Copy link
Copy Markdown
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some thinking about this change, it makes a lot of sense. We are emphasising how variables are sampled, not the domain in which they are sampled.

This also opens up some possible additional constructors like Uniform::default() and Uniform::full_range() — although the former is redundant with Standard and the latter doesn't make sense for floating-point types.

I think Standard still has an important role to play: it is simpler, thus easier to understand and probably faster to compile code using it. Also Standard uses no memory.

pub use self::other::Alphanumeric;
pub use self::range::Range;
pub use self::uniform::Uniform;
#[deprecated(since="0.5.0", note="use Distribution instead")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this say "use Uniform instead"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I fixed it.

pub use distributions::uniform::Uniform as Range;
pub use distributions::uniform::UniformInt as RangeInt;
pub use distributions::uniform::UniformFloat as RangeFloat;
pub use distributions::uniform::SampleUniform as SampleRange;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any point exporting the last three here because RangeInt and RangeFloat were never in a release and SampleRange is totally different.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about Range* and removed them. (I was not aware they were not released.)

However, what do you mean about SampleRange? It was public (although not supposed to be used), so removing is a breaking change, hence the deprecated reexport.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare the old and the new. But I guess usage as a bound (T: SampleRange) is not affected at least.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so you are saying it is a breaking change anyway? I still think it makes sense to have it deprecated for consistency. As you said, it might possibly keep some code working this way, but I suspect it was not used much.

@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 16, 2018

To be honest I feel like this PR is a bit premature

IMO it's much better to get this right now than after the 0.5 release.

I believe if we want to have Uniform, it should purely be an addition. Uniform should be a wrapper around Range or visa versa.

No, having two names for the same thing makes no sense IMO (except as deprecated re-export as in this PR).

@dhardy dhardy added E-question Participation: opinions wanted B-API Breakage: API T-distributions P-high Priority: high labels Apr 16, 2018
@dhardy dhardy mentioned this pull request Apr 16, 2018
Copy link
Copy Markdown
Contributor

@pitdicker pitdicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way there are a few other changes in this PR we want (finishing the rename from Uniform → Standard).

👍

After some thinking about this change, it makes a lot of sense. We are emphasising how variables are sampled, not the domain in which they are sampled.

Purely thinking within the domain it makes sense. As long as we keep the name Rng::gen_range, and don't purge the name "range" entirely from the documentation, I think it is ok.

I left some small notes on the documentation.

fn ind_sample<R: Rng>(&self, &mut R) -> Support;
}

/// DEPRECATED: Use `distributions::uniform` instead.
Copy link
Copy Markdown
Contributor

@pitdicker pitdicker Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (sorry): distributions::Uniform

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spelling is as intended, because it addresses the module and not the type.

/// Sample values uniformly between two bounds.
///
/// `Range::new` and `Range::new_inclusive` will set up a `Range`, which does
/// `Uniform::new` and `Uniform::new_inclusive` will set up a `Uniform`, which does
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this sentence read well any more, but have difficulty saying why.

Can you also mention "range" once in this description?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Perhaps something like U::new and U::new_inclusive construct a Uniform distribution sampling from the half-open and closed (inclusive) ranges respectively.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworded it.

/// repeatedly with the same arguments, one should use `Uniform`, as
/// that will amortize the computations that allow for perfect
/// uniformity, as they only happen when constructing the `Range`.
/// uniformity, as they only happen when constructing the `Uniform`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we mention "range" one or two times in this comment? I don't want to see no mention at all to this common term any more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already mentioned in the name and the fist sentence.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @pitdicker actually that a couple of things could be changed:

  • "wrapper around distributions::Uniform::sample_single"
  • "when constructing the Uniform range."

@vks
Copy link
Copy Markdown
Contributor Author

vks commented Apr 17, 2018

I will rebase after review is finished.

Copy link
Copy Markdown
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you pushed the From<ops::Range<X>> support into the same PR; I think we're all happy with that?

/// Implementation of `UniformImpl` for integer types.
///
/// Unless you are implementing `RangeImpl` for your own type, this type should
/// not be used directly, use `Range` instead.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to update the Range names

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is a left-over from the merge...

fn from(r: ::core::ops::Range<X>) -> Uniform<X> {
Uniform::new(r.start, r.end)
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And again

/// range `[low, high]` (inclusive). Panics if `low > high`.
pub fn new_inclusive(low: X, high: X) -> Uniform<X> {
assert!(low < high, "Uniform::new called with `low >= high`");
assert!(low <= high, "Uniform::new_inclusive called with `low > high`");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to solve #403. I looked over the code and don't see any issues with low == high.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. low == high is nonsensical, but not impossible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the trivial case, but but it is well-defined and supporting it might simplify more general code.

@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 17, 2018

Not sure why the comments from my previous review are "outdated"; there still appear to be some spurious uses of Range and RangeImpl in the doc.

@vks
Copy link
Copy Markdown
Contributor Author

vks commented Apr 17, 2018

I rebased on master.

@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 17, 2018

@vks could you fix the tests please?

@vks
Copy link
Copy Markdown
Contributor Author

vks commented Apr 17, 2018

Sorry again about that, something went wrong during the rebase (I already fixed those problems during the merge).

Fixed and rebased so the whole history passes the tests.

Copy link
Copy Markdown
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So other than a couple of very minor things I'm ready to see this merged. @pitdicker are you happy with it now?

/// sampling only a limited number of values from range. The default
/// implementation just sets up a range with `RangeImpl::new` and samples
/// Via this method, implementations can provide a method optimized for
/// sampling only a limited number of values from the range. The default
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should say "for sampling only a single value from the specified range", but not actually a problem with your PR.

/// repeatedly with the same arguments, one should use `Uniform`, as
/// that will amortize the computations that allow for perfect
/// uniformity, as they only happen when constructing the `Range`.
/// uniformity, as they only happen when constructing the `Uniform`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @pitdicker actually that a couple of things could be changed:

  • "wrapper around distributions::Uniform::sample_single"
  • "when constructing the Uniform range."

@pitdicker
Copy link
Copy Markdown
Contributor

@pitdicker are you happy with it now?

Yes, feel free to merge when ready 😄

@dhardy dhardy merged commit b418b61 into rust-random:master Apr 18, 2018
dhardy added a commit that referenced this pull request Apr 18, 2018
@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 18, 2018

Okay, I made the final doc changes myself.

@vks vks deleted the uniform branch April 18, 2018 16:20
@vks
Copy link
Copy Markdown
Contributor Author

vks commented Apr 18, 2018

Thanks!

@dhardy dhardy mentioned this pull request May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-API Breakage: API E-question Participation: opinions wanted P-high Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants