DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
statsutils.h
Go to the documentation of this file.
1 #ifndef STATSUTILS_H
2 #define STATSUTILS_H
3 
4 namespace stats {
5 
6 template <typename T, template<typename,typename> class Container>
7 inline void runningSum(Container<T, std::allocator<T>> &s)
8 {
9  T sum = 0;
10  for (auto &v : s) {
11  sum += v;
12  v = sum;
13  }
14 }
15 
16 template <typename T, template<typename,typename> class Container>
17 inline void runningAvg(Container<T, std::allocator<T>> &s)
18 {
19  size_t n = 0;
20  T sum = 0;
21  for (auto &v : s) {
22  ++n;
23  sum += v;
24  v = sum / static_cast<T>(n);
25  }
26 }
27 
28 
29 }
30 
31 #endif // STATSUTILS_H
Definition: statsutils.h:4
void runningSum(Container< T, std::allocator< T >> &s)
Definition: statsutils.h:7
void runningAvg(Container< T, std::allocator< T >> &s)
Definition: statsutils.h:17