Stan Math Library  2.20.0
reverse mode automatic differentiation
derivative.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_DERIVATIVE_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_DERIVATIVE_HPP
3 
4 #include <stan/math/fwd/core.hpp>
6 #include <stan/math/rev/core.hpp>
7 #include <vector>
8 
9 namespace stan {
10 namespace math {
11 
23 template <typename T, typename F>
24 void derivative(const F& f, const T& x, T& fx, T& dfx_dx) {
25  fvar<T> x_fvar = fvar<T>(x, 1.0);
26  fvar<T> fx_fvar = f(x_fvar);
27  fx = fx_fvar.val_;
28  dfx_dx = fx_fvar.d_;
29 }
30 
31 } // namespace math
32 } // namespace stan
33 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
T val_
The value of this variable.
Definition: fvar.hpp:45
void derivative(const F &f, const T &x, T &fx, T &dfx_dx)
Return the derivative of the specified univariate function at the specified argument.
Definition: derivative.hpp:24
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.