Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
vari.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__REV__VARI_HPP__
2 #define __STAN__AGRAD__REV__VARI_HPP__
3 
4 #include <ostream>
5 
8 
9 namespace stan {
10  namespace agrad {
11 
12  // forward declaration of var
13  class var;
14 
28  class vari : public chainable {
29  private:
30  friend class var;
31 
32  public:
33 
37  const double val_;
38 
43  double adj_;
44 
57  vari(const double x):
58  val_(x),
59  adj_(0.0) {
60  var_stack_.push_back(this);
61  }
62 
63  vari(const double x,bool stacked):
64  val_(x),
65  adj_(0.0) {
66  if (stacked)
67  var_stack_.push_back(this);
68  else
69  var_nochain_stack_.push_back(this);
70  }
71 
79  ~vari() {
80  // throw std::logic_error("vari destruction handled automatically");
81  }
82 
88  virtual void init_dependent() {
89  adj_ = 1.0; // droot/droot = 1
90  }
91 
95  virtual void set_zero_adjoint() {
96  adj_ = 0.0;
97  }
98 
108  friend std::ostream& operator<<(std::ostream& os, const vari* v) {
109  return os << v << " " << v->val_ << " : " << v->adj_;
110  }
111  };
112 
113  }
114 }
115 #endif

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