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>
|
template <typename T>
|
||||||
util::stats::accumulator<T>::accumulator ():
|
util::stats::accumulator<T>::accumulator ():
|
||||||
|
count (0),
|
||||||
min (std::numeric_limits<T>::max ()),
|
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) {
|
util::stats::accumulator<T>::add (T val) {
|
||||||
min = std::min (val, min);
|
min = std::min (val, min);
|
||||||
max = std::max (val, max);
|
max = std::max (val, max);
|
||||||
|
sum += val;
|
||||||
|
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,6 +48,8 @@ void
|
|||||||
util::stats::accumulator<T>::add (const accumulator<T> &rhs) {
|
util::stats::accumulator<T>::add (const accumulator<T> &rhs) {
|
||||||
min = std::min (rhs.min, min);
|
min = std::min (rhs.min, min);
|
||||||
max = std::max (rhs.max, max);
|
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; }
|
{ 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<double>;
|
||||||
template struct util::stats::accumulator<float>;
|
template struct util::stats::accumulator<float>;
|
||||||
|
|
||||||
|
@ -34,10 +34,14 @@ namespace util {
|
|||||||
void add (T);
|
void add (T);
|
||||||
void add (const accumulator<T> &);
|
void add (const accumulator<T> &);
|
||||||
|
|
||||||
|
size_t count;
|
||||||
|
|
||||||
T min;
|
T min;
|
||||||
T max;
|
T max;
|
||||||
|
T sum;
|
||||||
|
|
||||||
T range (void) const;
|
T range (void) const;
|
||||||
|
T mean (void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
Loading…
Reference in New Issue
Block a user