Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
operator_addition.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__REV__OPERATOR_ADDITION_HPP__
2 #define __STAN__AGRAD__REV__OPERATOR_ADDITION_HPP__
3 
4 #include <stan/agrad/rev/var.hpp>
7 
8 namespace stan {
9  namespace agrad {
10 
11  namespace {
12  class add_vv_vari : public op_vv_vari {
13  public:
14  add_vv_vari(vari* avi, vari* bvi) :
15  op_vv_vari(avi->val_ + bvi->val_, avi, bvi) {
16  }
17  void chain() {
18  avi_->adj_ += adj_;
19  bvi_->adj_ += adj_;
20  }
21  };
22 
23  class add_vd_vari : public op_vd_vari {
24  public:
25  add_vd_vari(vari* avi, double b) :
26  op_vd_vari(avi->val_ + b, avi, b) {
27  }
28  void chain() {
29  avi_->adj_ += adj_;
30  }
31  };
32  }
33 
47  inline var operator+(const var& a, const var& b) {
48  return var(new add_vv_vari(a.vi_,b.vi_));
49  }
50 
62  inline var operator+(const var& a, const double b) {
63  if (b == 0.0)
64  return a;
65  return var(new add_vd_vari(a.vi_,b));
66  }
67 
79  inline var operator+(const double a, const var& b) {
80  if (a == 0.0)
81  return b;
82  return var(new add_vd_vari(b.vi_,a)); // by symmetry
83  }
84 
85  }
86 }
87 #endif

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