Automatic Differentiation
 
Loading...
Searching...
No Matches
partial_derivative.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_MIX_FUNCTOR_PARTIAL_DERIVATIVE_HPP
2#define STAN_MATH_MIX_FUNCTOR_PARTIAL_DERIVATIVE_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
24template <typename T, typename F>
25void 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 }
32 fvar<T> fx_fvar = f(x_fvar);
33 fx = fx_fvar.val_;
34 dfx_dxn = fx_fvar.d_;
35}
36
37} // namespace math
38} // namespace stan
39#endif
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 multivariate function at the specified argument.
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