From 376c9e409d8a2efd6fa57b4a3dd77c2c72b80e57 Mon Sep 17 00:00:00 2001 From: Jing Dong Date: Wed, 6 May 2015 14:50:01 -0400 Subject: [PATCH] move some Expression implementations to include header --- gtsam/nonlinear/Expression-inl.h | 42 ++++++++++++++++++++++++++++++++ gtsam/nonlinear/Expression.h | 27 ++++---------------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/gtsam/nonlinear/Expression-inl.h b/gtsam/nonlinear/Expression-inl.h index 3267e20be..936691166 100644 --- a/gtsam/nonlinear/Expression-inl.h +++ b/gtsam/nonlinear/Expression-inl.h @@ -931,6 +931,48 @@ Expression::Expression( expression3)) { } + +/// Return root +template +const boost::shared_ptr >& Expression::root() const { + return root_; +} + +// Return size needed for memory buffer in traceExecution +template +size_t Expression::traceSize() const { + return root_->traceSize(); +} + +/// Return keys that play in this expression +template +std::set Expression::keys() const { + return root_->keys(); +} + +/// Return dimensions for each argument, as a map +template +void Expression::dims(std::map& map) const { + root_->dims(map); +} + +/** + * @brief Return value and optional derivatives, reverse AD version + * Notes: this is not terribly efficient, and H should have correct size. + * The order of the Jacobians is same as keys in either keys() or dims() + */ +template +T Expression::value(const Values& values, boost::optional&> H) const { + + if (H) { + // Call private version that returns derivatives in H + KeysAndDims pair = keysAndDims(); + return value(values, pair.first, pair.second, *H); + } else + // no derivatives needed, just return value + return root_->value(values); +} + /// private version that takes keys and dimensions, returns derivatives template T Expression::value(const Values& values, const FastVector& keys, diff --git a/gtsam/nonlinear/Expression.h b/gtsam/nonlinear/Expression.h index 1c4331de8..c400fbe12 100644 --- a/gtsam/nonlinear/Expression.h +++ b/gtsam/nonlinear/Expression.h @@ -144,24 +144,16 @@ public: const Expression& expression3); /// Return root - const boost::shared_ptr >& root() const { - return root_; - } + const boost::shared_ptr >& root() const; // Return size needed for memory buffer in traceExecution - size_t traceSize() const { - return root_->traceSize(); - } + size_t traceSize() const; /// Return keys that play in this expression - std::set keys() const { - return root_->keys(); - } + std::set keys() const; /// Return dimensions for each argument, as a map - void dims(std::map& map) const { - root_->dims(map); - } + void dims(std::map& map) const; /** * @brief Return value and optional derivatives, reverse AD version @@ -169,16 +161,7 @@ public: * The order of the Jacobians is same as keys in either keys() or dims() */ T value(const Values& values, boost::optional&> H = - boost::none) const { - - if (H) { - // Call private version that returns derivatives in H - KeysAndDims pair = keysAndDims(); - return value(values, pair.first, pair.second, *H); - } else - // no derivatives needed, just return value - return root_->value(values); - } + boost::none) const; /** * @return a "deep" copy of this Expression