Stan Math Library: stan/math/rev/scal/fun/atan2.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

atan2.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_ATAN2_HPP
2 #define STAN_MATH_REV_SCAL_FUN_ATAN2_HPP
3
4 #include <stan/math/rev/core.hpp>
5 #include <cmath>
6 #include <valarray>
7
8 namespace stan {
9 namespace math {
10
11 namespace {
12 class atan2_vv_vari : public op_vv_vari {
13 public:
14 atan2_vv_vari(vari* avi, vari* bvi) :
15 op_vv_vari(std::atan2(avi->val_, bvi->val_), avi, bvi) {
16 }
17 void chain() {
18 double a_sq_plus_b_sq = (avi_->val_ * avi_->val_)
19 + (bvi_->val_ * bvi_->val_);
20 avi_->adj_ += adj_ * bvi_->val_ / a_sq_plus_b_sq;
21 bvi_->adj_ -= adj_ * avi_->val_ / a_sq_plus_b_sq;
22 }
23 };
24
25 class atan2_vd_vari : public op_vd_vari {
26 public:
27 atan2_vd_vari(vari* avi, double b) :
28 op_vd_vari(std::atan2(avi->val_, b), avi, b) {
29 }
30 void chain() {
31 double a_sq_plus_b_sq = (avi_->val_ * avi_->val_) + (bd_ * bd_);
32 avi_->adj_ += adj_ * bd_ / a_sq_plus_b_sq;
33 }
34 };
35
36 class atan2_dv_vari : public op_dv_vari {
37 public:
38 atan2_dv_vari(double a, vari* bvi) :
39 op_dv_vari(std::atan2(a, bvi->val_), a, bvi) {
40 }
41 void chain() {
42 double a_sq_plus_b_sq = (ad_ * ad_) + (bvi_->val_ * bvi_->val_);
43 bvi_->adj_ -= adj_ * ad_ / a_sq_plus_b_sq;
44 }
45 };
46 }
47
62 inline var atan2(const var& a, const var& b) {
63 return var(new atan2_vv_vari(a.vi_, b.vi_));
64 }
65
78 inline var atan2(const var& a, const double b) {
79 return var(new atan2_vd_vari(a.vi_, b));
80 }
81
119 inline var atan2(const double a, const var& b) {
120 return var(new atan2_dv_vari(a, b.vi_));
121 }
122
123 }
124 }
125 #endif
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::atan2
fvar< T > atan2(const fvar< T > &x1, const fvar< T > &x2)
Definition: atan2.hpp:12
std
Definition: std_numeric_limits.hpp:7
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43

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