diff --git a/gtsam_unstable/nonlinear/Expression-inl.h b/gtsam_unstable/nonlinear/Expression-inl.h index 0bc552985..6f78832b9 100644 --- a/gtsam_unstable/nonlinear/Expression-inl.h +++ b/gtsam_unstable/nonlinear/Expression-inl.h @@ -552,10 +552,16 @@ struct GenerateFunctionalNode: Argument, Base { /// Construct an execution trace for reverse AD void trace(const Values& values, Record* record, char*& raw) const { - Base::trace(values, record, raw); + Base::trace(values, record, raw); // recurse + // Write an Expression execution trace in record->trace + // Iff Constant or Leaf, this will not write to raw, only to trace. + // Iff the expression is functional, write all Records in raw buffer + // Return value of type T is recorded in record->value record->Record::This::value = This::expression->traceExecution(values, record->Record::This::trace, raw); - raw = raw + This::expression->traceSize(); + // raw is never modified by traceExecution, but if traceExecution has + // written in the buffer, the next caller expects we advance the pointer + raw += This::expression->traceSize(); } }; @@ -590,12 +596,6 @@ struct FunctionalNode { return static_cast const &>(*this).value; } - /// Access Trace - template - ExecutionTrace& trace() { - return static_cast&>(*this).trace; - } - /// Access Jacobian template typename Jacobian::type& jacobian() {