Skip to content

Commit

Permalink
Revert CDF test
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Oct 24, 2024
1 parent af3251c commit 6e8f8d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rand_distr/src/zipf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rand::Rng;
/// use rand::prelude::*;
/// use rand_distr::Zipf;
///
/// let val: f64 = rand::rng().sample(Zipf::new(10, 1.5).unwrap());
/// let val: f64 = rand::rng().sample(Zipf::new(10.0, 1.5).unwrap());
/// println!("{}", val);
/// ```
///
Expand Down
15 changes: 7 additions & 8 deletions rand_distr/tests/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,21 @@ fn zeta() {

#[test]
fn zipf() {
fn cdf(k: f64, n: f64, s: f64) -> f64 {
debug_assert!(k.fract() == 0.0 && k < u64::MAX as f64);
if k < 1.0 {
fn cdf(k: i64, n: u64, s: f64) -> f64 {
if k < 1 {
return 0.0;
}
if k > n {
if k > n as i64 {
return 1.0;
}
gen_harmonic(k as u64, s) / gen_harmonic(n as u64, s)
gen_harmonic(k as u64, s) / gen_harmonic(n, s)
}

let parameters = [(1000.0, 1.0), (500.0, 2.0), (1000.0, 0.5)];
let parameters = [(1000, 1.0), (500, 2.0), (1000, 0.5)];

for (seed, (n, x)) in parameters.into_iter().enumerate() {
let dist = rand_distr::Zipf::new(n, x).unwrap();
test_continuous(seed as u64, dist, |k| cdf(k, n, x));
let dist = rand_distr::Zipf::new(n as f64, x).unwrap();
test_discrete(seed as u64, dist, |k| cdf(k, n, x));
}
}

Expand Down

0 comments on commit 6e8f8d8

Please sign in to comment.