Add count, sum, and mean for stats accumulator
This commit is contained in:
parent
ee6fb59e99
commit
e8844943a7
15
stats.cpp
15
stats.cpp
@ -25,8 +25,10 @@
|
||||
|
||||
template <typename T>
|
||||
util::stats::accumulator<T>::accumulator ():
|
||||
count (0),
|
||||
min (std::numeric_limits<T>::max ()),
|
||||
max (std::numeric_limits<T>::min ())
|
||||
max (std::numeric_limits<T>::min ()),
|
||||
sum (0)
|
||||
{ ; }
|
||||
|
||||
|
||||
@ -35,6 +37,9 @@ void
|
||||
util::stats::accumulator<T>::add (T val) {
|
||||
min = std::min (val, min);
|
||||
max = std::max (val, max);
|
||||
sum += val;
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +48,8 @@ void
|
||||
util::stats::accumulator<T>::add (const accumulator<T> &rhs) {
|
||||
min = std::min (rhs.min, min);
|
||||
max = std::max (rhs.max, max);
|
||||
sum += rhs.sum;
|
||||
count += rhs.count;
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +59,12 @@ util::stats::accumulator<T>::range (void) const
|
||||
{ return max - min; }
|
||||
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
util::stats::accumulator<T>::mean (void) const
|
||||
{ return sum / count; }
|
||||
|
||||
|
||||
template struct util::stats::accumulator<double>;
|
||||
template struct util::stats::accumulator<float>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user