Skip to content

Commit 27f1ff5

Browse files
authored
bump rand/rand_distr versions (#265)
1 parent 8284042 commit 27f1ff5

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

forrustts-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ keywords = ["simulation", "tree_sequences", "tskit", "population_genetics"]
1414
[dependencies]
1515
thiserror = "1.0"
1616
# NOTE: automagically adds rand as a cargo feature
17-
rand = { version = "0.8.5", optional = true }
17+
rand = { version = "0.9.0", optional = true }
1818

1919
[dev-dependencies]
2020
proptest = "1.1.0"

forrustts-core/src/rand_position.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rand::distributions::uniform::{SampleBorrow, SampleUniform, UniformInt, UniformSampler};
1+
use rand::distr::uniform::{SampleBorrow, SampleUniform, UniformInt, UniformSampler};
22
use rand::prelude::Rng;
33

44
use crate::Position;
@@ -9,25 +9,25 @@ pub struct UniformPos(UniformInt<i64>);
99

1010
impl UniformSampler for UniformPos {
1111
type X = Position;
12-
fn new<B1, B2>(low: B1, high: B2) -> Self
12+
fn new<B1, B2>(low: B1, high: B2) -> Result<Self, rand::distr::uniform::Error>
1313
where
1414
B1: SampleBorrow<Self::X> + Sized,
1515
B2: SampleBorrow<Self::X> + Sized,
1616
{
17-
UniformPos(UniformInt::<i64>::new(
17+
Ok(UniformPos(UniformInt::<i64>::new(
1818
i64::from(*low.borrow()),
1919
i64::from(*high.borrow()),
20-
))
20+
)?))
2121
}
22-
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
22+
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Result<Self, rand::distr::uniform::Error>
2323
where
2424
B1: SampleBorrow<Self::X> + Sized,
2525
B2: SampleBorrow<Self::X> + Sized,
2626
{
27-
UniformPos(UniformInt::<i64>::new_inclusive(
27+
Ok(UniformPos(UniformInt::<i64>::new_inclusive(
2828
i64::from(*low.borrow()),
2929
i64::from(*high.borrow()),
30-
))
30+
)?))
3131
}
3232
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
3333
Position::new_valid(self.0.sample(rng))

forrustts-core/tests/tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
mod test_rand_traits {
33
use forrustts_core::Position;
44
use proptest::prelude::*;
5+
use rand::Rng;
56
use rand::SeedableRng;
67

78
proptest! {
@@ -11,7 +12,7 @@ mod test_rand_traits {
1112
if a != b { // else rand will panic
1213
let lo = Position::new_valid(std::cmp::min(a, b));
1314
let hi = Position::new_valid(std::cmp::max(a, b));
14-
let upos = rand::distributions::Uniform::<Position>::new(lo, hi);
15+
let upos = rand::distr::Uniform::<Position>::new(lo, hi).unwrap();
1516
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
1617
for _ in 0..100 {
1718
let _ = rng.sample(upos);
@@ -27,7 +28,7 @@ mod test_rand_traits {
2728
if a != b { // else rand will panic
2829
let lo = Position::new_valid(std::cmp::min(a, b));
2930
let hi = Position::new_valid(std::cmp::max(a, b));
30-
let upos = rand::distributions::Uniform::<Position>::new_inclusive(lo, hi);
31+
let upos = rand::distr::Uniform::<Position>::new_inclusive(lo, hi).unwrap();
3132
let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
3233
for _ in 0..100 {
3334
let _ = rng.sample(upos);

forrustts-genetics/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ keywords = ["simulation", "tree_sequences", "tskit", "population_genetics"]
1313

1414
[dependencies]
1515
forrustts-core = { version = "0.1.0", path = "../forrustts-core", features = ["rand"]}
16-
rand = "0.8.5"
17-
rand_distr = "0.4.3"
16+
rand = "0.9.0"
17+
rand_distr = "0.5.0"

forrustts-genetics/src/genetic_maps.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl GeneticMapBuilder {
238238
#[derive(Debug)]
239239
struct PoissonRegions {
240240
regions: Vec<rand_distr::Uniform<Position>>,
241-
lookup: rand_distr::WeightedAliasIndex<f64>,
241+
lookup: rand_distr::weighted::WeightedAliasIndex<f64>,
242242
poisson: rand_distr::Poisson<f64>,
243243
}
244244

@@ -250,13 +250,13 @@ impl PoissonRegions {
250250
for p in poisson {
251251
let mean = p.mean();
252252
if mean > 0.0 {
253-
let u = rand_distr::Uniform::new(p.left(), p.right());
253+
let u = rand_distr::Uniform::new(p.left(), p.right()).ok()?;
254254
regions.push(u);
255255
weights.push(mean);
256256
sum_poisson_means += mean;
257257
}
258258
}
259-
let lookup = rand_distr::WeightedAliasIndex::new(weights).ok()?;
259+
let lookup = rand_distr::weighted::WeightedAliasIndex::new(weights).ok()?;
260260
let poisson = rand_distr::Poisson::new(sum_poisson_means).ok()?;
261261
Some(Self {
262262
regions,
@@ -285,7 +285,7 @@ impl BernoulliRegions {
285285
for b in binomial {
286286
let prob = b.probability();
287287
if prob > 0.0 {
288-
let u = rand_distr::Uniform::new(b.left(), b.right());
288+
let u = rand_distr::Uniform::new(b.left(), b.right()).ok()?;
289289
regions.push(u);
290290
let dist = rand_distr::Bernoulli::new(prob).ok()?;
291291
probabilities.push(dist);
@@ -357,7 +357,7 @@ impl GenerateBreakpoints for GeneticMap {
357357
}
358358
}
359359
}
360-
let uint = rand_distr::Uniform::new(0., 1.);
360+
let uint = rand_distr::Uniform::new(0., 1.).unwrap();
361361
for i in self.independent_assortment.iter() {
362362
if rng.sample(uint) < 0.5 {
363363
self.breakpoints.push(i.at());

0 commit comments

Comments
 (0)