10 #ifndef EIGEN_FINITEDIFF_CHAIN_HESSIAN_H_
11 #define EIGEN_FINITEDIFF_CHAIN_HESSIAN_H_
21 template <
typename Functor, NumericalDiffMode mode = Forward>
27 typedef typename ValueType::Scalar
Scalar;
36 typedef Matrix<Scalar, ValuesAtCompileTime, JacobianInputsAtCompileTime>
JacobianType;
39 typedef typename JacobianType::Index
Index;
50 #if EIGEN_HAS_VARIADIC_TEMPLATES
51 template <
typename... T>
55 template <
typename... T>
60 template <
typename T0>
64 template <
typename T0,
typename T1>
68 template <
typename T0,
typename T1,
typename T2>
73 template <
typename T0>
77 template <
typename T0,
typename T1>
81 template <
typename T0,
typename T1,
typename T2>
87 #if EIGEN_HAS_VARIADIC_TEMPLATES
99 template <
typename... ParamsType>
108 template <
typename... ParamsType>
112 return autoj(_jx, v, jac, Params...);
115 template <
typename... ParamsType>
130 return autoj(_jx, v, jac);
142 const typename InputJacobianRowType::Index
n = _jx.size();
143 const typename ValueType::Index m = jac.rows();
144 const Scalar eps = sqrt(((std::max)(
epsfcn_, NumTraits<Scalar>::epsilon())));
145 JacobianType jac1(jac.rows(), jac.cols()), jac2(jac.rows(), jac.cols());
148 Index cols = jac.cols();
152 for (
Index i = 0; i < m; ++i)
154 hess[i].resize(cols, cols);
159 #if EIGEN_HAS_VARIADIC_TEMPLATES
160 nfev += autoj(_jx, v, jac, Params...);
162 nfev += autoj(_jx, v, jac);
179 for (
int j = 0; j <
n; ++j)
181 h = eps * abs(jx[j]);
191 #if EIGEN_HAS_VARIADIC_TEMPLATES
192 nfev += autoj(jx, _v, jac2, Params...);
194 nfev += autoj(jx, _v, jac2);
197 for (
int l = 0; l < m; ++l)
199 hess[l].row(j) = (jac2.row(l) - jac1.row(l)) / h;
204 #if EIGEN_HAS_VARIADIC_TEMPLATES
205 nfev += autoj(jx, _v, jac2, Params...);
207 nfev += autoj(jx, _v, jac2);
210 #if EIGEN_HAS_VARIADIC_TEMPLATES
211 nfev += autoj(jx, _v, jac1, Params...);
213 nfev += autoj(jx, _v, jac1);
216 for (
int l = 0; l < m; ++l)
218 hess[l].col(j) = (jac2.row(l) - jac1.row(l)) / (2.0 * h);
230 #endif // EIGEN_FINITEDIFF_CHAIN_HESSIAN_H_