1 #ifndef STAN_MATH_FWD_MAT_FUNCTOR_JACOBIAN_HPP 2 #define STAN_MATH_FWD_MAT_FUNCTOR_JACOBIAN_HPP 10 template <
typename T,
typename F>
11 void jacobian(
const F& f,
const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
12 Eigen::Matrix<T, Eigen::Dynamic, 1>& fx,
13 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& J) {
16 Matrix<fvar<T>, Dynamic, 1> x_fvar(x.size());
17 for (
int i = 0; i < x.size(); ++i) {
18 for (
int k = 0; k < x.size(); ++k)
19 x_fvar(k) =
fvar<T>(x(k), i == k);
20 Matrix<fvar<T>, Dynamic, 1> fx_fvar = f(x_fvar);
22 J.resize(fx_fvar.size(), x.size());
23 fx.resize(fx_fvar.size());
24 for (
int k = 0; k < fx_fvar.size(); ++k)
25 fx(k) = fx_fvar(k).
val_;
27 for (
int k = 0; k < fx_fvar.size(); ++k) {
28 J(k, i) = fx_fvar(k).
d_;
T d_
The tangent (derivative) of this variable.
void jacobian(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, Eigen::Matrix< T, Eigen::Dynamic, 1 > &fx, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &J)
T val_
The value of this variable.
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.