Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Uniform constructors return a result #1229

Merged
merged 10 commits into from
Feb 6, 2023
Prev Previous commit
Next Next commit
Small fixes
  • Loading branch information
dhardy committed Feb 3, 2023
commit 6695abe4ba72ab30ecffb2fd82018a9ecd12db71
2 changes: 1 addition & 1 deletion examples/rayon-monte-carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static BATCH_SIZE: u64 = 10_000;
static BATCHES: u64 = 1000;

fn main() {
let range = Uniform::new(-1.0f64, 1.0);
let range = Uniform::new(-1.0f64, 1.0).unwrap();

let in_circle = (0..BATCHES)
.into_par_iter()
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
use core::fmt;
use core::time::Duration;
use core::ops::{Range, RangeInclusive};
use std::convert::TryFrom;
use core::convert::TryFrom;

use crate::distributions::float::IntoFloat;
use crate::distributions::utils::{BoolAsSIMD, FloatAsSIMD, FloatSIMDUtils, IntAsSIMD, WideningMultiply};
Expand Down
1 change: 0 additions & 1 deletion src/distributions/weighted_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ impl<X> Distribution<usize> for WeightedIndex<X>
where X: SampleUniform + PartialOrd
{
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize {
use ::core::cmp::Ordering;
let chosen_weight = self.weight_distribution.sample(rng);
// Find the first item which has a weight *higher* than the chosen weight.
self.cumulative_weights.partition_point(|w| w <= &chosen_weight)
Expand Down