diff --git a/gtsam_unstable/nonlinear/Expression.h b/gtsam_unstable/nonlinear/Expression.h index 8f1514a22..4684184b8 100644 --- a/gtsam_unstable/nonlinear/Expression.h +++ b/gtsam_unstable/nonlinear/Expression.h @@ -45,8 +45,6 @@ public: /// Define type so we can apply it as a meta-function typedef Expression type; - typedef std::pair, FastVector > KeysAndDims; - private: // Paul's trick shared pointer, polymorphic root of entire expression tree @@ -136,18 +134,6 @@ public: root_->dims(map); } - /// return keys and dimensions as vectors in same order - KeysAndDims keysAndDims() const { - std::map map; - dims(map); - size_t n = map.size(); - FastVector keys(n); - boost::copy(map | boost::adaptors::map_keys, keys.begin()); - FastVector dims(n); - boost::copy(map | boost::adaptors::map_values, dims.begin()); - return make_pair(keys, dims); - } - /** * @brief Return value and optional derivatives, reverse AD version * Notes: this is not terribly efficient, and H should have correct size. @@ -165,6 +151,19 @@ public: private: + /// Vaguely unsafe keys and dimensions in same order + typedef std::pair, FastVector > KeysAndDims; + KeysAndDims keysAndDims() const { + std::map map; + dims(map); + size_t n = map.size(); + FastVector keys(n); + boost::copy(map | boost::adaptors::map_keys, keys.begin()); + FastVector dims(n); + boost::copy(map | boost::adaptors::map_values, dims.begin()); + return make_pair(keys, dims); + } + /// private version that takes keys and dimensions, returns derivatives T value(const Values& values, const KeysAndDims& keysAndDims, std::vector& H) const { diff --git a/gtsam_unstable/nonlinear/tests/testExpression.cpp b/gtsam_unstable/nonlinear/tests/testExpression.cpp index d02a67b2d..6156d103c 100644 --- a/gtsam_unstable/nonlinear/tests/testExpression.cpp +++ b/gtsam_unstable/nonlinear/tests/testExpression.cpp @@ -119,15 +119,6 @@ TEST(Expression, NullaryMethod) { norm.dims(map); LONGS_EQUAL(1,map.size()); - // Get and check keys and dims - FastVector keys; - FastVector dims; - boost::tie(keys, dims) = norm.keysAndDims(); - LONGS_EQUAL(1,keys.size()); - LONGS_EQUAL(1,dims.size()); - LONGS_EQUAL(67,keys[0]); - LONGS_EQUAL(3,dims[0]); - // Get value and Jacobians std::vector H(1); double actual = norm.value(values, H); diff --git a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp index b9d9896d3..d146ea945 100644 --- a/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp +++ b/gtsam_unstable/nonlinear/tests/testExpressionFactor.cpp @@ -202,6 +202,17 @@ TEST(ExpressionFactor, Shallow) { // Construct expression, concise evrsion Point2_ expression = project(transform_to(x_, p_)); + // Get and check keys and dims + FastVector keys; + FastVector dims; + boost::tie(keys, dims) = expression.keysAndDims(); + LONGS_EQUAL(2,keys.size()); + LONGS_EQUAL(2,dims.size()); + LONGS_EQUAL(1,keys[0]); + LONGS_EQUAL(2,keys[1]); + LONGS_EQUAL(6,dims[0]); + LONGS_EQUAL(3,dims[1]); + // traceExecution of shallow tree typedef UnaryExpression Unary; typedef BinaryExpression Binary;