29 template <
class VECTORLIKE,
class VECTORLIKE2,
class VECTORLIKE3,
30 class MATRIXLIKE,
class USERPARAM>
33 const std::function<
void(
34 const VECTORLIKE&
x,
const USERPARAM&
y, VECTORLIKE3& out)>& functor,
35 const VECTORLIKE2& increments,
const USERPARAM& userParam,
36 MATRIXLIKE& out_Jacobian)
39 ASSERT_(
x.size() > 0 && increments.size() ==
x.size());
42 const size_t n =
x.size();
44 for (
size_t j = 0; j <
n; j++)
49 VECTORLIKE3 f_minus, f_plus;
53 for (
size_t j = 0; j <
n; j++)
56 x_mod[j] =
x[j] + increments[j];
57 functor(x_mod, userParam, f_plus);
59 x_mod[j] =
x[j] - increments[j];
60 functor(x_mod, userParam, f_minus);
63 const double Ax_2_inv = 0.5 / increments[j];
69 out_Jacobian.setSize(m,
n);
72 for (
size_t i = 0; i < m; i++)
73 out_Jacobian.get_unsafe(i, j) = Ax_2_inv * (f_plus[i] - f_minus[i]);