From 52fc6f2db4e5ce098016ade73fda0e8f01cf5946 Mon Sep 17 00:00:00 2001 From: dellaert Date: Sat, 11 Oct 2014 08:41:39 +0200 Subject: [PATCH] Testing old trace --- gtsam_unstable/nonlinear/Expression-inl.h | 8 +++++- .../nonlinear/tests/testExpressionFactor.cpp | 25 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gtsam_unstable/nonlinear/Expression-inl.h b/gtsam_unstable/nonlinear/Expression-inl.h index c7a7f0911..87ff1c7fb 100644 --- a/gtsam_unstable/nonlinear/Expression-inl.h +++ b/gtsam_unstable/nonlinear/Expression-inl.h @@ -91,6 +91,12 @@ public: type = Function; content.ptr = record; } + /// Return record pointer, highly unsafe, used only for testing + boost::optional*> record() { + return + (type == Function) ? boost::optional*>(content.ptr) : + boost::none; + } // *** This is the main entry point for reverseAD, called from Expression::augmented *** // Called only once, either inserts identity into Jacobians (Leaf) or starts AD (Function) void startReverseAD(JacobianMap& jacobians) const { @@ -485,7 +491,7 @@ private: function_(f), expressionA1_(e1.root()), expressionA2_(e2.root()) { } - friend class Expression; + friend class Expression ; friend struct ::TestBinaryExpression; public: diff --git a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp index 95348a1f1..3a9aa28a0 100644 --- a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp +++ b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp @@ -122,9 +122,32 @@ struct TestBinaryExpression { /* ************************************************************************* */ // Binary(Leaf,Leaf) TEST(ExpressionFactor, binary) { - TestBinaryExpression tester; + // Create some values + Values values; + values.insert(1, Cal3_S2()); + values.insert(2, Point2(0, 0)); + + // Do old trace + ExecutionTrace trace; + tester.binary_.traceExecution(values, trace); + + // Extract record :-( + boost::optional*> r = trace.record(); + CHECK(r); + typedef BinaryExpression Binary; + Binary::Record* p = dynamic_cast(*r); + CHECK(p); + + // Check matrices + Matrix25 expected25; + expected25 << 0, 0, 0, 1, 0, 0, 0, 0, 0, 1; + EXPECT( assert_equal(expected25, (Matrix)p->dTdA1, 1e-9)); + Matrix2 expected22; + expected22 << 1, 0, 0, 1; + EXPECT( assert_equal(expected22, (Matrix)p->dTdA2, 1e-9)); + // Check raw memory trace } /* ************************************************************************* */