Skip to content

Commit

Permalink
fix: sampling should use DistIter, but not collect it
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungOnion committed Dec 3, 2024
1 parent 2992dec commit c2dea67
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/random_clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,24 @@ 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)?);
let sample_iter = thread_rng().sample_iter(Multinomial::new(p, n)?);
print_multivariate_samples(
count,
samples.map(|v: na::DVector<u64>| {
sample_iter.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: Vec<u64> = thread_rng().sample_iter(Binomial::new(p, n)?).collect();
print_samples(count, samples)?;
let sample_iter = thread_rng().sample_iter::<u64, Binomial>(Binomial::new(p, n)?);
print_samples(count, sample_iter)?;
}
// normal should print `count` of float
DistributionAsCommand::Normal { mu, sigma } => {
let samples = thread_rng().sample_iter(Normal::new(mu, sigma)?);
print_samples(count, samples)?
let sample_iter = thread_rng().sample_iter(Normal::new(mu, sigma)?);
print_samples(count, sample_iter)?
}
}

Expand Down

0 comments on commit c2dea67

Please sign in to comment.