Stan Math Library  2.20.0
reverse mode automatic differentiation
partial_derivative.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_MIX_MAT_FUNCTOR_PARTIAL_DERIVATIVE_HPP
2 #define STAN_MATH_MIX_MAT_FUNCTOR_PARTIAL_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 
24 template <typename T, typename F>
25 void partial_derivative(const F& f,
26  const Eigen::Matrix<T, Eigen::Dynamic, 1>& x, int n,
27  T& fx, T& dfx_dxn) {
28  Eigen::Matrix<fvar<T>, Eigen::Dynamic, 1> x_fvar(x.size());
29  for (int i = 0; i < x.size(); ++i)
30  x_fvar(i) = fvar<T>(x(i), i == n);
31  fvar<T> fx_fvar = f(x_fvar);
32  fx = fx_fvar.val_;
33  dfx_dxn = fx_fvar.d_;
34 }
35 
36 } // namespace math
37 } // namespace stan
38 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
T val_
The value of this variable.
Definition: fvar.hpp:45
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
void partial_derivative(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, int n, T &fx, T &dfx_dxn)
Return the partial derivative of the specified multiivariate function at the specified argument...

     [ Stan Home Page ] © 2011–2018, Stan Development Team.