pub struct NeumaierSum<ScalarType> { /* private fields */ }Expand description
Neumaier compensated accumulator for sums of floating-point (real or complex) numbers.
Standard sequential summation loses precision when values of very different
magnitudes are added: a small addend can be completely swallowed by a much
larger running total. NeumaierSum corrects for this by maintaining a
compensation term that captures the low-order bits discarded at each step,
then folds them back into the result at the end.
NeumaierSum<T> implements SumAccumulator,
so it can be used directly as the accumulation strategy in the
norms vector-norm functions (e.g.,
vector_norm_l2_neumaier,
vector_norm_l1_neumaier).
§Example
use num_valid::algorithms::accumulators::*;
let mut neumaier = NeumaierSum::<f64>::new();
neumaier.push(1.0);
neumaier.push(1e100);
neumaier.push(1.0);
neumaier.push(-1e100);
let sum = neumaier.result();
println!("Sum: {}", sum);
assert_eq!(sum, 2.0);§References
Implementations§
Source§impl<ScalarType> NeumaierSum<ScalarType>
impl<ScalarType> NeumaierSum<ScalarType>
Sourcepub fn sum_before_compensation(&self) -> &ScalarType
pub fn sum_before_compensation(&self) -> &ScalarType
The sum before the compensation term is added.
Sourcepub fn compensation(&self) -> &ScalarType
pub fn compensation(&self) -> &ScalarType
The compensation term.
This is the correction term that is added to the sum_before_compensation to correct for the loss of precision.
Trait Implementations§
Source§impl<ScalarType> Accumulator for NeumaierSum<ScalarType>where
ScalarType: Clone + Zero + for<'a> Add<&'a ScalarType, Output = ScalarType> + for<'a> AddAssign<&'a ScalarType> + for<'a> Mul<&'a ScalarType, Output = ScalarType> + for<'a> MulAssign<&'a ScalarType> + NeumaierAddable,
impl<ScalarType> Accumulator for NeumaierSum<ScalarType>where
ScalarType: Clone + Zero + for<'a> Add<&'a ScalarType, Output = ScalarType> + for<'a> AddAssign<&'a ScalarType> + for<'a> Mul<&'a ScalarType, Output = ScalarType> + for<'a> MulAssign<&'a ScalarType> + NeumaierAddable,
Source§fn new_sequential<I>(values: I) -> Selfwhere
I: IntoIterator<Item = Self::Input>,
fn new_sequential<I>(values: I) -> Selfwhere
I: IntoIterator<Item = Self::Input>,
values. Read moreSource§fn new_parallel<I>(values: I) -> Self
fn new_parallel<I>(values: I) -> Self
Source§impl<ScalarType: Clone> Clone for NeumaierSum<ScalarType>
impl<ScalarType: Clone> Clone for NeumaierSum<ScalarType>
Source§fn clone(&self) -> NeumaierSum<ScalarType>
fn clone(&self) -> NeumaierSum<ScalarType>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<ScalarType: Debug> Debug for NeumaierSum<ScalarType>
impl<ScalarType: Debug> Debug for NeumaierSum<ScalarType>
Source§impl<ScalarType> SumAccumulator for NeumaierSum<ScalarType>where
ScalarType: Clone + Zero + for<'a> Add<&'a ScalarType, Output = ScalarType> + for<'a> AddAssign<&'a ScalarType> + for<'a> Mul<&'a ScalarType, Output = ScalarType> + for<'a> MulAssign<&'a ScalarType> + NeumaierAddable,
impl<ScalarType> SumAccumulator for NeumaierSum<ScalarType>where
ScalarType: Clone + Zero + for<'a> Add<&'a ScalarType, Output = ScalarType> + for<'a> AddAssign<&'a ScalarType> + for<'a> Mul<&'a ScalarType, Output = ScalarType> + for<'a> MulAssign<&'a ScalarType> + NeumaierAddable,
Source§fn rescale_by(&mut self, r: &Self::Input)
fn rescale_by(&mut self, r: &Self::Input)
r.Auto Trait Implementations§
impl<ScalarType> Freeze for NeumaierSum<ScalarType>where
ScalarType: Freeze,
impl<ScalarType> RefUnwindSafe for NeumaierSum<ScalarType>where
ScalarType: RefUnwindSafe,
impl<ScalarType> Send for NeumaierSum<ScalarType>where
ScalarType: Send,
impl<ScalarType> Sync for NeumaierSum<ScalarType>where
ScalarType: Sync,
impl<ScalarType> Unpin for NeumaierSum<ScalarType>where
ScalarType: Unpin,
impl<ScalarType> UnsafeUnpin for NeumaierSum<ScalarType>where
ScalarType: UnsafeUnpin,
impl<ScalarType> UnwindSafe for NeumaierSum<ScalarType>where
ScalarType: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more