From 8db2cd17fc8d03e43fe943ee2b565dd6e23982ee Mon Sep 17 00:00:00 2001 From: dellaert Date: Sun, 5 Oct 2014 13:41:20 +0200 Subject: [PATCH] Finished constant Trace and *everything* just works!!! Amazing :-) --- gtsam_unstable/nonlinear/Expression-inl.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gtsam_unstable/nonlinear/Expression-inl.h b/gtsam_unstable/nonlinear/Expression-inl.h index 16489ea80..cfd0bf7f2 100644 --- a/gtsam_unstable/nonlinear/Expression-inl.h +++ b/gtsam_unstable/nonlinear/Expression-inl.h @@ -205,10 +205,22 @@ public: return Augmented(constant_); } + /// Trace structure for reverse AD + typedef typename ExpressionNode::Trace BaseTrace; + struct Trace: public BaseTrace { + T t; + /// Return value and derivatives + virtual Augmented augmented(const Matrix& H) const { + // Base case: just return value and empty map + return Augmented(t); + } + }; + /// Construct an execution trace for reverse AD - virtual boost::shared_ptr::Trace> reverse( - const Values& values) const { - return boost::shared_ptr::Trace>(); + virtual boost::shared_ptr reverse(const Values& values) const { + boost::shared_ptr trace = boost::make_shared(); + trace->t = constant_; + return trace; } };