Stan
1.3
probability, sampling & optimization
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
Pages
src
stan
agrad
rev
hypot.hpp
Go to the documentation of this file.
1
#ifndef __STAN__AGRAD__REV__HYPOT_HPP__
2
#define __STAN__AGRAD__REV__HYPOT_HPP__
3
4
#include <valarray>
5
#include <
stan/agrad/rev/var.hpp
>
6
#include <
stan/agrad/rev/op/vv_vari.hpp
>
7
#include <
stan/agrad/rev/op/v_vari.hpp
>
8
#include <boost/math/special_functions/hypot.hpp>
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(boost::math::
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(boost::math::
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
92
inline
var
hypot
(
const
double
& a,
93
const
stan::agrad::var
& b) {
94
return
var
(
new
hypot_vd_vari(b.
vi_
,a));
95
}
96
97
}
98
}
99
#endif
[
Stan Home Page
]
© 2011–2013, Stan Development Team.