Stan Math Library
2.14.0
reverse mode automatic differentiation
stan
math
fwd
scal
fun
fdim.hpp
Go to the documentation of this file.
1
#ifndef STAN_MATH_FWD_SCAL_FUN_FDIM_HPP
2
#define STAN_MATH_FWD_SCAL_FUN_FDIM_HPP
3
4
#include <
stan/math/fwd/core.hpp
>
5
#include <
stan/math/prim/scal/fun/fdim.hpp
>
6
7
namespace
stan
{
8
namespace
math {
9
19
template
<
typename
T>
20
inline
fvar<T>
fdim
(
const
fvar<T>
& x,
const
fvar<T>
& y) {
21
if
(x.
val_
< y.
val_
)
22
return
fvar<T>
(
fdim
(x.
val_
, y.
val_
), 0);
23
else
24
return
fvar<T>
(
fdim
(x.
val_
, y.
val_
),
25
x.
d_
- y.
d_
);
26
}
27
37
template
<
typename
T>
38
inline
fvar<T>
fdim
(
const
fvar<T>
& x,
double
y) {
39
if
(x.
val_
< y)
40
return
fvar<T>
(
fdim
(x.
val_
, y), 0);
41
else
42
return
fvar<T>
(
fdim
(x.
val_
, y), x.
d_
);
43
}
44
54
template
<
typename
T>
55
inline
fvar<T>
fdim
(
double
x,
const
fvar<T>
& y) {
56
if
(x < y.
val_
)
57
return
fvar<T>
(
fdim
(x, y.
val_
), 0);
58
else
59
return
fvar<T>
(
fdim
(x, y.
val_
), -y.
d_
);
60
}
61
62
}
63
}
64
#endif
core.hpp
stan::math::fvar::d_
T d_
Definition:
fvar.hpp:16
stan
Definition:
log_sum_exp.hpp:8
stan::math::fdim
fvar< T > fdim(const fvar< T > &x, const fvar< T > &y)
Return the positive difference of the specified values (C++11).
Definition:
fdim.hpp:20
stan::math::fvar::val_
T val_
Definition:
fvar.hpp:15
stan::math::fvar
Definition:
fvar.hpp:14
fdim.hpp
[
Stan Home Page
]
© 2011–2016, Stan Development Team.