Automatic Differentiation
 
Loading...
Searching...
No Matches
fma.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_FMA_HPP
2#define STAN_MATH_FWD_FUN_FMA_HPP
3
7
8namespace stan {
9namespace math {
10
58template <typename T1, typename T2, typename T3,
59 require_all_stan_scalar_t<T1, T2, T3>* = nullptr>
61 const fvar<T2>& x2,
62 const fvar<T3>& x3) {
64 fma(x1.val_, x2.val_, x3.val_),
65 x1.d_ * x2.val_ + x2.d_ * x1.val_ + x3.d_);
66}
67
71template <typename T1, typename T2, typename T3,
73inline fvar<return_type_t<T1, T2, T3>> fma(const T1& x1, const fvar<T2>& x2,
74 const fvar<T3>& x3) {
75 return fvar<return_type_t<T1, T2, T3>>(fma(x1, x2.val_, x3.val_),
76 x2.d_ * x1 + x3.d_);
77}
78
82template <typename T1, typename T2, typename T3,
84inline fvar<return_type_t<T1, T2, T3>> fma(const fvar<T1>& x1, const T2& x2,
85 const fvar<T3>& x3) {
86 return fvar<return_type_t<T1, T2, T3>>(fma(x1.val_, x2, x3.val_),
87 x1.d_ * x2 + x3.d_);
88}
89
93template <typename T1, typename T2, typename T3,
96 const fvar<T2>& x2, const T3& x3) {
97 return fvar<return_type_t<T1, T2, T3>>(fma(x1.val_, x2.val_, x3),
98 x1.d_ * x2.val_ + x2.d_ * x1.val_);
99}
100
104template <typename T1, typename T2, typename T3,
106inline fvar<return_type_t<T1, T2, T3>> fma(const T1& x1, const T2& x2,
107 const fvar<T3>& x3) {
108 return fvar<return_type_t<T1, T2, T3>>(fma(x1, x2, x3.val_), x3.d_);
109}
110
114template <typename T1, typename T2, typename T3,
116inline fvar<return_type_t<T1, T2, T3>> fma(const fvar<T1>& x1, const T2& x2,
117 const T3& x3) {
118 return fvar<return_type_t<T1, T2, T3>>(fma(x1.val_, x2, x3), x1.d_ * x2);
119}
120
124template <typename T1, typename T2, typename T3,
126inline fvar<return_type_t<T1, T2, T3>> fma(const T1& x1, const fvar<T2>& x2,
127 const T3& x3) {
128 return fvar<return_type_t<T1, T2, T3>>(fma(x1, x2.val_, x3), x2.d_ * x1);
129}
130
131} // namespace math
132} // namespace stan
133#endif
require_all_t< is_stan_scalar< std::decay_t< Types > >... > require_all_stan_scalar_t
Require all of the types satisfy is_stan_scalar.
fvar< return_type_t< T1, T2, T3 > > fma(const fvar< T1 > &x1, const fvar< T2 > &x2, const fvar< T3 > &x3)
The fused multiply-add operation (C99).
Definition fma.hpp:60
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40