1#ifndef STAN_MATH_FWD_FUNCTOR_JACOBIAN_HPP
2#define STAN_MATH_FWD_FUNCTOR_JACOBIAN_HPP
10template <
typename T,
typename F>
11void 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 J.resize(x_fvar.size(), x.size());
18 fx.resize(x_fvar.size());
19 for (
int k = 0; k < x.size(); ++k) {
23 Matrix<fvar<T>, Dynamic, 1> fx_fvar = f(x_fvar);
25 J.col(0) = fx_fvar.d();
26 const fvar<T> switch_fvar(0, 1);
27 for (
int i = 1; i < x.size(); ++i) {
28 x_fvar(i - 1) -= switch_fvar;
29 x_fvar(i) += switch_fvar;
30 Matrix<fvar<T>, Dynamic, 1> fx_fvar = f(x_fvar);
31 J.col(i) = fx_fvar.d();
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)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
This template class represents scalars used in forward-mode automatic differentiation,...