diff --git a/.cproject b/.cproject index 7d302b39a..0665eaf06 100644 --- a/.cproject +++ b/.cproject @@ -600,7 +600,6 @@ make - tests/testBayesTree.run true false @@ -608,7 +607,6 @@ make - testBinaryBayesNet.run true false @@ -656,7 +654,6 @@ make - testSymbolicBayesNet.run true false @@ -664,7 +661,6 @@ make - tests/testSymbolicFactor.run true false @@ -672,7 +668,6 @@ make - testSymbolicFactorGraph.run true false @@ -688,7 +683,6 @@ make - tests/testBayesTree true false @@ -1040,7 +1034,6 @@ make - testErrors.run true false @@ -1270,46 +1263,6 @@ true true - - make - -j5 - testBTree.run - true - true - true - - - make - -j5 - testDSF.run - true - true - true - - - make - -j5 - testDSFMap.run - true - true - true - - - make - -j5 - testDSFVector.run - true - true - true - - - make - -j5 - testFixedVector.run - true - true - true - make -j2 @@ -1392,6 +1345,7 @@ make + testSimulated2DOriented.run true false @@ -1431,6 +1385,7 @@ make + testSimulated2D.run true false @@ -1438,6 +1393,7 @@ make + testSimulated3D.run true false @@ -1451,6 +1407,46 @@ true true + + make + -j5 + testBTree.run + true + true + true + + + make + -j5 + testDSF.run + true + true + true + + + make + -j5 + testDSFMap.run + true + true + true + + + make + -j5 + testDSFVector.run + true + true + true + + + make + -j5 + testFixedVector.run + true + true + true + make -j5 @@ -1708,7 +1704,6 @@ cpack - -G DEB true false @@ -1716,7 +1711,6 @@ cpack - -G RPM true false @@ -1724,7 +1718,6 @@ cpack - -G TGZ true false @@ -1732,7 +1725,6 @@ cpack - --config CPackSourceConfig.cmake true false @@ -2459,7 +2451,6 @@ make - testGraph.run true false @@ -2467,7 +2458,6 @@ make - testJunctionTree.run true false @@ -2475,7 +2465,6 @@ make - testSymbolicBayesNetB.run true false @@ -2561,6 +2550,14 @@ true true + + make + -j5 + testExpressionMeta.run + true + true + true + make -j2 @@ -2963,6 +2960,7 @@ make + tests/testGaussianISAM2 true false diff --git a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp index 3a7ad5c72..5867f9dcf 100644 --- a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp +++ b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp @@ -424,129 +424,6 @@ TEST(ExpressionFactor, composeTernary) { EXPECT( assert_equal(expected, *jf,1e-9)); } -/* ************************************************************************* */ -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; diff --git a/gtsam_unstable/nonlinear/tests/testExpressionMeta.cpp b/gtsam_unstable/nonlinear/tests/testExpressionMeta.cpp new file mode 100644 index 000000000..19a39d52f --- /dev/null +++ b/gtsam_unstable/nonlinear/tests/testExpressionMeta.cpp @@ -0,0 +1,158 @@ +/* ---------------------------------------------------------------------------- + + * 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); +} +/* ************************************************************************* */ +