Skip to content

Commit

Permalink
fix: specify type sampled after merging #155
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungOnion committed Sep 24, 2024
1 parent acbd302 commit 0457e05
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/random_clap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate statrs;

use nalgebra as na;
use rand::{thread_rng, Rng};
use statrs::distribution::{Binomial, Continuous, Discrete, Multinomial, Normal};
use statrs::statistics::Mode;
Expand Down Expand Up @@ -158,14 +159,18 @@ fn run_command_sample(count: Option<usize>, dist: DistributionAsCommand) -> Resu
match dist {
// multinomial should print `count` of Vec<uint>
DistributionAsCommand::Multinomial { n, p } => {
let samples = thread_rng()
.sample_iter(Multinomial::new(p, n)?)
.map(|v| Into::<Vec<_>>::into(v.data));
print_multivariate_samples(count, samples.map(|v| v.into_iter().map(|x| x as usize)))?
let samples = thread_rng().sample_iter(Multinomial::new(p, n)?);
print_multivariate_samples(
count,
samples.map(|v: na::DVector<u64>| {
let vec: Vec<_> = v.into_iter().cloned().collect();
vec
}),
)?;
}
// binomial should print `count` of uint
DistributionAsCommand::Binomial { n, p } => {
let samples = thread_rng().sample_iter(Binomial::new(p, n)?);
let samples: Vec<u64> = thread_rng().sample_iter(Binomial::new(p, n)?).collect();
print_samples(count, samples)?;
}
// normal should print `count` of float
Expand Down

0 comments on commit 0457e05

Please sign in to comment.