| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
hypot.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_HYPOT_HPP
2 #define STAN_MATH_REV_SCAL_FUN_HYPOT_HPP
3
4 #include <math.h>
5 #include <stan/math/rev/core.hpp>
6 #include <cmath>
7 #include <valarray>
8
9 namespace stan {
10 namespace math {
11
12 namespace {
13 class hypot_vv_vari : public op_vv_vari {
14 public:
15 hypot_vv_vari(vari* avi, vari* bvi) :
16 op_vv_vari(::hypot(avi->val_, bvi->val_),
17 avi, bvi) {
18 }
19 void chain() {
20 avi_->adj_ += adj_ * avi_->val_ / val_;
21 bvi_->adj_ += adj_ * bvi_->val_ / val_;
22 }
23 };
24
25 class hypot_vd_vari : public op_v_vari {
26 public:
27 hypot_vd_vari(vari* avi, double b) :
28 op_v_vari(::hypot(avi->val_, b),
29 avi) {
30 }
31 void chain() {
32 avi_->adj_ += adj_ * avi_->val_ / val_;
33 }
34 };
35 }
36
53 inline var hypot(const var& a, const var& b) {
54 return var(new hypot_vv_vari(a.vi_, b.vi_));
55 }
56
71 inline var hypot(const var& a, double b) {
72 return var(new hypot_vd_vari(a.vi_, b));
73 }
74
116 inline var hypot(double a, const var& b) {
117 return var(new hypot_vd_vari(b.vi_, a));
118 }
119
120 }
121 }
122 #endif
core.hpp
stan::math::hypot
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Definition: hypot.hpp:13
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.