Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
atan2.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__ATAN2_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__ATAN2_HPP
3 
4 #include <valarray>
5 #include <stan/agrad/rev/var.hpp>
9 #include <math.h>
10 
11 namespace stan {
12  namespace agrad {
13 
14  namespace {
15  class atan2_vv_vari : public op_vv_vari {
16  public:
17  atan2_vv_vari(vari* avi, vari* bvi) :
18  op_vv_vari(::atan2(avi->val_,bvi->val_),avi,bvi) {
19  }
20  void chain() {
21  double a_sq_plus_b_sq = (avi_->val_ * avi_->val_) + (bvi_->val_ * bvi_->val_);
22  avi_->adj_ += adj_ * bvi_->val_ / a_sq_plus_b_sq;
23  bvi_->adj_ -= adj_ * avi_->val_ / a_sq_plus_b_sq;
24  }
25  };
26 
27  class atan2_vd_vari : public op_vd_vari {
28  public:
29  atan2_vd_vari(vari* avi, double b) :
30  op_vd_vari(::atan2(avi->val_,b),avi,b) {
31  }
32  void chain() {
33  double a_sq_plus_b_sq = (avi_->val_ * avi_->val_) + (bd_ * bd_);
34  avi_->adj_ += adj_ * bd_ / a_sq_plus_b_sq;
35  }
36  };
37 
38  class atan2_dv_vari : public op_dv_vari {
39  public:
40  atan2_dv_vari(double a, vari* bvi) :
41  op_dv_vari(::atan2(a,bvi->val_),a,bvi) {
42  }
43  void chain() {
44  double a_sq_plus_b_sq = (ad_ * ad_) + (bvi_->val_ * bvi_->val_);
45  bvi_->adj_ -= adj_ * ad_ / a_sq_plus_b_sq;
46  }
47  };
48  }
49 
64  inline var atan2(const var& a, const var& b) {
65  return var(new atan2_vv_vari(a.vi_,b.vi_));
66  }
67 
80  inline var atan2(const var& a, const double b) {
81  return var(new atan2_vd_vari(a.vi_,b));
82  }
83 
121  inline var atan2(const double a, const var& b) {
122  return var(new atan2_dv_vari(a,b.vi_));
123  }
124 
125  }
126 }
127 #endif
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
fvar< T > atan2(const fvar< T > &x1, const fvar< T > &x2)
Definition: atan2.hpp:16
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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