Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hypot.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__HYPOT_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__HYPOT_HPP
3 
4 #include <valarray>
5 #include <stan/agrad/rev/var.hpp>
8 #include <math.h>
9 
10 namespace stan {
11  namespace agrad {
12 
13  namespace {
14  class hypot_vv_vari : public op_vv_vari {
15  public:
16  hypot_vv_vari(vari* avi, vari* bvi) :
17  op_vv_vari(::hypot(avi->val_,bvi->val_),
18  avi,bvi) {
19  }
20  void chain() {
21  avi_->adj_ += adj_ * avi_->val_ / val_;
22  bvi_->adj_ += adj_ * bvi_->val_ / val_;
23  }
24  };
25 
26  class hypot_vd_vari : public op_v_vari {
27  public:
28  hypot_vd_vari(vari* avi, double b) :
29  op_v_vari(::hypot(avi->val_,b),
30  avi) {
31  }
32  void chain() {
33  avi_->adj_ += adj_ * avi_->val_ / val_;
34  }
35  };
36  }
37 
54  inline var hypot(const stan::agrad::var& a,
55  const stan::agrad::var& b) {
56  return var(new hypot_vv_vari(a.vi_,b.vi_));
57  }
58 
73  inline var hypot(const stan::agrad::var& a,
74  const double& b) {
75  return var(new hypot_vd_vari(a.vi_,b));
76  }
77 
119  inline var hypot(const double& a,
120  const stan::agrad::var& b) {
121  return var(new hypot_vd_vari(b.vi_,a));
122  }
123 
124  }
125 }
126 #endif
fvar< T > hypot(const fvar< T > &x1, const fvar< T > &x2)
Definition: hypot.hpp:16
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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