Inline everything

This commit is contained in:
Vinzent Steinberg 2017-05-24 18:59:53 +02:00
parent 12c3fd76d1
commit c1af508205
4 changed files with 11 additions and 0 deletions

View File

@ -28,6 +28,7 @@ pub struct Average {
impl Average { impl Average {
/// Create a new average estimator. /// Create a new average estimator.
#[inline]
pub fn new() -> Average { pub fn new() -> Average {
Average { avg: 0., n: 0 } Average { avg: 0., n: 0 }
} }

View File

@ -28,6 +28,7 @@ pub struct Min {
impl Min { impl Min {
/// Create a new minium estimator from a given value. /// Create a new minium estimator from a given value.
#[inline]
pub fn from_value(x: f64) -> Min { pub fn from_value(x: f64) -> Min {
Min { Min {
r: Reduce::from_value_and_fn(x, min), r: Reduce::from_value_and_fn(x, min),
@ -35,16 +36,19 @@ impl Min {
} }
/// Create a new minimum estimator. /// Create a new minimum estimator.
#[inline]
pub fn new() -> Min { pub fn new() -> Min {
Min::from_value(::core::f64::INFINITY) Min::from_value(::core::f64::INFINITY)
} }
/// Add an element sampled from the population. /// Add an element sampled from the population.
#[inline]
pub fn add(&mut self, x: f64) { pub fn add(&mut self, x: f64) {
self.r.add(x); self.r.add(x);
} }
/// Estimate the minium of the population. /// Estimate the minium of the population.
#[inline]
pub fn min(&self) -> f64 { pub fn min(&self) -> f64 {
self.r.reduction() self.r.reduction()
} }
@ -65,6 +69,7 @@ impl Min {
/// min_left.merge(&min_right); /// min_left.merge(&min_right);
/// assert_eq!(min_total.min(), min_left.min()); /// assert_eq!(min_total.min(), min_left.min());
/// ``` /// ```
#[inline]
pub fn merge(&mut self, other: &Min) { pub fn merge(&mut self, other: &Min) {
self.r.merge(&other.r); self.r.merge(&other.r);
} }

View File

@ -14,21 +14,25 @@ impl<F> Reduce<F>
where F: Fn(f64, f64) -> f64 where F: Fn(f64, f64) -> f64
{ {
/// Create a new reduction estimator given an initial value and a reduction. /// Create a new reduction estimator given an initial value and a reduction.
#[inline]
pub fn from_value_and_fn(x: f64, f: F) -> Reduce<F> { pub fn from_value_and_fn(x: f64, f: F) -> Reduce<F> {
Reduce { x: x, reduce: f } Reduce { x: x, reduce: f }
} }
/// Add an element sampled from the population. /// Add an element sampled from the population.
#[inline]
pub fn add(&mut self, x: f64) { pub fn add(&mut self, x: f64) {
self.x = (self.reduce)(self.x, x); self.x = (self.reduce)(self.x, x);
} }
/// Estimate the reduction of the population. /// Estimate the reduction of the population.
#[inline]
pub fn reduction(&self) -> f64 { pub fn reduction(&self) -> f64 {
self.x self.x
} }
/// Merge another sample into this one. /// Merge another sample into this one.
#[inline]
pub fn merge(&mut self, other: &Reduce<F>) { pub fn merge(&mut self, other: &Reduce<F>) {
self.add(other.x); self.add(other.x);
} }

View File

@ -140,6 +140,7 @@ pub struct WeightedAverageWithError {
impl WeightedAverageWithError { impl WeightedAverageWithError {
/// Create a new weighted and unweighted average estimator. /// Create a new weighted and unweighted average estimator.
#[inline]
pub fn new() -> WeightedAverageWithError { pub fn new() -> WeightedAverageWithError {
WeightedAverageWithError { WeightedAverageWithError {
weight_sum_sq: 0., weight_sum_sq: 0.,