/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file testExpressionMeta.cpp * @date October 14, 2014 * @author Frank Dellaert * @brief Test meta-programming constructs for Expressions */ #include #include #include #include #include using namespace std; using namespace gtsam; /* ************************************************************************* */ namespace mpl = boost::mpl; #include #include template struct Incomplete; // Check generation of FunctionalNode typedef mpl::vector MyTypes; typedef FunctionalNode::type Generated; //Incomplete incomplete; BOOST_MPL_ASSERT((boost::is_same< Matrix2, Generated::Record::Jacobian2T >)); // Try generating vectors of ExecutionTrace typedef mpl::vector, ExecutionTrace > ExpectedTraces; typedef mpl::transform >::type MyTraces; BOOST_MPL_ASSERT((mpl::equal< ExpectedTraces, MyTraces >)); template struct MakeTrace { typedef ExecutionTrace type; }; typedef mpl::transform >::type MyTraces1; BOOST_MPL_ASSERT((mpl::equal< ExpectedTraces, MyTraces1 >)); // Try generating vectors of Expression types typedef mpl::vector, Expression > ExpectedExpressions; typedef mpl::transform >::type Expressions; BOOST_MPL_ASSERT((mpl::equal< ExpectedExpressions, Expressions >)); // Try generating vectors of Jacobian types typedef mpl::vector ExpectedJacobians; typedef mpl::transform >::type Jacobians; BOOST_MPL_ASSERT((mpl::equal< ExpectedJacobians, Jacobians >)); // Try accessing a Jacobian typedef mpl::at_c::type Jacobian23; // base zero ! BOOST_MPL_ASSERT((boost::is_same< Matrix23, Jacobian23>)); /* ************************************************************************* */ // Boost Fusion includes allow us to create/access values from MPL vectors #include #include // Create a value and access it TEST(ExpressionFactor, JacobiansValue) { using boost::fusion::at_c; Matrix23 expected; Jacobians jacobians; at_c<1>(jacobians) << 1, 2, 3, 4, 5, 6; Matrix23 actual = at_c<1>(jacobians); CHECK(actual.cols() == expected.cols()); CHECK(actual.rows() == expected.rows()); } /* ************************************************************************* */ // Test out polymorphic transform #include #include #include struct triple { template struct result; // says we will provide result template struct result { typedef double type; // result for int argument }; template struct result { typedef double type; // result for int argument }; template struct result { typedef double type; // result for double argument }; template struct result { typedef double type; // result for double argument }; // actual function template typename result::type operator()(const T& x) const { return (double) x; } }; TEST(ExpressionFactor, Triple) { typedef boost::fusion::vector IntDouble; IntDouble H = boost::fusion::make_vector(1, 2.0); // Only works if I use Double2 typedef boost::fusion::result_of::transform::type Result; typedef boost::fusion::vector Double2; Double2 D = boost::fusion::transform(H, triple()); using boost::fusion::at_c; DOUBLES_EQUAL(1.0, at_c<0>(D), 1e-9); DOUBLES_EQUAL(2.0, at_c<1>(D), 1e-9); } /* ************************************************************************* */ #include #include // Test out polymorphic transform TEST(ExpressionFactor, Invoke) { std::plus add; assert(invoke(add,boost::fusion::make_vector(1,1)) == 2); // Creating a Pose3 (is there another way?) boost::fusion::vector pair; Pose3 pose = boost::fusion::invoke(boost::value_factory(), pair); } /* ************************************************************************* */ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */