Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sum_values.hpp
Go to the documentation of this file.
1 #ifndef STAN__COMMON__RECORDER__SUM_VALUES_HPP
2 #define STAN__COMMON__RECORDER__SUM_VALUES_HPP
3 
4 #include <vector>
5 #include <stdexcept>
6 #include <string>
7 
8 namespace stan {
9  namespace common {
10  namespace recorder {
11 
12  class sum_values {
13  public:
14  sum_values(const size_t N)
15  : N_(N), m_(0), skip_(0), sum_(N_, 0.0) { }
16 
17  sum_values(const size_t N, const size_t skip)
18  : N_(N), m_(0), skip_(skip), sum_(N_, 0.0) { }
19 
20 
27  void operator()(const std::vector<std::string>& x) {
28  }
29 
36  template <class T>
37  void operator()(const std::vector<T>& x) {
38  if (N_ != x.size())
39  throw std::length_error("vector provided does not match the parameter length");
40  if (m_ >= skip_)
41  for (size_t n = 0; n < N_; n++) {
42  sum_[n] += x[n];
43  }
44  m_++;
45  }
46 
47 
53  void operator()(const std::string x) { }
54 
59  void operator()() { }
60 
64  bool is_recording() const {
65  return true;
66  }
67 
68  const std::vector<double>& sum() const {
69  return sum_;
70  }
71 
72  const size_t called() const {
73  return m_;
74  }
75 
76  const size_t recorded() const {
77  if (m_ >= skip_)
78  return m_ - skip_;
79  else
80  return 0;
81  }
82 
83 
84  private:
85  size_t N_;
86  size_t m_;
87  size_t skip_;
88  std::vector<double> sum_;
89  };
90 
91  }
92  }
93 }
94 
95 #endif
bool is_recording() const
Indicator function for whether the instance is recording.
Definition: sum_values.hpp:64
sum_values(const size_t N, const size_t skip)
Definition: sum_values.hpp:17
void operator()(const std::vector< T > &x)
Add values to cumulative sum.
Definition: sum_values.hpp:37
const size_t called() const
Definition: sum_values.hpp:72
void operator()(const std::string x)
Do nothing with a string.
Definition: sum_values.hpp:53
const std::vector< double > & sum() const
Definition: sum_values.hpp:68
const size_t recorded() const
Definition: sum_values.hpp:76
void operator()(const std::vector< std::string > &x)
Do nothing with std::string vector.
Definition: sum_values.hpp:27

     [ Stan Home Page ] © 2011–2014, Stan Development Team.