From ef5bf03c81dcbad11118d9895fe2c25bdf76144c Mon Sep 17 00:00:00 2001 From: dellaert Date: Mon, 13 Oct 2014 23:04:30 +0200 Subject: [PATCH] Clean up --- gtsam_unstable/nonlinear/Expression-inl.h | 40 +++++++++---------- .../nonlinear/tests/testExpressionFactor.cpp | 23 +++++++++-- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/gtsam_unstable/nonlinear/Expression-inl.h b/gtsam_unstable/nonlinear/Expression-inl.h index 53b38bba4..f0301ba4a 100644 --- a/gtsam_unstable/nonlinear/Expression-inl.h +++ b/gtsam_unstable/nonlinear/Expression-inl.h @@ -38,10 +38,6 @@ struct TestBinaryExpression; #include #include -// Boost Fusion includes allow us to create/access values from MPL vectors -#include -#include - namespace MPL = boost::mpl::placeholders; class ExpressionFactorBinaryTest; @@ -677,10 +673,13 @@ public: virtual Augmented forward(const Values& values) const { using boost::none; Augmented a1 = this->template expression()->forward(values); - typename Jacobian::type dTdA1; - T t = function_(a1.value(), - a1.constant() ? none : typename Optional::type(dTdA1)); - return Augmented(t, dTdA1, a1.jacobians()); + + // Declare Jacobians + using boost::mpl::at_c; + typename at_c::type H1; + + T t = function_(a1.value(), H1); + return Augmented(t, H1, a1.jacobians()); } /// Construct an execution trace for reverse AD @@ -741,12 +740,14 @@ public: using boost::none; Augmented a1 = this->template expression()->forward(values); Augmented a2 = this->template expression()->forward(values); - typename Jacobian::type dTdA1; - typename Jacobian::type dTdA2; - T t = function_(a1.value(), a2.value(), - a1.constant() ? none : typename Optional::type(dTdA1), - a2.constant() ? none : typename Optional::type(dTdA2)); - return Augmented(t, dTdA1, a1.jacobians(), dTdA2, a2.jacobians()); + + // Declare Jacobians + using boost::mpl::at_c; + typename at_c::type H1; + typename at_c::type H2; + + T t = function_(a1.value(), a2.value(),H1,H2); + return Augmented(t, H1, a1.jacobians(), H2, a2.jacobians()); } /// Construct an execution trace for reverse AD @@ -811,13 +812,12 @@ public: Augmented a2 = this->template expression()->forward(values); Augmented a3 = this->template expression()->forward(values); - typedef typename Base::Jacobians Jacobians; + // Declare Jacobians + using boost::mpl::at_c; + typename at_c::type H1; + typename at_c::type H2; + typename at_c::type H3; - using boost::fusion::at_c; - Jacobians H; - typename boost::mpl::at_c::type H1; - typename boost::mpl::at_c::type H2; - typename boost::mpl::at_c::type H3; T t = function_(a1.value(), a2.value(), a3.value(),H1,H2,H3); return Augmented(t, H1, a1.jacobians(), H2, a2.jacobians(), H3, a3.jacobians()); diff --git a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp index d7fe87c87..3a7ad5c72 100644 --- a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp +++ b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp @@ -464,6 +464,11 @@ BOOST_MPL_ASSERT((mpl::equal< ExpectedJacobians, Jacobians >)); 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; @@ -478,7 +483,11 @@ TEST(ExpressionFactor, JacobiansValue) { } /* ************************************************************************* */ +// Test out polymorphic transform + #include +#include +#include struct triple { template struct result; // says we will provide result @@ -488,6 +497,16 @@ struct triple { 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 @@ -495,13 +514,11 @@ struct triple { // actual function template - typename result::type operator()(T& x) const { + typename result::type operator()(const T& x) const { return (double) x; } }; - -// Test out polymorphic transform TEST(ExpressionFactor, Triple) { typedef boost::fusion::vector IntDouble; IntDouble H = boost::fusion::make_vector(1, 2.0);