From 8f3838427b4a3baef3ef4b42934c9d36d617b87c Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 18 Jul 2024 10:47:22 +0100 Subject: [PATCH] Rename rand::distributions -> rand::distr --- README.md | 2 +- benches/Cargo.toml | 4 +-- benches/benches/base_distributions.rs | 6 ++-- benches/benches/misc.rs | 2 +- benches/benches/weighted.rs | 2 +- benches/src/{distributions.rs => distr.rs} | 0 benches/src/uniform.rs | 2 +- benches/src/uniform_float.rs | 2 +- examples/monte-carlo.rs | 2 +- examples/monty-hall.rs | 2 +- examples/rayon-monte-carlo.rs | 2 +- rand_distr/README.md | 4 +-- rand_distr/src/hypergeometric.rs | 2 +- rand_distr/src/lib.rs | 8 ++--- rand_distr/src/utils.rs | 2 +- rand_distr/src/weighted_tree.rs | 6 ++-- rand_distr/src/zeta.rs | 2 +- src/{distributions => distr}/bernoulli.rs | 6 ++-- src/{distributions => distr}/distribution.rs | 10 +++---- src/{distributions => distr}/float.rs | 20 ++++++------- src/{distributions => distr}/integer.rs | 2 +- src/{distributions => distr}/mod.rs | 4 +-- src/{distributions => distr}/other.rs | 8 ++--- src/{distributions => distr}/slice.rs | 9 ++---- src/{distributions => distr}/uniform.rs | 30 +++++++++---------- src/{distributions => distr}/uniform_float.rs | 8 ++--- src/{distributions => distr}/uniform_int.rs | 6 ++-- src/{distributions => distr}/uniform_other.rs | 6 ++-- src/{distributions => distr}/utils.rs | 0 .../weighted_index.rs | 14 ++++----- src/lib.rs | 8 ++--- src/prelude.rs | 2 +- src/rng.rs | 30 +++++++++---------- src/rngs/mock.rs | 4 +-- src/seq/index.rs | 4 +-- src/seq/mod.rs | 4 +-- src/seq/slice.rs | 16 +++++----- utils/ziggurat_tables.py | 2 +- 38 files changed, 119 insertions(+), 124 deletions(-) rename benches/src/{distributions.rs => distr.rs} (100%) rename src/{distributions => distr}/bernoulli.rs (98%) rename src/{distributions => distr}/distribution.rs (96%) rename src/{distributions => distr}/float.rs (96%) rename src/{distributions => distr}/integer.rs (99%) rename src/{distributions => distr}/mod.rs (99%) rename src/{distributions => distr}/other.rs (98%) rename src/{distributions => distr}/slice.rs (97%) rename src/{distributions => distr}/uniform.rs (95%) rename src/{distributions => distr}/uniform_float.rs (98%) rename src/{distributions => distr}/uniform_int.rs (99%) rename src/{distributions => distr}/uniform_other.rs (98%) rename src/{distributions => distr}/utils.rs (100%) rename src/{distributions => distr}/weighted_index.rs (98%) diff --git a/README.md b/README.md index 9fa7a2f8528..18f22a89eb8 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index b3068c2f758..083512d0bc6 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -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]] diff --git a/benches/benches/base_distributions.rs b/benches/benches/base_distributions.rs index c60ce47aeab..17202a30350 100644 --- a/benches/benches/base_distributions.rs +++ b/benches/benches/base_distributions.rs @@ -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; @@ -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)`. diff --git a/benches/benches/misc.rs b/benches/benches/misc.rs index 50dfc0ea8a7..8a3b4767ef2 100644 --- a/benches/benches/misc.rs +++ b/benches/benches/misc.rs @@ -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}; diff --git a/benches/benches/weighted.rs b/benches/benches/weighted.rs index 68722908a9e..da437ab5b0b 100644 --- a/benches/benches/weighted.rs +++ b/benches/benches/weighted.rs @@ -10,7 +10,7 @@ extern crate test; -use rand::distributions::WeightedIndex; +use rand::distr::WeightedIndex; use rand::Rng; use test::Bencher; diff --git a/benches/src/distributions.rs b/benches/src/distr.rs similarity index 100% rename from benches/src/distributions.rs rename to benches/src/distr.rs diff --git a/benches/src/uniform.rs b/benches/src/uniform.rs index 948d1315889..78eb066eac7 100644 --- a/benches/src/uniform.rs +++ b/benches/src/uniform.rs @@ -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}; diff --git a/benches/src/uniform_float.rs b/benches/src/uniform_float.rs index 91c0eff4b7b..f33a2b729d3 100644 --- a/benches/src/uniform_float.rs +++ b/benches/src/uniform_float.rs @@ -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}; diff --git a/examples/monte-carlo.rs b/examples/monte-carlo.rs index 21ab109ce05..0f50a4aeb0d 100644 --- a/examples/monte-carlo.rs +++ b/examples/monte-carlo.rs @@ -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(); diff --git a/examples/monty-hall.rs b/examples/monty-hall.rs index aaff41cad33..a6fcd04e802 100644 --- a/examples/monty-hall.rs +++ b/examples/monty-hall.rs @@ -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 { diff --git a/examples/rayon-monte-carlo.rs b/examples/rayon-monte-carlo.rs index 839a1593a1b..31d8e681067 100644 --- a/examples/rayon-monte-carlo.rs +++ b/examples/rayon-monte-carlo.rs @@ -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::*; diff --git a/rand_distr/README.md b/rand_distr/README.md index 16a44bc85c9..0c8b20b95ef 100644 --- a/rand_distr/README.md +++ b/rand_distr/README.md @@ -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 @@ -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 diff --git a/rand_distr/src/hypergeometric.rs b/rand_distr/src/hypergeometric.rs index 4e4f4306353..683db15314d 100644 --- a/rand_distr/src/hypergeometric.rs +++ b/rand_distr/src/hypergeometric.rs @@ -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)] diff --git a/rand_distr/src/lib.rs b/rand_distr/src/lib.rs index f6f3ad54cfa..90a534ff8cb 100644 --- a/rand_distr/src/lib.rs +++ b/rand_distr/src/lib.rs @@ -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: @@ -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, }; @@ -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; diff --git a/rand_distr/src/utils.rs b/rand_distr/src/utils.rs index fb49ab85762..5879a152670 100644 --- a/rand_distr/src/utils.rs +++ b/rand_distr/src/utils.rs @@ -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 diff --git a/rand_distr/src/weighted_tree.rs b/rand_distr/src/weighted_tree.rs index f3463bcd960..28edab700d4 100644 --- a/rand_distr/src/weighted_tree.rs +++ b/rand_distr/src/weighted_tree.rs @@ -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}; @@ -30,7 +30,7 @@ use serde::{Deserialize, Serialize}; /// /// # Key differences /// -/// The main distinction between [`WeightedTreeIndex`] and [`rand::distributions::WeightedIndex`] +/// The main distinction between [`WeightedTreeIndex`] and [`rand::distr::WeightedIndex`] /// lies in the internal representation of weights. In [`WeightedTreeIndex`], /// weights are structured as a tree, which is optimized for frequent updates of the weights. /// diff --git a/rand_distr/src/zeta.rs b/rand_distr/src/zeta.rs index da146883f0a..922458436f5 100644 --- a/rand_distr/src/zeta.rs +++ b/rand_distr/src/zeta.rs @@ -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)`. /// diff --git a/src/distributions/bernoulli.rs b/src/distr/bernoulli.rs similarity index 98% rename from src/distributions/bernoulli.rs rename to src/distr/bernoulli.rs index e49b415fea9..5a56d079a83 100644 --- a/src/distributions/bernoulli.rs +++ b/src/distr/bernoulli.rs @@ -8,7 +8,7 @@ //! The Bernoulli distribution `Bernoulli(p)`. -use crate::distributions::Distribution; +use crate::distr::Distribution; use crate::Rng; use core::fmt; @@ -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()); @@ -153,7 +153,7 @@ impl Distribution for Bernoulli { #[cfg(test)] mod test { use super::Bernoulli; - use crate::distributions::Distribution; + use crate::distr::Distribution; use crate::Rng; #[test] diff --git a/src/distributions/distribution.rs b/src/distr/distribution.rs similarity index 96% rename from src/distributions/distribution.rs rename to src/distr/distribution.rs index d545eeea457..8a59e11e13c 100644 --- a/src/distributions/distribution.rs +++ b/src/distr/distribution.rs @@ -49,7 +49,7 @@ pub trait Distribution { /// /// ``` /// use rand::thread_rng; - /// use rand::distributions::{Distribution, Alphanumeric, Uniform, Standard}; + /// use rand::distr::{Distribution, Alphanumeric, Uniform, Standard}; /// /// let mut rng = thread_rng(); /// @@ -89,7 +89,7 @@ pub trait Distribution { /// /// ``` /// use rand::thread_rng; - /// use rand::distributions::{Distribution, Uniform}; + /// use rand::distr::{Distribution, Uniform}; /// /// let mut rng = thread_rng(); /// @@ -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::::sample_iter(distr, &mut rng); @@ -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); diff --git a/src/distributions/float.rs b/src/distr/float.rs similarity index 96% rename from src/distributions/float.rs rename to src/distr/float.rs index 427385e50a2..67e6d4b250d 100644 --- a/src/distributions/float.rs +++ b/src/distr/float.rs @@ -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")] @@ -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; @@ -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; diff --git a/src/distributions/integer.rs b/src/distr/integer.rs similarity index 99% rename from src/distributions/integer.rs rename to src/distr/integer.rs index 66258dcbd5c..49546a39417 100644 --- a/src/distributions/integer.rs +++ b/src/distr/integer.rs @@ -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; diff --git a/src/distributions/mod.rs b/src/distr/mod.rs similarity index 99% rename from src/distributions/mod.rs rename to src/distr/mod.rs index b31ebe14f18..8b5c0054271 100644 --- a/src/distributions/mod.rs +++ b/src/distr/mod.rs @@ -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, @@ -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); diff --git a/src/distributions/other.rs b/src/distr/other.rs similarity index 98% rename from src/distributions/other.rs rename to src/distr/other.rs index 21289ca94d0..d4445209454 100644 --- a/src/distributions/other.rs +++ b/src/distr/other.rs @@ -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}; @@ -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(); @@ -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); /// ``` diff --git a/src/distributions/slice.rs b/src/distr/slice.rs similarity index 97% rename from src/distributions/slice.rs rename to src/distr/slice.rs index 3bf3118078b..4bd1a43cbdf 100644 --- a/src/distributions/slice.rs +++ b/src/distr/slice.rs @@ -8,7 +8,7 @@ use core::num::NonZeroUsize; -use crate::distributions::{Distribution, Uniform}; +use crate::distr::{Distribution, Uniform}; use crate::Rng; #[cfg(feature = "alloc")] use alloc::string::String; @@ -63,7 +63,7 @@ impl UniformUsize { /// /// ``` /// use rand::Rng; -/// use rand::distributions::Slice; +/// use rand::distr::Slice; /// /// let vowels = ['a', 'e', 'i', 'o', 'u']; /// let vowels_dist = Slice::new(&vowels).unwrap(); @@ -146,10 +146,7 @@ pub struct EmptySlice; impl core::fmt::Display for EmptySlice { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!( - f, - "Tried to create a `distributions::Slice` with an empty slice" - ) + write!(f, "Tried to create a `distr::Slice` with an empty slice") } } diff --git a/src/distributions/uniform.rs b/src/distr/uniform.rs similarity index 95% rename from src/distributions/uniform.rs rename to src/distr/uniform.rs index a8d9b22cce8..7e69614cc14 100644 --- a/src/distributions/uniform.rs +++ b/src/distr/uniform.rs @@ -27,7 +27,7 @@ //! //! ``` //! use rand::{Rng, thread_rng}; -//! use rand::distributions::Uniform; +//! use rand::distr::Uniform; //! //! let mut rng = thread_rng(); //! let side = Uniform::new(-10.0, 10.0).unwrap(); @@ -60,7 +60,7 @@ //! //! ``` //! use rand::prelude::*; -//! use rand::distributions::uniform::{Uniform, SampleUniform, +//! use rand::distr::uniform::{Uniform, SampleUniform, //! UniformSampler, UniformFloat, SampleBorrow, Error}; //! //! struct MyF32(f32); @@ -97,12 +97,12 @@ //! let x = uniform.sample(&mut thread_rng()); //! ``` //! -//! [`SampleUniform`]: crate::distributions::uniform::SampleUniform -//! [`UniformSampler`]: crate::distributions::uniform::UniformSampler -//! [`UniformInt`]: crate::distributions::uniform::UniformInt -//! [`UniformFloat`]: crate::distributions::uniform::UniformFloat -//! [`UniformDuration`]: crate::distributions::uniform::UniformDuration -//! [`SampleBorrow::borrow`]: crate::distributions::uniform::SampleBorrow::borrow +//! [`SampleUniform`]: crate::distr::uniform::SampleUniform +//! [`UniformSampler`]: crate::distr::uniform::UniformSampler +//! [`UniformInt`]: crate::distr::uniform::UniformInt +//! [`UniformFloat`]: crate::distr::uniform::UniformFloat +//! [`UniformDuration`]: crate::distr::uniform::UniformDuration +//! [`SampleBorrow::borrow`]: crate::distr::uniform::SampleBorrow::borrow #[path = "uniform_float.rs"] mod float; @@ -122,7 +122,7 @@ pub use other::{UniformChar, UniformDuration}; use core::fmt; use core::ops::{Range, RangeInclusive}; -use crate::distributions::Distribution; +use crate::distr::Distribution; use crate::{Rng, RngCore}; /// Error type returned from [`Uniform::new`] and `new_inclusive`. @@ -175,7 +175,7 @@ use serde::{Deserialize, Serialize}; /// # Example /// /// ``` -/// use rand::distributions::{Distribution, Uniform}; +/// use rand::distr::{Distribution, Uniform}; /// /// let between = Uniform::try_from(10..10000).unwrap(); /// let mut rng = rand::thread_rng(); @@ -252,7 +252,7 @@ impl Distribution for Uniform { /// See the [module documentation] on how to implement [`Uniform`] range /// sampling for a custom type. /// -/// [module documentation]: crate::distributions::uniform +/// [module documentation]: crate::distr::uniform pub trait SampleUniform: Sized { /// The `UniformSampler` implementation supporting type `X`. type Sampler: UniformSampler; @@ -266,7 +266,7 @@ pub trait SampleUniform: Sized { /// Implementation of [`sample_single`] is optional, and is only useful when /// the implementation can be faster than `Self::new(low, high).sample(rng)`. /// -/// [module documentation]: crate::distributions::uniform +/// [module documentation]: crate::distr::uniform /// [`sample_single`]: UniformSampler::sample_single pub trait UniformSampler: Sized { /// The type sampled by this implementation. @@ -315,7 +315,7 @@ pub trait UniformSampler: Sized { /// Note that to use this method in a generic context, the type needs to be /// retrieved via `SampleUniform::Sampler` as follows: /// ``` - /// use rand::{thread_rng, distributions::uniform::{SampleUniform, UniformSampler}}; + /// use rand::{thread_rng, distr::uniform::{SampleUniform, UniformSampler}}; /// # #[allow(unused)] /// fn sample_from_range(lb: T, ub: T) -> T { /// let mut rng = thread_rng(); @@ -460,9 +460,7 @@ mod tests { #[test] fn test_custom_uniform() { - use crate::distributions::uniform::{ - SampleBorrow, SampleUniform, UniformFloat, UniformSampler, - }; + use crate::distr::uniform::{SampleBorrow, SampleUniform, UniformFloat, UniformSampler}; #[derive(Clone, Copy, PartialEq, PartialOrd)] struct MyF32 { x: f32, diff --git a/src/distributions/uniform_float.rs b/src/distr/uniform_float.rs similarity index 98% rename from src/distributions/uniform_float.rs rename to src/distr/uniform_float.rs index 6185552df45..b44e192c65d 100644 --- a/src/distributions/uniform_float.rs +++ b/src/distr/uniform_float.rs @@ -10,8 +10,8 @@ //! `UniformFloat` implementation use super::{Error, SampleBorrow, SampleUniform, UniformSampler}; -use crate::distributions::float::IntoFloat; -use crate::distributions::utils::{BoolAsSIMD, FloatAsSIMD, FloatSIMDUtils, IntAsSIMD}; +use crate::distr::float::IntoFloat; +use crate::distr::utils::{BoolAsSIMD, FloatAsSIMD, FloatSIMDUtils, IntAsSIMD}; use crate::Rng; #[cfg(feature = "simd_support")] @@ -40,7 +40,7 @@ use serde::{Deserialize, Serialize}; /// /// [`new`]: UniformSampler::new /// [`new_inclusive`]: UniformSampler::new_inclusive -/// [`Standard`]: crate::distributions::Standard +/// [`Standard`]: crate::distr::Standard /// [`Uniform`]: super::Uniform #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] @@ -215,7 +215,7 @@ uniform_float_impl! { feature = "simd_support", f64x8, u64x8, f64, u64, 64 - 52 #[cfg(test)] mod tests { use super::*; - use crate::distributions::{utils::FloatSIMDScalarUtils, Uniform}; + use crate::distr::{utils::FloatSIMDScalarUtils, Uniform}; use crate::rngs::mock::StepRng; #[test] diff --git a/src/distributions/uniform_int.rs b/src/distr/uniform_int.rs similarity index 99% rename from src/distributions/uniform_int.rs rename to src/distr/uniform_int.rs index 6554ac135d2..5a6254058e0 100644 --- a/src/distributions/uniform_int.rs +++ b/src/distr/uniform_int.rs @@ -10,9 +10,9 @@ //! `UniformInt` implementation use super::{Error, SampleBorrow, SampleUniform, UniformSampler}; -use crate::distributions::utils::WideningMultiply; +use crate::distr::utils::WideningMultiply; #[cfg(feature = "simd_support")] -use crate::distributions::{Distribution, Standard}; +use crate::distr::{Distribution, Standard}; use crate::Rng; #[cfg(feature = "simd_support")] @@ -388,7 +388,7 @@ uniform_simd_int_impl! { (u8, i8), (u16, i16), (u32, i32), (u64, i64) } #[cfg(test)] mod tests { use super::*; - use crate::distributions::Uniform; + use crate::distr::Uniform; #[test] fn test_uniform_bad_limits_equal_int() { diff --git a/src/distributions/uniform_other.rs b/src/distr/uniform_other.rs similarity index 98% rename from src/distributions/uniform_other.rs rename to src/distr/uniform_other.rs index 75e341849f2..af10eed50d1 100644 --- a/src/distributions/uniform_other.rs +++ b/src/distr/uniform_other.rs @@ -10,7 +10,7 @@ //! `UniformChar`, `UniformDuration` implementations use super::{Error, SampleBorrow, SampleUniform, Uniform, UniformInt, UniformSampler}; -use crate::distributions::Distribution; +use crate::distr::Distribution; use crate::Rng; use core::time::Duration; @@ -94,7 +94,7 @@ impl UniformSampler for UniformChar { /// includes non ascii chars; optionally the user may call /// `string.shrink_to_fit()` afterwards. #[cfg(feature = "alloc")] -impl crate::distributions::DistString for Uniform { +impl crate::distr::DistString for Uniform { fn append_string( &self, rng: &mut R, @@ -281,7 +281,7 @@ mod tests { } #[cfg(feature = "alloc")] { - use crate::distributions::DistString; + use crate::distr::DistString; let string1 = d.sample_string(&mut rng, 100); assert_eq!(string1.capacity(), 300); let string2 = Uniform::new( diff --git a/src/distributions/utils.rs b/src/distr/utils.rs similarity index 100% rename from src/distributions/utils.rs rename to src/distr/utils.rs diff --git a/src/distributions/weighted_index.rs b/src/distr/weighted_index.rs similarity index 98% rename from src/distributions/weighted_index.rs rename to src/distr/weighted_index.rs index 88fad5a88ad..c0ceefee5d1 100644 --- a/src/distributions/weighted_index.rs +++ b/src/distr/weighted_index.rs @@ -8,8 +8,8 @@ //! Weighted index sampling -use crate::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler}; -use crate::distributions::Distribution; +use crate::distr::uniform::{SampleBorrow, SampleUniform, UniformSampler}; +use crate::distr::Distribution; use crate::Rng; use core::fmt; @@ -59,7 +59,7 @@ use serde::{Deserialize, Serialize}; /// /// ``` /// use rand::prelude::*; -/// use rand::distributions::WeightedIndex; +/// use rand::distr::WeightedIndex; /// /// let choices = ['a', 'b', 'c']; /// let weights = [2, 1, 1]; @@ -78,7 +78,7 @@ use serde::{Deserialize, Serialize}; /// } /// ``` /// -/// [`Uniform`]: crate::distributions::Uniform +/// [`Uniform`]: crate::distr::Uniform /// [`RngCore`]: crate::RngCore /// [`rand_distr::weighted_alias`]: https://docs.rs/rand_distr/*/rand_distr/weighted_alias/index.html /// [`rand_distr::weighted_tree`]: https://docs.rs/rand_distr/*/rand_distr/weighted_tree/index.html @@ -101,7 +101,7 @@ impl WeightedIndex { /// - [`WeightError::InsufficientNonZero`] when the sum of all weights is zero. /// - [`WeightError::Overflow`] when the sum of all weights overflows. /// - /// [`Uniform`]: crate::distributions::uniform::Uniform + /// [`Uniform`]: crate::distr::uniform::Uniform pub fn new(weights: I) -> Result, WeightError> where I: IntoIterator, @@ -306,7 +306,7 @@ impl WeightedIndex { /// # Example /// /// ``` - /// use rand::distributions::WeightedIndex; + /// use rand::distr::WeightedIndex; /// /// let weights = [0, 1, 2]; /// let dist = WeightedIndex::new(&weights).unwrap(); @@ -341,7 +341,7 @@ impl WeightedIndex { /// # Example /// /// ``` - /// use rand::distributions::WeightedIndex; + /// use rand::distr::WeightedIndex; /// /// let weights = [1, 2, 3]; /// let mut dist = WeightedIndex::new(&weights).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 8b43f0320f9..ce0206db09b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ //! To get you started quickly, the easiest and highest-level way to get //! a random value is to use [`random()`]; alternatively you can use //! [`thread_rng()`]. The [`Rng`] trait provides a useful API on all RNGs, while -//! the [`distributions`] and [`seq`] modules provide further +//! the [`distr`] and [`seq`] modules provide further //! functionality on top of RNGs. //! //! ``` @@ -97,7 +97,7 @@ macro_rules! error { ($($x:tt)*) => ( pub use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore}; // Public modules -pub mod distributions; +pub mod distr; pub mod prelude; mod rng; pub mod rngs; @@ -109,7 +109,7 @@ pub use crate::rngs::thread::thread_rng; pub use rng::{Fill, Rng}; #[cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))] -use crate::distributions::{Distribution, Standard}; +use crate::distr::{Distribution, Standard}; /// Generates a random value using the thread-local random number generator. /// @@ -153,7 +153,7 @@ use crate::distributions::{Distribution, Standard}; /// } /// ``` /// -/// [`Standard`]: distributions::Standard +/// [`Standard`]: distr::Standard /// [`ThreadRng`]: rngs::ThreadRng #[cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))] #[inline] diff --git a/src/prelude.rs b/src/prelude.rs index 2605bca91f4..37b703742df 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -19,7 +19,7 @@ //! ``` #[doc(no_inline)] -pub use crate::distributions::Distribution; +pub use crate::distr::Distribution; #[cfg(feature = "small_rng")] #[doc(no_inline)] pub use crate::rngs::SmallRng; diff --git a/src/rng.rs b/src/rng.rs index 06fc2bb741e..9c015eddd41 100644 --- a/src/rng.rs +++ b/src/rng.rs @@ -9,8 +9,8 @@ //! [`Rng`] trait -use crate::distributions::uniform::{SampleRange, SampleUniform}; -use crate::distributions::{self, Distribution, Standard}; +use crate::distr::uniform::{SampleRange, SampleUniform}; +use crate::distr::{self, Distribution, Standard}; use core::num::Wrapping; use core::{mem, slice}; use rand_core::RngCore; @@ -86,7 +86,7 @@ pub trait Rng: RngCore { /// rng.fill(&mut arr2); // array fill /// ``` /// - /// [`Standard`]: distributions::Standard + /// [`Standard`]: distr::Standard #[inline] fn random(&mut self) -> T where @@ -125,7 +125,7 @@ pub trait Rng: RngCore { /// println!("{}", n); /// ``` /// - /// [`Uniform`]: distributions::uniform::Uniform + /// [`Uniform`]: distr::uniform::Uniform #[track_caller] fn gen_range(&mut self, range: R) -> T where @@ -139,7 +139,7 @@ pub trait Rng: RngCore { /// Generate values via an iterator /// /// This is a just a wrapper over [`Rng::sample_iter`] using - /// [`distributions::Standard`]. + /// [`distr::Standard`]. /// /// Note: this method consumes its argument. Use /// `(&mut rng).gen_iter()` to avoid consuming the RNG. @@ -154,7 +154,7 @@ pub trait Rng: RngCore { /// assert_eq!(&v, &[1, 2, 3, 4, 5]); /// ``` #[inline] - fn gen_iter(self) -> distributions::DistIter + fn gen_iter(self) -> distr::DistIter where Self: Sized, Standard: Distribution, @@ -168,7 +168,7 @@ pub trait Rng: RngCore { /// /// ``` /// use rand::{thread_rng, Rng}; - /// use rand::distributions::Uniform; + /// use rand::distr::Uniform; /// /// let mut rng = thread_rng(); /// let x = rng.sample(Uniform::new(10u32, 15).unwrap()); @@ -189,7 +189,7 @@ pub trait Rng: RngCore { /// /// ``` /// use rand::{thread_rng, Rng}; - /// use rand::distributions::{Alphanumeric, Uniform, Standard}; + /// use rand::distr::{Alphanumeric, Uniform, Standard}; /// /// let mut rng = thread_rng(); /// @@ -213,7 +213,7 @@ pub trait Rng: RngCore { /// println!("Not a 6; rolling again!"); /// } /// ``` - fn sample_iter(self, distr: D) -> distributions::DistIter + fn sample_iter(self, distr: D) -> distr::DistIter where D: Distribution, Self: Sized, @@ -259,11 +259,11 @@ pub trait Rng: RngCore { /// /// If `p < 0` or `p > 1`. /// - /// [`Bernoulli`]: distributions::Bernoulli + /// [`Bernoulli`]: distr::Bernoulli #[inline] #[track_caller] fn gen_bool(&mut self, p: f64) -> bool { - match distributions::Bernoulli::new(p) { + match distr::Bernoulli::new(p) { Ok(d) => self.sample(d), Err(_) => panic!("p={:?} is outside range [0.0, 1.0]", p), } @@ -291,11 +291,11 @@ pub trait Rng: RngCore { /// println!("{}", rng.gen_ratio(2, 3)); /// ``` /// - /// [`Bernoulli`]: distributions::Bernoulli + /// [`Bernoulli`]: distr::Bernoulli #[inline] #[track_caller] fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool { - match distributions::Bernoulli::from_ratio(numerator, denominator) { + match distr::Bernoulli::from_ratio(numerator, denominator) { Ok(d) => self.sample(d), Err(_) => panic!( "p={}/{} is outside range [0.0, 1.0]", @@ -554,7 +554,7 @@ mod test { #[test] fn test_rng_trait_object() { - use crate::distributions::{Distribution, Standard}; + use crate::distr::{Distribution, Standard}; let mut rng = rng(109); let mut r = &mut rng as &mut dyn RngCore; r.next_u32(); @@ -566,7 +566,7 @@ mod test { #[test] #[cfg(feature = "alloc")] fn test_rng_boxed_trait() { - use crate::distributions::{Distribution, Standard}; + use crate::distr::{Distribution, Standard}; let rng = rng(110); let mut r = Box::new(rng) as Box; r.next_u32(); diff --git a/src/rngs/mock.rs b/src/rngs/mock.rs index a01a6bd7b4e..6218626db9b 100644 --- a/src/rngs/mock.rs +++ b/src/rngs/mock.rs @@ -22,7 +22,7 @@ use serde::{Deserialize, Serialize}; /// Other integer types (64-bit and smaller) are produced via cast from `u64`. /// /// Other types are produced via their implementation of [`Rng`](crate::Rng) or -/// [`Distribution`](crate::distributions::Distribution). +/// [`Distribution`](crate::distr::Distribution). /// Output values may not be intuitive and may change in future releases but /// are considered /// [portable](https://rust-random.github.io/book/portability.html). @@ -95,7 +95,7 @@ mod tests { #[test] #[cfg(feature = "alloc")] fn test_bool() { - use crate::{distributions::Standard, Rng}; + use crate::{distr::Standard, Rng}; // If this result ever changes, update doc on StepRng! let rng = StepRng::new(0, 1 << 31); diff --git a/src/seq/index.rs b/src/seq/index.rs index b85ac348bab..2da713ebdb6 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -13,8 +13,8 @@ use core::{hash::Hash, ops::AddAssign}; // BTreeMap is not as fast in tests, but better than nothing. #[cfg(feature = "std")] use super::WeightError; -use crate::distributions::uniform::SampleUniform; -use crate::distributions::{Distribution, Uniform}; +use crate::distr::uniform::SampleUniform; +use crate::distr::{Distribution, Uniform}; use crate::Rng; #[cfg(not(feature = "std"))] use alloc::collections::BTreeSet; diff --git a/src/seq/mod.rs b/src/seq/mod.rs index 77f2fb31113..0015517907a 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -19,7 +19,7 @@ //! //! Also see: //! -//! * [`crate::distributions::WeightedIndex`] distribution which provides +//! * [`crate::distr::WeightedIndex`] distribution which provides //! weighted index sampling. //! //! In order to make results reproducible across 32-64 bit architectures, all @@ -37,7 +37,7 @@ mod index_; #[cfg(feature = "alloc")] #[doc(no_inline)] -pub use crate::distributions::WeightError; +pub use crate::distr::WeightError; pub use iterator::IteratorRandom; #[cfg(feature = "alloc")] pub use slice::SliceChooseIter; diff --git a/src/seq/slice.rs b/src/seq/slice.rs index c82998fd358..7c86f00a736 100644 --- a/src/seq/slice.rs +++ b/src/seq/slice.rs @@ -11,9 +11,9 @@ use super::increasing_uniform::IncreasingUniform; use super::{gen_index, index}; #[cfg(feature = "alloc")] -use crate::distributions::uniform::{SampleBorrow, SampleUniform}; +use crate::distr::uniform::{SampleBorrow, SampleUniform}; #[cfg(feature = "alloc")] -use crate::distributions::{Weight, WeightError}; +use crate::distr::{Weight, WeightError}; use crate::Rng; use core::ops::{Index, IndexMut}; @@ -137,7 +137,7 @@ pub trait IndexedRandom: Index { /// /// For slices of length `n`, complexity is `O(n)`. /// For more information about the underlying algorithm, - /// see [`distributions::WeightedIndex`]. + /// see [`distr::WeightedIndex`]. /// /// See also [`choose_weighted_mut`]. /// @@ -154,7 +154,7 @@ pub trait IndexedRandom: Index { /// ``` /// [`choose`]: IndexedRandom::choose /// [`choose_weighted_mut`]: IndexedMutRandom::choose_weighted_mut - /// [`distributions::WeightedIndex`]: crate::distributions::WeightedIndex + /// [`distr::WeightedIndex`]: crate::distr::WeightedIndex #[cfg(feature = "alloc")] fn choose_weighted( &self, @@ -167,7 +167,7 @@ pub trait IndexedRandom: Index { B: SampleBorrow, X: SampleUniform + Weight + PartialOrd, { - use crate::distributions::{Distribution, WeightedIndex}; + use crate::distr::{Distribution, WeightedIndex}; let distr = WeightedIndex::new((0..self.len()).map(|idx| weight(&self[idx])))?; Ok(&self[distr.sample(rng)]) } @@ -268,13 +268,13 @@ pub trait IndexedMutRandom: IndexedRandom + IndexMut { /// /// For slices of length `n`, complexity is `O(n)`. /// For more information about the underlying algorithm, - /// see [`distributions::WeightedIndex`]. + /// see [`distr::WeightedIndex`]. /// /// See also [`choose_weighted`]. /// /// [`choose_mut`]: IndexedMutRandom::choose_mut /// [`choose_weighted`]: IndexedRandom::choose_weighted - /// [`distributions::WeightedIndex`]: crate::distributions::WeightedIndex + /// [`distr::WeightedIndex`]: crate::distr::WeightedIndex #[cfg(feature = "alloc")] fn choose_weighted_mut( &mut self, @@ -287,7 +287,7 @@ pub trait IndexedMutRandom: IndexedRandom + IndexMut { B: SampleBorrow, X: SampleUniform + Weight + PartialOrd, { - use crate::distributions::{Distribution, WeightedIndex}; + use crate::distr::{Distribution, WeightedIndex}; let distr = WeightedIndex::new((0..self.len()).map(|idx| weight(&self[idx])))?; let index = distr.sample(rng); Ok(&mut self[index]) diff --git a/utils/ziggurat_tables.py b/utils/ziggurat_tables.py index 88cfdab6ba2..87a766ccc36 100755 --- a/utils/ziggurat_tables.py +++ b/utils/ziggurat_tables.py @@ -10,7 +10,7 @@ # except according to those terms. # This creates the tables used for distributions implemented using the -# ziggurat algorithm in `rand::distributions;`. They are +# ziggurat algorithm in `rand::distr;`. They are # (basically) the tables as used in the ZIGNOR variant (Doornik 2005). # They are changed rarely, so the generated file should be checked in # to git.