From a1445a2cf15217aaf917e86cd1dd2b412333af11 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 23 May 2019 16:53:46 +0100 Subject: [PATCH] rand_distr: use Pcg32 in uniformity test and update the two new test vectors --- rand_distr/src/unit_ball.rs | 6 +++--- rand_distr/src/unit_disc.rs | 8 ++++---- rand_distr/tests/uniformity.rs | 12 +++--------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/rand_distr/src/unit_ball.rs b/rand_distr/src/unit_ball.rs index 9d59002b0d5..9d61627a3ef 100644 --- a/rand_distr/src/unit_ball.rs +++ b/rand_distr/src/unit_ball.rs @@ -55,9 +55,9 @@ mod tests { fn value_stability() { let mut rng = crate::test::rng(2); let expected = [ - [-0.42140140089381806, 0.4245276448803281, -0.7109276652167549], - [0.6683277779168173, 0.12753134283863998, 0.6843687153674809], - [-0.80397712218568, -0.0015797354643116712, 0.1588400395442835], + [0.018035709265959987, -0.4348771383120438, -0.07982762085055706], + [0.10588569388223945, -0.4734350111375454, -0.7392104908825501], + [0.11060237642041049, -0.16065642822852677, -0.8444043930440075] ]; let samples: [[f64; 3]; 3] = [ UnitBall.sample(&mut rng), diff --git a/rand_distr/src/unit_disc.rs b/rand_distr/src/unit_disc.rs index 81e74f49975..97abc2f206e 100644 --- a/rand_distr/src/unit_disc.rs +++ b/rand_distr/src/unit_disc.rs @@ -52,10 +52,10 @@ mod tests { fn value_stability() { let mut rng = crate::test::rng(2); let expected = [ - [-0.13921053103419823, -0.42140140089381806], - [0.4245276448803281, -0.7109276652167549], - [0.6683277779168173, 0.12753134283863998], - ]; + [0.018035709265959987, -0.4348771383120438], + [-0.07982762085055706, 0.7765329819820659], + [0.21450745997299503, 0.7398636984333291] + ]; let samples: [[f64; 2]; 3] = [ UnitDisc.sample(&mut rng), UnitDisc.sample(&mut rng), diff --git a/rand_distr/tests/uniformity.rs b/rand_distr/tests/uniformity.rs index ab9607111fe..3582b7f19ac 100644 --- a/rand_distr/tests/uniformity.rs +++ b/rand_distr/tests/uniformity.rs @@ -6,12 +6,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[macro_use] -extern crate average; -extern crate rand; -extern crate rand_distr; -extern crate core; - use average::Histogram; use rand::distributions::Distribution; use rand::FromEntropy; @@ -19,7 +13,7 @@ use rand::FromEntropy; const N_BINS: usize = 100; const N_SAMPLES: u32 = 1_000_000; const TOL: f64 = 1e-3; -define_histogram!(hist, 100); +average::define_histogram!(hist, 100); use hist::Histogram as Histogram100; #[test] @@ -28,7 +22,7 @@ fn unit_sphere() { let h = Histogram100::with_const_width(-1., 1.); let mut histograms = [h.clone(), h.clone(), h]; let dist = rand_distr::UnitSphere; - let mut rng = rand::rngs::SmallRng::from_entropy(); + let mut rng = rand_pcg::Pcg32::from_entropy(); for _ in 0..N_SAMPLES { let v: [f64; 3] = dist.sample(&mut rng); for i in 0..N_DIM { @@ -52,7 +46,7 @@ fn unit_circle() { use std::f64::consts::PI; let mut h = Histogram100::with_const_width(-PI, PI); let dist = rand_distr::UnitCircle; - let mut rng = rand::rngs::SmallRng::from_entropy(); + let mut rng = rand_pcg::Pcg32::from_entropy(); for _ in 0..N_SAMPLES { let v: [f64; 2] = dist.sample(&mut rng); h.add(v[0].atan2(v[1])).unwrap();