| 23 | using context::VectorSpace; |
| 24 | |
| 25 | void fd_test(VectorXs x0, VectorXs u0, MatrixXs weights, |
| 26 | QuadraticResidualCost qres, shared_ptr<CostData> data) { |
| 27 | |
| 28 | const xyz::polymorphic<StageFunctionTpl<T>> fun = qres.residual_; |
| 29 | const auto fd = fun->createData(); |
| 30 | const auto ndx = fd->ndx1; |
| 31 | const auto nu = fd->nu; |
| 32 | qres.evaluate(x0, u0, *data); |
| 33 | qres.computeGradients(x0, u0, *data); |
| 34 | qres.computeHessians(x0, u0, *data); |
| 35 | |
| 36 | // analytical formula |
| 37 | fun->evaluate(x0, u0, *fd); |
| 38 | fun->computeJacobians(x0, u0, *fd); |
| 39 | |
| 40 | auto n = (long)(ndx + nu); |
| 41 | auto J = fd->jac_buffer_.leftCols(n); |
| 42 | |
| 43 | auto grad_ref = J.transpose() * weights * fd->value_; |
| 44 | auto hess_ref = J.transpose() * weights * J; |
| 45 | REQUIRE(grad_ref.isApprox(data->grad_)); |
| 46 | REQUIRE(hess_ref.isApprox(data->hess_)); |
| 47 | } |
| 48 | |
| 49 | #ifdef ALIGATOR_WITH_PINOCCHIO |
| 50 | TEST_CASE("quad_state_se2", "[costs]") { |
no test coverage detected