Define TEST_JACOBIAN_FINITE_DIFFERENCE

Define Documentation

TEST_JACOBIAN_FINITE_DIFFERENCE(FUNCTOR_TYPE, X, STEP, TOLERANCE, ...)

Test macro and numerical differentiator to unit test Jacobian implementations.

Example:

 struct Functor : public aslam::common::NumDiffFunctor<2, 3> {
  Functor(MyClass::Ptr my_class) : my_class_(my_class) {};
  virtual ~Functor() {};

  void functional(const typename NumDiffFunctor::InputType& x,
                  typename NumDiffFunctor::ValueType& fvec,
                  typename NumDiffFunctor::JacobianType* Jout) const {
      fvec = getValue(x,my_class->params);
      Jout = my_class_->getAnalyticalJacobian(x, my_class->params);
  };

  MyClass::Ptr my_class_;
};

double stepsize = 1e-3;
double test_tolerance = 1e-2;
Eigen::Vector2d x0(0.0, 1.0); // Evaluation point
TEST_JACOBIAN_FINITE_DIFFERENCE(Functor, x0, stepsize, tolerance, my_class_);

Parameters
  • FUNCTOR_TYPE ([in]) – Functor that wraps the value and symbolic Jacobian generating function to the required form. See example below.

  • X ([in]) – Evaluation point. (struct Functor : public aslam::common::NumDiffFunctor<Nf, Nx>) Nf: output dimension, Nx: number of parameters > dim(J)=(Nf x Nx)

  • STEP ([in]) – Step size used for the numerical differentiation. (Eigen::VectorXd)

  • TOLERANCE ([in]) – Tolerance used for comparing the numerical and symbolic Jacobian evaluations. (double)

  • ... ([in]) – Argument list forwarded to Functor constructor. (VA_ARGS)