13 #ifndef EIGEN_NUMERICAL_DIFF_H
14 #define EIGEN_NUMERICAL_DIFF_H
18 enum NumericalDiffMode {
35 template<
typename _Functor, NumericalDiffMode mode=Forward>
39 typedef _Functor Functor;
40 typedef typename Functor::Scalar Scalar;
41 typedef typename Functor::InputType InputType;
42 typedef typename Functor::ValueType ValueType;
43 typedef typename Functor::JacobianType JacobianType;
45 NumericalDiff(Scalar _epsfcn=0.) : Functor(), epsfcn(_epsfcn) {}
46 NumericalDiff(
const Functor& f, Scalar _epsfcn=0.) : Functor(f), epsfcn(_epsfcn) {}
51 template<
typename T0,
typename T1>
52 NumericalDiff(
const T0& a0,
const T1& a1) : Functor(a0, a1), epsfcn(0) {}
53 template<
typename T0,
typename T1,
typename T2>
54 NumericalDiff(
const T0& a0,
const T1& a1,
const T2& a2) : Functor(a0, a1, a2), epsfcn(0) {}
57 InputsAtCompileTime = Functor::InputsAtCompileTime,
58 ValuesAtCompileTime = Functor::ValuesAtCompileTime
64 int df(
const InputType& _x, JacobianType &jac)
const
71 const typename InputType::Index n = _x.size();
72 const Scalar eps = sqrt(((std::max)(epsfcn,NumTraits<Scalar>::epsilon() )));
76 val1.resize(Functor::values());
77 val2.resize(Functor::values());
83 Functor::operator()(x, val1); nfev++;
93 for (
int j = 0; j < n; ++j) {
101 Functor::operator()(x, val2);
104 jac.col(j) = (val2-val1)/h;
108 Functor::operator()(x, val2); nfev++;
110 Functor::operator()(x, val1); nfev++;
112 jac.col(j) = (val2-val1)/(2*h);
129 #endif // EIGEN_NUMERICAL_DIFF_H
int df(const InputType &_x, JacobianType &jac) const
Definition: NumericalDiff.h:64
Definition: NumericalDiff.h:36