Stan Math Library  2.20.0
reverse mode automatic differentiation
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>
7 
8 namespace stan {
9 namespace math {
10 
58 template <typename T1, typename T2, typename T3>
60  const fvar<T1>& x1, const fvar<T2>& x2, const fvar<T3>& x3) {
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>
71  const T1& x1, const fvar<T2>& x2, const fvar<T3>& x3) {
73  fma(x1, x2.val_, x3.val_), x2.d_ * x1 + x3.d_);
74 }
75 
79 template <typename T1, typename T2, typename T3>
81  const fvar<T1>& x1, const T2& x2, const fvar<T3>& x3) {
83  fma(x1.val_, x2, x3.val_), x1.d_ * x2 + x3.d_);
84 }
85 
89 template <typename T1, typename T2, typename T3>
91  const fvar<T1>& x1, const fvar<T2>& x2, const T3& x3) {
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>
101  const T1& x1, const T2& x2, const fvar<T3>& x3) {
103  fma(x1, x2, x3.val_), x3.d_);
104 }
105 
109 template <typename T1, typename T2, typename T3>
111  const fvar<T1>& x1, const T2& x2, const T3& x3) {
113  fma(x1.val_, x2, x3), x1.d_ * x2);
114 }
115 
119 template <typename T1, typename T2, typename T3>
121  const T1& x1, const fvar<T2>& x2, const T3& x3) {
123  fma(x1, x2.val_, x3), x2.d_ * x1);
124 }
125 
126 } // namespace math
127 } // namespace stan
128 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
T val_
The value of this variable.
Definition: fvar.hpp:45
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
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.