Made vaguely unsafe keysAndDims private (as it relies on keys and dimensions being in same order), as to not tempt people to use it.
parent
2ced73ebe1
commit
df91cf7fad
|
@ -45,8 +45,6 @@ public:
|
||||||
/// Define type so we can apply it as a meta-function
|
/// Define type so we can apply it as a meta-function
|
||||||
typedef Expression<T> type;
|
typedef Expression<T> type;
|
||||||
|
|
||||||
typedef std::pair<FastVector<Key>, FastVector<int> > KeysAndDims;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Paul's trick shared pointer, polymorphic root of entire expression tree
|
// Paul's trick shared pointer, polymorphic root of entire expression tree
|
||||||
|
@ -136,18 +134,6 @@ public:
|
||||||
root_->dims(map);
|
root_->dims(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return keys and dimensions as vectors in same order
|
|
||||||
KeysAndDims keysAndDims() const {
|
|
||||||
std::map<Key, int> map;
|
|
||||||
dims(map);
|
|
||||||
size_t n = map.size();
|
|
||||||
FastVector<Key> keys(n);
|
|
||||||
boost::copy(map | boost::adaptors::map_keys, keys.begin());
|
|
||||||
FastVector<int> 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
|
* @brief Return value and optional derivatives, reverse AD version
|
||||||
* Notes: this is not terribly efficient, and H should have correct size.
|
* Notes: this is not terribly efficient, and H should have correct size.
|
||||||
|
@ -165,6 +151,19 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/// Vaguely unsafe keys and dimensions in same order
|
||||||
|
typedef std::pair<FastVector<Key>, FastVector<int> > KeysAndDims;
|
||||||
|
KeysAndDims keysAndDims() const {
|
||||||
|
std::map<Key, int> map;
|
||||||
|
dims(map);
|
||||||
|
size_t n = map.size();
|
||||||
|
FastVector<Key> keys(n);
|
||||||
|
boost::copy(map | boost::adaptors::map_keys, keys.begin());
|
||||||
|
FastVector<int> 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
|
/// private version that takes keys and dimensions, returns derivatives
|
||||||
T value(const Values& values, const KeysAndDims& keysAndDims,
|
T value(const Values& values, const KeysAndDims& keysAndDims,
|
||||||
std::vector<Matrix>& H) const {
|
std::vector<Matrix>& H) const {
|
||||||
|
|
|
@ -119,15 +119,6 @@ TEST(Expression, NullaryMethod) {
|
||||||
norm.dims(map);
|
norm.dims(map);
|
||||||
LONGS_EQUAL(1,map.size());
|
LONGS_EQUAL(1,map.size());
|
||||||
|
|
||||||
// Get and check keys and dims
|
|
||||||
FastVector<Key> keys;
|
|
||||||
FastVector<int> 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
|
// Get value and Jacobians
|
||||||
std::vector<Matrix> H(1);
|
std::vector<Matrix> H(1);
|
||||||
double actual = norm.value(values, H);
|
double actual = norm.value(values, H);
|
||||||
|
|
|
@ -202,6 +202,17 @@ TEST(ExpressionFactor, Shallow) {
|
||||||
// Construct expression, concise evrsion
|
// Construct expression, concise evrsion
|
||||||
Point2_ expression = project(transform_to(x_, p_));
|
Point2_ expression = project(transform_to(x_, p_));
|
||||||
|
|
||||||
|
// Get and check keys and dims
|
||||||
|
FastVector<Key> keys;
|
||||||
|
FastVector<int> 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
|
// traceExecution of shallow tree
|
||||||
typedef UnaryExpression<Point2, Point3> Unary;
|
typedef UnaryExpression<Point2, Point3> Unary;
|
||||||
typedef BinaryExpression<Point3, Pose3, Point3> Binary;
|
typedef BinaryExpression<Point3, Pose3, Point3> Binary;
|
||||||
|
|
Loading…
Reference in New Issue