Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
maratik123 committed Jun 15, 2024
1 parent 5a7fc8a commit 79e3ced
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ mod distribution;
mod float;
mod integer;
mod other;
#[cfg(feature = "alloc")]
mod reusable_weighted_index;
mod slice;
mod utils;
#[cfg(feature = "alloc")]
mod weighted_index;
#[cfg(feature = "alloc")]
mod reusable_weighted_index;

#[doc(hidden)]
pub mod hidden_export {
Expand All @@ -117,13 +117,13 @@ pub use self::distribution::DistString;
pub use self::distribution::{DistIter, DistMap, Distribution};
pub use self::float::{Open01, OpenClosed01};
pub use self::other::Alphanumeric;
#[cfg(feature = "alloc")]
pub use self::reusable_weighted_index::{CumulativeWeightsWrapper, ReusableWeightedIndex};
pub use self::slice::Slice;
#[doc(inline)]
pub use self::uniform::Uniform;
#[cfg(feature = "alloc")]
pub use self::weighted_index::{Weight, WeightError, WeightedIndex};
#[cfg(feature = "alloc")]
pub use self::reusable_weighted_index::{CumulativeWeightsWrapper, ReusableWeightedIndex};

#[allow(unused)]
use crate::Rng;
Expand Down
18 changes: 8 additions & 10 deletions src/distributions/reusable_weighted_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//! Reusable weighted index sampling

use crate::distributions::uniform::{SampleBorrow, SampleUniform, UniformSampler};
use crate::distributions::{Distribution, Weight};
use crate::distributions::weighted_index::WeightError;
use crate::distributions::{Distribution, Weight};
use crate::Rng;

// Note that this whole module is only imported if feature="alloc" is enabled.
Expand Down Expand Up @@ -136,18 +136,19 @@ impl<X: SampleUniform + PartialOrd + Default> CumulativeWeightsWrapper<X> {
/// if any weight is `< 0`, or if its total value is 0
///
/// [`Uniform<X>`]: crate::distributions::uniform::Uniform
pub fn fill<I>(
&mut self,
weights: I,
) -> Result<ReusableWeightedIndex<X>, WeightError>
pub fn fill<I>(&mut self, weights: I) -> Result<ReusableWeightedIndex<X>, WeightError>
where
I: IntoIterator,
I::Item: SampleBorrow<X>,
X: Weight,
{
self.cumulative_weights.clear();
let mut iter = weights.into_iter();
let mut total_weight: X = iter.next().ok_or(WeightError::InvalidInput)?.borrow().clone();
let mut total_weight: X = iter
.next()
.ok_or(WeightError::InvalidInput)?
.borrow()
.clone();
let zero = X::ZERO;

if matches!(total_weight.partial_cmp(&zero), None | Some(Ordering::Less)) {
Expand Down Expand Up @@ -287,10 +288,7 @@ mod test {
distr_w.fill([-10, 20, 1, 30]).unwrap_err(),
WeightError::InvalidWeight
);
assert_eq!(
distr_w.fill([-10]).unwrap_err(),
WeightError::InvalidWeight
);
assert_eq!(distr_w.fill([-10]).unwrap_err(), WeightError::InvalidWeight);
}

#[test]
Expand Down

0 comments on commit 79e3ced

Please sign in to comment.