All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
atan2.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_SCAL_FUN_ATAN2_HPP
#define STAN_MATH_REV_SCAL_FUN_ATAN2_HPP
#include <stan/math/rev/core.hpp>
#include <cmath>
#include <valarray>
namespace stan {
namespace math {
namespace {
class atan2_vv_vari : public op_vv_vari {
public:
atan2_vv_vari(vari* avi, vari* bvi) :
op_vv_vari(std::atan2(avi->val_, bvi->val_), avi, bvi) {
}
void chain() {
double a_sq_plus_b_sq = (avi_->val_ * avi_->val_)
+ (bvi_->val_ * bvi_->val_);
avi_->adj_ += adj_ * bvi_->val_ / a_sq_plus_b_sq;
bvi_->adj_ -= adj_ * avi_->val_ / a_sq_plus_b_sq;
}
};
class atan2_vd_vari : public op_vd_vari {
public:
atan2_vd_vari(vari* avi, double b) :
op_vd_vari(std::atan2(avi->val_, b), avi, b) {
}
void chain() {
double a_sq_plus_b_sq = (avi_->val_ * avi_->val_) + (bd_ * bd_);
avi_->adj_ += adj_ * bd_ / a_sq_plus_b_sq;
}
};
class atan2_dv_vari : public op_dv_vari {
public:
atan2_dv_vari(double a, vari* bvi) :
op_dv_vari(std::atan2(a, bvi->val_), a, bvi) {
}
void chain() {
double a_sq_plus_b_sq = (ad_ * ad_) + (bvi_->val_ * bvi_->val_);
bvi_->adj_ -= adj_ * ad_ / a_sq_plus_b_sq;
}
};
}
inline var atan2(const var& a, const var& b) {
return var(new atan2_vv_vari(a.vi_, b.vi_));
}
inline var atan2(const var& a, const double b) {
return var(new atan2_vd_vari(a.vi_, b));
}
inline var atan2(const double a, const var& b) {
return var(new atan2_dv_vari(a, b.vi_));
}
}
}
#endif
core.hpp
stan::math::atan2
fvar< T > atan2(const fvar< T > &x1, const fvar< T > &x2)
Definition: atan2.hpp:12
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44

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