Example shows numeric linear function use.
#include "shared-tests/fixture.hh"
#include <iostream>
BOOST_FIXTURE_TEST_SUITE (core, TestSuiteConfiguration)
BOOST_AUTO_TEST_CASE_TEMPLATE (numeric_linear_function, T, functionTypes_t)
{
boost::shared_ptr<boost::test_tools::output_test_stream>
output = retrievePattern ("numeric-linear-function");
typename GenericNumericLinearFunction<T>::matrix_t a (1, 5);
typename GenericNumericLinearFunction<T>::vector_t b (1);
typename GenericNumericLinearFunction<T>::vector_t x (5);
a.setZero ();
b.setZero ();
x.setZero ();
a.coeffRef (0, 0) = 1.2;
a.coeffRef (0, 1) = 3.4;
a.coeffRef (0, 2) = 5.6;
a.coeffRef (0, 3) = 7.8;
b[0] = 1.;
GenericNumericLinearFunction<T> f (a, b);
(*output) << f << std::endl;
x[0] = 0.1;
x[1] = 1.2;
x[2] = 2.3;
x[3] = 3.4;
x[4] = 4.5;
(*output) << "f(x) = " << f (x) << std::endl;
(*output) << "G(x) = " << f.gradient (x, 0) << std::endl;
(*output) << "J(x) = " << f.jacobian (x) << std::endl;
(*output) << "H(x) = " << f.hessian (x) << std::endl;
GenericNumericLinearFunction<T> numericLinearFunction (a, b);
GenericLinearFunction<T>* linearFunction = &numericLinearFunction;
GenericNumericLinearFunction<T> numericLinearFunctionRebuilt (*linearFunction);
BOOST_CHECK (
allclose (numericLinearFunction.A (),
numericLinearFunctionRebuilt.A ()));
BOOST_CHECK_EQUAL (numericLinearFunction.b (), numericLinearFunctionRebuilt.b ());
std::cout << output->str () << std::endl;
}
BOOST_AUTO_TEST_SUITE_END ()
DummyDifferentiableSparseSolverLastState::parent_t solver_t
Definition: dummy-d-sparse-laststate.cc:29
defined(EIGEN_RUNTIME_NO_MALLOC) && !defined(ROBOPTIM_DO_NOT_CHECK_ALLOCATION)
Definition: alloc.hh:33
ROBOPTIM_DLLAPI bool allclose(const Eigen::SparseMatrix< double > &a, const Eigen::SparseMatrix< double > &b, double rtol=Eigen::NumTraits< double >::dummy_precision(), double atol=Eigen::NumTraits< double >::epsilon())
Compare sparse vectors (matrices) using both relative and absolute tolerances.
Definition: util.cc:104
Tag type for functions using Eigen dense matrices.
Definition: fwd.hh:59
Tag type for functions using Eigen sparse matrices.
Definition: fwd.hh:61