Skip to content

Commit

Permalink
rand_distr: use Pcg32 in uniformity test and update the two new test …
Browse files Browse the repository at this point in the history
…vectors
  • Loading branch information
dhardy committed May 23, 2019
1 parent 66c22e0 commit a1445a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
6 changes: 3 additions & 3 deletions rand_distr/src/unit_ball.rs
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions rand_distr/src/unit_disc.rs
Expand Up @@ -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),
Expand Down
12 changes: 3 additions & 9 deletions rand_distr/tests/uniformity.rs
Expand Up @@ -6,20 +6,14 @@
// 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;

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]
Expand All @@ -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 {
Expand All @@ -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();
Expand Down

0 comments on commit a1445a2

Please sign in to comment.