Stan Math Library
2.20.0
reverse mode automatic differentiation
stan
math
fwd
scal
fun
fma.hpp
Go to the documentation of this file.
1
#ifndef STAN_MATH_FWD_SCAL_FUN_FMA_HPP
2
#define STAN_MATH_FWD_SCAL_FUN_FMA_HPP
3
4
#include <
stan/math/fwd/meta.hpp
>
5
#include <
stan/math/fwd/core.hpp
>
6
#include <
stan/math/prim/scal/fun/fma.hpp
>
7
8
namespace
stan
{
9
namespace
math {
10
58
template
<
typename
T1,
typename
T2,
typename
T3>
59
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
60
const
fvar<T1>
& x1,
const
fvar<T2>
& x2,
const
fvar<T3>
& x3) {
61
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
62
fma
(x1.
val_
, x2.
val_
, x3.
val_
),
63
x1.
d_
* x2.
val_
+ x2.
d_
* x1.
val_
+ x3.
d_
);
64
}
65
69
template
<
typename
T1,
typename
T2,
typename
T3>
70
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
71
const
T1& x1,
const
fvar<T2>
& x2,
const
fvar<T3>
& x3) {
72
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
73
fma
(x1, x2.
val_
, x3.
val_
), x2.
d_
* x1 + x3.
d_
);
74
}
75
79
template
<
typename
T1,
typename
T2,
typename
T3>
80
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
81
const
fvar<T1>
& x1,
const
T2& x2,
const
fvar<T3>
& x3) {
82
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
83
fma
(x1.
val_
, x2, x3.
val_
), x1.
d_
* x2 + x3.
d_
);
84
}
85
89
template
<
typename
T1,
typename
T2,
typename
T3>
90
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
91
const
fvar<T1>
& x1,
const
fvar<T2>
& x2,
const
T3& x3) {
92
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
93
fma
(x1.
val_
, x2.
val_
, x3), x1.
d_
* x2.
val_
+ x2.
d_
* x1.
val_
);
94
}
95
99
template
<
typename
T1,
typename
T2,
typename
T3>
100
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
101
const
T1& x1,
const
T2& x2,
const
fvar<T3>
& x3) {
102
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
103
fma
(x1, x2, x3.
val_
), x3.
d_
);
104
}
105
109
template
<
typename
T1,
typename
T2,
typename
T3>
110
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
111
const
fvar<T1>
& x1,
const
T2& x2,
const
T3& x3) {
112
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
113
fma
(x1.
val_
, x2, x3), x1.
d_
* x2);
114
}
115
119
template
<
typename
T1,
typename
T2,
typename
T3>
120
inline
fvar<typename stan::return_type<T1, T2, T3>::type
>
fma
(
121
const
T1& x1,
const
fvar<T2>
& x2,
const
T3& x3) {
122
return
fvar<typename stan::return_type<T1, T2, T3>::type
>(
123
fma
(x1, x2.
val_
, x3), x2.
d_
* x1);
124
}
125
126
}
// namespace math
127
}
// namespace stan
128
#endif
core.hpp
stan::math::fvar::d_
T d_
The tangent (derivative) of this variable.
Definition:
fvar.hpp:50
stan
Definition:
log_sum_exp.hpp:8
stan::math::fvar::val_
T val_
The value of this variable.
Definition:
fvar.hpp:45
stan::math::fma
fvar< typename stan::return_type< T1, T2, T3 >::type > fma(const fvar< T1 > &x1, const fvar< T2 > &x2, const fvar< T3 > &x3)
The fused multiply-add operation (C99).
Definition:
fma.hpp:59
fma.hpp
meta.hpp
stan::math::fvar
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition:
fvar.hpp:41
[
Stan Home Page
]
© 2011–2018, Stan Development Team.