Skip to content

Commit 24748cc

Browse files
committed
Upgrade rand to 0.9 and adjust implementation accordingly
1 parent f12eac7 commit 24748cc

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "hammer-and-sample"
33
description = "Simplistic MCMC ensemble sampler based on emcee, the MCMC hammer"
4-
version = "0.2.0"
4+
version = "0.3.0"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
readme = "README.md"
@@ -14,12 +14,12 @@ categories = ["science", "mathematics", "algorithms"]
1414
test = false
1515

1616
[dependencies]
17-
rand = { version = "0.8", default-features = false }
17+
rand = { version = "0.9", default-features = false }
1818
rayon = { version = "1.5", optional = true }
1919

2020
[dev-dependencies]
21-
rand_distr = "0.4"
22-
rand_pcg = "0.3"
21+
rand_distr = "0.5"
22+
rand_pcg = "0.9"
2323

2424
[package.metadata.docs.rs]
2525
all-features = true

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use std::ops::ControlFlow;
5151

5252
use rand::{
53-
distributions::{Distribution, Standard, Uniform},
53+
distr::{Distribution, StandardUniform, Uniform},
5454
Rng,
5555
};
5656
#[cfg(feature = "rayon")]
@@ -158,7 +158,7 @@ where
158158
let half = walkers.len() / 2;
159159
let (lower_half, upper_half) = walkers.split_at_mut(half);
160160

161-
let random_index = Uniform::new(0, half);
161+
let random_index = Uniform::new(0, half).unwrap();
162162

163163
let update_walker = move |walker: &mut Walker<M, R>, other_walkers: &[Walker<M, R>]| {
164164
let other = &other_walkers[random_index.sample(&mut walker.rng)];
@@ -232,7 +232,7 @@ fn gen_unit<R>(rng: &mut R) -> f64
232232
where
233233
R: Rng,
234234
{
235-
Standard.sample(rng)
235+
StandardUniform.sample(rng)
236236
}
237237

238238
/// Estimate the integrated auto-correlation time

tests/coin_flip.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rand::{
2-
distributions::{Bernoulli, Distribution, Standard},
2+
distr::{Bernoulli, Distribution, StandardUniform},
33
SeedableRng,
44
};
55
use rand_pcg::Pcg64Mcg;
@@ -41,9 +41,9 @@ fn coin_flip() {
4141
};
4242

4343
let walkers = (0..100).map(|_| {
44-
let mut rng = Pcg64Mcg::from_rng(&mut rng).unwrap();
44+
let mut rng = Pcg64Mcg::from_rng(&mut rng);
4545

46-
let guess_p = Distribution::<f64>::sample(&Standard, &mut rng);
46+
let guess_p = Distribution::<f64>::sample(&StandardUniform, &mut rng);
4747

4848
([guess_p], rng)
4949
});

tests/hierarchical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn hierarchical() {
9696
let prior_sigma = Normal::<f64>::new(0., 2.).unwrap();
9797

9898
let walkers = (0..WALKERS).map(|_| {
99-
let mut rng = Pcg64Mcg::from_rng(&mut rng).unwrap();
99+
let mut rng = Pcg64Mcg::from_rng(&mut rng);
100100

101101
let guess_logit_theta = prior_logit_theta.sample(&mut rng);
102102
let guess_sigma = prior_sigma.sample(&mut rng).abs();

0 commit comments

Comments
 (0)