Add note about floating point weights in update_weights docs (#1280)

This commit is contained in:
Arya 2023-02-02 04:30:08 -05:00 committed by GitHub
parent 4bde8a0adb
commit ae4b48ece8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,6 +141,10 @@ impl<X: SampleUniform + PartialOrd> WeightedIndex<X> {
/// allocation internally.
///
/// In case of error, `self` is not modified.
///
/// Note: Updating floating-point weights may cause slight inaccuracies in the total weight.
/// This method may not return `WeightedError::AllWeightsZero` when all weights
/// are zero if using floating-point weights.
pub fn update_weights(&mut self, new_weights: &[(usize, &X)]) -> Result<(), WeightedError>
where X: for<'a> ::core::ops::AddAssign<&'a X>
+ for<'a> ::core::ops::SubAssign<&'a X>