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

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