Improve performance by making sure add is inlined

This commit is contained in:
Vinzent Steinberg 2017-05-23 21:10:50 +02:00
parent 262d5c88da
commit 4fa92eb9e0
2 changed files with 2 additions and 0 deletions

View File

@ -37,6 +37,7 @@ impl Average {
}
/// Add an element sampled from the population.
#[inline]
pub fn add(&mut self, sample: f64) {
// This algorithm introduced by Welford in 1962 trades numerical
// stability for a division inside the loop.

View File

@ -40,6 +40,7 @@ impl WeightedAverage {
}
/// Add a weighted element sampled from the population.
#[inline]
pub fn add(&mut self, sample: f64, weight: f64) {
// The algorithm for the unweighted average was suggested by Welford in 1962.
// The algorithm for the weighted average was suggested by West in 1979.