Skip to content

Commit

Permalink
Rename rand::distributions -> rand::distr
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jul 18, 2024
1 parent c4fb6eb commit 8f38384
Show file tree
Hide file tree
Showing 38 changed files with 119 additions and 124 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A Rust library for random number generation, featuring:
([see the book](https://rust-random.github.io/book/crates.html))
- Fast implementations of the best-in-class [cryptographic](https://rust-random.github.io/book/guide-rngs.html#cryptographically-secure-pseudo-random-number-generators-csprngs) and
[non-cryptographic](https://rust-random.github.io/book/guide-rngs.html#basic-pseudo-random-number-generators-prngs) generators
- A flexible [`distributions`](https://docs.rs/rand/*/rand/distributions/index.html) module
- A flexible [`distributions`](https://docs.rs/rand/*/rand/distr/index.html) module
- Samplers for a large number of random number distributions via our own
[`rand_distr`](https://docs.rs/rand_distr) and via
the [`statrs`](https://docs.rs/statrs/0.13.0/statrs/)
Expand Down
4 changes: 2 additions & 2 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ criterion = "0.5"
criterion-cycles-per-byte = "0.6"

[[bench]]
name = "distributions"
path = "src/distributions.rs"
name = "distr"
path = "src/distr.rs"
harness = false

[[bench]]
Expand Down
6 changes: 3 additions & 3 deletions benches/benches/base_distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ extern crate test;

const RAND_BENCH_N: u64 = 1000;

use rand::distributions::{Alphanumeric, Open01, OpenClosed01, Standard, Uniform};
use rand::distributions::uniform::{UniformInt, UniformSampler};
use rand::distr::{Alphanumeric, Open01, OpenClosed01, Standard, Uniform};
use rand::distr::uniform::{UniformInt, UniformSampler};
use core::mem::size_of;
use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8};
use core::time::Duration;
Expand Down Expand Up @@ -253,7 +253,7 @@ gen_range_float!(gen_range_f32, f32, -20000.0f32, 100000.0);
gen_range_float!(gen_range_f64, f64, 123.456f64, 7890.12);


// In src/distributions/uniform.rs, we say:
// In src/distr/uniform.rs, we say:
// Implementation of [`uniform_single`] is optional, and is only useful when
// the implementation can be faster than `Self::new(low, high).sample(rng)`.

Expand Down
2 changes: 1 addition & 1 deletion benches/benches/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const RAND_BENCH_N: u64 = 1000;

use test::Bencher;

use rand::distributions::{Bernoulli, Distribution, Standard};
use rand::distr::{Bernoulli, Distribution, Standard};
use rand::prelude::*;
use rand_pcg::{Pcg32, Pcg64Mcg};

Expand Down
2 changes: 1 addition & 1 deletion benches/benches/weighted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern crate test;

use rand::distributions::WeightedIndex;
use rand::distr::WeightedIndex;
use rand::Rng;
use test::Bencher;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion benches/src/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use core::time::Duration;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rand::distributions::uniform::{SampleRange, Uniform};
use rand::distr::uniform::{SampleRange, Uniform};
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use rand_pcg::{Pcg32, Pcg64};
Expand Down
2 changes: 1 addition & 1 deletion benches/src/uniform_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use core::time::Duration;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rand::distributions::uniform::{SampleUniform, Uniform, UniformSampler};
use rand::distr::uniform::{SampleUniform, Uniform, UniformSampler};
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use rand_pcg::{Pcg32, Pcg64};
Expand Down
2 changes: 1 addition & 1 deletion examples/monte-carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! We can use the above fact to estimate the value of π: pick many points in
//! the square at random, calculate the fraction that fall within the circle,
//! and multiply this fraction by 4.
use rand::distributions::{Distribution, Uniform};
use rand::distr::{Distribution, Uniform};

fn main() {
let range = Uniform::new(-1.0f64, 1.0).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/monty-hall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//!
//! [Monty Hall Problem]: https://en.wikipedia.org/wiki/Monty_Hall_problem
use rand::distributions::{Distribution, Uniform};
use rand::distr::{Distribution, Uniform};
use rand::Rng;

struct SimulationResult {
Expand Down
2 changes: 1 addition & 1 deletion examples/rayon-monte-carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! over BATCH_SIZE trials. Manually batching also turns out to be faster
//! for the nondeterministic version of this program as well.
use rand::distributions::{Distribution, Uniform};
use rand::distr::{Distribution, Uniform};
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use rayon::prelude::*;

Expand Down
4 changes: 2 additions & 2 deletions rand_distr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Implements a full suite of random number distribution sampling routines.

This crate is a superset of the [rand::distributions] module, including support
This crate is a superset of the [rand::distr] module, including support
for sampling from Beta, Binomial, Cauchy, ChiSquared, Dirichlet, Exponential,
FisherF, Gamma, Geometric, Hypergeometric, InverseGaussian, LogNormal, Normal,
Pareto, PERT, Poisson, StudentT, Triangular and Weibull distributions. Sampling
Expand Down Expand Up @@ -46,7 +46,7 @@ can be enabled. (Note that any other crate depending on `num-traits` with the


[statrs]: https://github.com/boxtown/statrs
[rand::distributions]: https://rust-random.github.io/rand/rand/distributions/index.html
[rand::distr]: https://rust-random.github.io/rand/rand/distr/index.html

## License

Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/hypergeometric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::Distribution;
use core::fmt;
#[allow(unused_imports)]
use num_traits::Float;
use rand::distributions::uniform::Uniform;
use rand::distr::uniform::Uniform;
use rand::Rng;

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down
8 changes: 4 additions & 4 deletions rand_distr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
//!
//! ## Re-exports
//!
//! This crate is a super-set of the [`rand::distributions`] module. See the
//! [`rand::distributions`] module documentation for an overview of the core
//! This crate is a super-set of the [`rand::distr`] module. See the
//! [`rand::distr`] module documentation for an overview of the core
//! [`Distribution`] trait and implementations.
//!
//! The following are re-exported:
Expand Down Expand Up @@ -93,7 +93,7 @@ extern crate std;
#[allow(unused)]
use rand::Rng;

pub use rand::distributions::{
pub use rand::distr::{
uniform, Alphanumeric, Bernoulli, BernoulliError, DistIter, Distribution, Open01, OpenClosed01,
Standard, Uniform,
};
Expand Down Expand Up @@ -129,7 +129,7 @@ pub use self::weibull::{Error as WeibullError, Weibull};
pub use self::zeta::{Error as ZetaError, Zeta};
pub use self::zipf::{Error as ZipfError, Zipf};
#[cfg(feature = "alloc")]
pub use rand::distributions::{WeightError, WeightedIndex};
pub use rand::distr::{WeightError, WeightedIndex};
pub use student_t::StudentT;
#[cfg(feature = "alloc")]
pub use weighted_alias::WeightedAliasIndex;
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use crate::ziggurat_tables;
use num_traits::Float;
use rand::distributions::hidden_export::IntoFloat;
use rand::distr::hidden_export::IntoFloat;
use rand::Rng;

/// Calculates ln(gamma(x)) (natural logarithm of the gamma
Expand Down
6 changes: 3 additions & 3 deletions rand_distr/src/weighted_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use core::ops::SubAssign;
use super::WeightError;
use crate::Distribution;
use alloc::vec::Vec;
use rand::distributions::uniform::{SampleBorrow, SampleUniform};
use rand::distributions::Weight;
use rand::distr::uniform::{SampleBorrow, SampleUniform};
use rand::distr::Weight;
use rand::Rng;
#[cfg(feature = "serde1")]
use serde::{Deserialize, Serialize};
Expand All @@ -30,7 +30,7 @@ use serde::{Deserialize, Serialize};
///
/// # Key differences
///
/// The main distinction between [`WeightedTreeIndex<W>`] and [`rand::distributions::WeightedIndex<W>`]
/// The main distinction between [`WeightedTreeIndex<W>`] and [`rand::distr::WeightedIndex<W>`]
/// lies in the internal representation of weights. In [`WeightedTreeIndex<W>`],
/// weights are structured as a tree, which is optimized for frequent updates of the weights.
///
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/zeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use crate::{Distribution, Standard};
use core::fmt;
use num_traits::Float;
use rand::{distributions::OpenClosed01, Rng};
use rand::{distr::OpenClosed01, Rng};

/// The [Zeta distribution](https://en.wikipedia.org/wiki/Zeta_distribution) `Zeta(s)`.
///
Expand Down
6 changes: 3 additions & 3 deletions src/distributions/bernoulli.rs → src/distr/bernoulli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//! The Bernoulli distribution `Bernoulli(p)`.
use crate::distributions::Distribution;
use crate::distr::Distribution;
use crate::Rng;
use core::fmt;

Expand All @@ -31,7 +31,7 @@ use serde::{Deserialize, Serialize};
/// # Example
///
/// ```rust
/// use rand::distributions::{Bernoulli, Distribution};
/// use rand::distr::{Bernoulli, Distribution};
///
/// let d = Bernoulli::new(0.3).unwrap();
/// let v = d.sample(&mut rand::thread_rng());
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Distribution<bool> for Bernoulli {
#[cfg(test)]
mod test {
use super::Bernoulli;
use crate::distributions::Distribution;
use crate::distr::Distribution;
use crate::Rng;

#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/distributions/distribution.rs → src/distr/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub trait Distribution<T> {
///
/// ```
/// use rand::thread_rng;
/// use rand::distributions::{Distribution, Alphanumeric, Uniform, Standard};
/// use rand::distr::{Distribution, Alphanumeric, Uniform, Standard};
///
/// let mut rng = thread_rng();
///
Expand Down Expand Up @@ -89,7 +89,7 @@ pub trait Distribution<T> {
///
/// ```
/// use rand::thread_rng;
/// use rand::distributions::{Distribution, Uniform};
/// use rand::distr::{Distribution, Uniform};
///
/// let mut rng = thread_rng();
///
Expand Down Expand Up @@ -201,12 +201,12 @@ pub trait DistString {

#[cfg(test)]
mod tests {
use crate::distributions::{Distribution, Uniform};
use crate::distr::{Distribution, Uniform};
use crate::Rng;

#[test]
fn test_distributions_iter() {
use crate::distributions::Open01;
use crate::distr::Open01;
let mut rng = crate::test::rng(210);
let distr = Open01;
let mut iter = Distribution::<f32>::sample_iter(distr, &mut rng);
Expand Down Expand Up @@ -248,7 +248,7 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
fn test_dist_string() {
use crate::distributions::{Alphanumeric, DistString, Standard};
use crate::distr::{Alphanumeric, DistString, Standard};
use core::str;
let mut rng = crate::test::rng(213);

Expand Down
20 changes: 10 additions & 10 deletions src/distributions/float.rs → src/distr/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

//! Basic floating-point number distributions
use crate::distributions::utils::{FloatAsSIMD, FloatSIMDUtils, IntAsSIMD};
use crate::distributions::{Distribution, Standard};
use crate::distr::utils::{FloatAsSIMD, FloatSIMDUtils, IntAsSIMD};
use crate::distr::{Distribution, Standard};
use crate::Rng;
use core::mem;
#[cfg(feature = "simd_support")]
Expand All @@ -33,15 +33,15 @@ use serde::{Deserialize, Serialize};
/// # Example
/// ```
/// use rand::{thread_rng, Rng};
/// use rand::distributions::OpenClosed01;
/// use rand::distr::OpenClosed01;
///
/// let val: f32 = thread_rng().sample(OpenClosed01);
/// println!("f32 from (0, 1): {}", val);
/// ```
///
/// [`Standard`]: crate::distributions::Standard
/// [`Open01`]: crate::distributions::Open01
/// [`Uniform`]: crate::distributions::uniform::Uniform
/// [`Standard`]: crate::distr::Standard
/// [`Open01`]: crate::distr::Open01
/// [`Uniform`]: crate::distr::uniform::Uniform
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct OpenClosed01;
Expand All @@ -60,15 +60,15 @@ pub struct OpenClosed01;
/// # Example
/// ```
/// use rand::{thread_rng, Rng};
/// use rand::distributions::Open01;
/// use rand::distr::Open01;
///
/// let val: f32 = thread_rng().sample(Open01);
/// println!("f32 from (0, 1): {}", val);
/// ```
///
/// [`Standard`]: crate::distributions::Standard
/// [`OpenClosed01`]: crate::distributions::OpenClosed01
/// [`Uniform`]: crate::distributions::uniform::Uniform
/// [`Standard`]: crate::distr::Standard
/// [`OpenClosed01`]: crate::distr::OpenClosed01
/// [`Uniform`]: crate::distr::uniform::Uniform
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct Open01;
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/integer.rs → src/distr/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//! The implementations of the `Standard` distribution for integer types.
use crate::distributions::{Distribution, Standard};
use crate::distr::{Distribution, Standard};
use crate::Rng;
#[cfg(all(target_arch = "x86", feature = "simd_support"))]
use core::arch::x86::__m512i;
Expand Down
4 changes: 2 additions & 2 deletions src/distributions/mod.rs → src/distr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ use crate::Rng;
/// ```
/// # #![allow(dead_code)]
/// use rand::Rng;
/// use rand::distributions::{Distribution, Standard};
/// use rand::distr::{Distribution, Standard};
///
/// struct MyF32 {
/// x: f32,
Expand All @@ -188,7 +188,7 @@ use crate::Rng;
/// ## Example usage
/// ```
/// use rand::prelude::*;
/// use rand::distributions::Standard;
/// use rand::distr::Standard;
///
/// let val: f32 = StdRng::from_os_rng().sample(Standard);
/// println!("f32 from [0, 1): {}", val);
Expand Down
8 changes: 4 additions & 4 deletions src/distributions/other.rs → src/distr/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use core::char;
use core::num::Wrapping;

#[cfg(feature = "alloc")]
use crate::distributions::DistString;
use crate::distributions::{Distribution, Standard, Uniform};
use crate::distr::DistString;
use crate::distr::{Distribution, Standard, Uniform};
use crate::Rng;

use core::mem::{self, MaybeUninit};
Expand All @@ -35,7 +35,7 @@ use serde::{Deserialize, Serialize};
///
/// ```
/// use rand::{Rng, thread_rng};
/// use rand::distributions::Alphanumeric;
/// use rand::distr::Alphanumeric;
///
/// let mut rng = thread_rng();
/// let chars: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
Expand All @@ -45,7 +45,7 @@ use serde::{Deserialize, Serialize};
/// The [`DistString`] trait provides an easier method of generating
/// a random `String`, and offers more efficient allocation:
/// ```
/// use rand::distributions::{Alphanumeric, DistString};
/// use rand::distr::{Alphanumeric, DistString};
/// let string = Alphanumeric.sample_string(&mut rand::thread_rng(), 16);
/// println!("Random string: {}", string);
/// ```
Expand Down
Loading

0 comments on commit 8f38384

Please sign in to comment.