Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
fmod.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__REV__FMOD_HPP__
2 #define __STAN__AGRAD__REV__FMOD_HPP__
3 
4 #include <cmath>
5 #include <stan/agrad/rev/var.hpp>
9 
10 namespace stan {
11  namespace agrad {
12 
13  namespace {
14  class fmod_vv_vari : public op_vv_vari {
15  public:
16  fmod_vv_vari(vari* avi, vari* bvi) :
17  op_vv_vari(std::fmod(avi->val_,bvi->val_),avi,bvi) {
18  }
19  void chain() {
20  avi_->adj_ += adj_;
21  bvi_->adj_ -= adj_ * static_cast<int>(avi_->val_ / bvi_->val_);
22  }
23  };
24 
25  class fmod_vd_vari : public op_v_vari {
26  public:
27  fmod_vd_vari(vari* avi, double b) :
28  op_v_vari(std::fmod(avi->val_,b),avi) {
29  }
30  void chain() {
31  avi_->adj_ += adj_;
32  }
33  };
34 
35  class fmod_dv_vari : public op_dv_vari {
36  public:
37  fmod_dv_vari(double a, vari* bvi) :
38  op_dv_vari(std::fmod(a,bvi->val_),a,bvi) {
39  }
40  void chain() {
41  int d = static_cast<int>(ad_ / bvi_->val_);
42  bvi_->adj_ -= adj_ * d;
43  }
44  };
45  }
46 
64  inline var fmod(const var& a, const var& b) {
65  return var(new fmod_vv_vari(a.vi_,b.vi_));
66  }
67 
81  inline var fmod(const var& a, const double b) {
82  return var(new fmod_vd_vari(a.vi_,b));
83  }
84 
98  inline var fmod(const double a, const var& b) {
99  return var(new fmod_dv_vari(a,b.vi_));
100  }
101 
102  }
103 }
104 #endif

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