(in branch) Fixed Value base class assignment operator, ISAM2 expmap function, and unit tests

release/4.3a0
Richard Roberts 2012-01-30 21:23:02 +00:00
parent f86da6f983
commit 51dca5b2d0
9 changed files with 34 additions and 10 deletions

View File

@ -73,6 +73,23 @@ public:
return (static_cast<const DERIVED*>(this))->localCoordinates(derivedValue2); return (static_cast<const DERIVED*>(this))->localCoordinates(derivedValue2);
} }
/// Assignment operator
virtual Value& operator=(const Value& rhs) {
// Cast the base class Value pointer to a derived class pointer
const DERIVED& derivedRhs = dynamic_cast<const DERIVED&>(rhs);
// Do the assignment and return the result
return (static_cast<DERIVED*>(this))->operator=(derivedRhs);
}
protected:
/// Assignment operator, protected because only the Value or DERIVED
/// assignment operators should be used.
DerivedValue<DERIVED>& operator=(const DerivedValue<DERIVED>& rhs) {
// Nothing to do, do not call base class assignment operator
return *this;
}
}; };
} /* namespace gtsam */ } /* namespace gtsam */

View File

@ -136,6 +136,9 @@ namespace gtsam {
*/ */
virtual Vector localCoordinates_(const Value& value) const = 0; virtual Vector localCoordinates_(const Value& value) const = 0;
/** Assignment operator */
virtual Value& operator=(const Value& rhs) = 0;
/** Virutal destructor */ /** Virutal destructor */
virtual ~Value() {} virtual ~Value() {}

View File

@ -175,7 +175,7 @@ namespace gtsam {
/// @name Advanced Constructors /// @name Advanced Constructors
/// @{ /// @{
/** Construct from a container of variable dimensions (in variable order). */ /** Construct from a container of variable dimensions (in variable order), without initializing any values. */
template<class CONTAINER> template<class CONTAINER>
VectorValues(const CONTAINER& dimensions) { append(dimensions); } VectorValues(const CONTAINER& dimensions) { append(dimensions); }

View File

@ -245,10 +245,12 @@ struct _SelectiveExpmapAndClear {
else else
cout << " " << (string)it_x->first << " (j = " << var << "), delta = " << delta[var].transpose() << endl; cout << " " << (string)it_x->first << " (j = " << var << "), delta = " << delta[var].transpose() << endl;
} }
assert(delta[var].size() == (int)it_x->second.dim()); assert(delta[var].size() == (int)it_x->second->dim());
assert(delta[var].unaryExpr(&isfinite<double>).all()); assert(delta[var].unaryExpr(&isfinite<double>).all());
if(mask[var]) { if(mask[var]) {
it_x->second = it_x->second.retract(delta[var]); Value* retracted = it_x->second->retract_(delta[var]);
*it_x->second = *retracted;
retracted->deallocate_();
if(invalidate) if(invalidate)
(*invalidate)[var].operator=(Vector::Constant(delta[var].rows(), numeric_limits<double>::infinity())); // Strange syntax to work with clang++ (bug in clang?) (*invalidate)[var].operator=(Vector::Constant(delta[var].rows(), numeric_limits<double>::infinity())); // Strange syntax to work with clang++ (bug in clang?)
} }

View File

@ -162,7 +162,7 @@ TEST(DynamicValues, expmap_b)
config0.insert(key2, LieVector(3, 5.0, 6.0, 7.0)); config0.insert(key2, LieVector(3, 5.0, 6.0, 7.0));
Ordering ordering(*config0.orderingArbitrary()); Ordering ordering(*config0.orderingArbitrary());
VectorValues increment(config0.dims(ordering)); VectorValues increment(VectorValues::Zero(config0.dims(ordering)));
increment[ordering[key2]] = LieVector(3, 1.3, 1.4, 1.5); increment[ordering[key2]] = LieVector(3, 1.3, 1.4, 1.5);
DynamicValues expected; DynamicValues expected;

View File

@ -85,8 +85,6 @@ TEST( ProjectionFactor, error )
Point3 t2(1,1,-5); Pose3 x2(R,t2); expected_config.insert(PoseKey(1), x2); Point3 t2(1,1,-5); Pose3 x2(R,t2); expected_config.insert(PoseKey(1), x2);
Point3 l2(1,2,3); expected_config.insert(PointKey(1), l2); Point3 l2(1,2,3); expected_config.insert(PointKey(1), l2);
VectorValues delta(expected_config.dims(ordering)); VectorValues delta(expected_config.dims(ordering));
ordering.print("ordering: ");
delta.print("delta: ");
delta[ordering["x1"]] = Vector_(6, 0.,0.,0., 1.,1.,1.); delta[ordering["x1"]] = Vector_(6, 0.,0.,0., 1.,1.,1.);
delta[ordering["l1"]] = Vector_(3, 1.,2.,3.); delta[ordering["l1"]] = Vector_(3, 1.,2.,3.);
DynamicValues actual_config = config.retract(delta, ordering); DynamicValues actual_config = config.retract(delta, ordering);

View File

@ -20,7 +20,7 @@ check_PROGRAMS += testSymbolicBayesNet testSymbolicFactorGraph
check_PROGRAMS += testNonlinearISAM check_PROGRAMS += testNonlinearISAM
check_PROGRAMS += testBoundingConstraint check_PROGRAMS += testBoundingConstraint
#check_PROGRAMS += testPose2SLAMwSPCG #check_PROGRAMS += testPose2SLAMwSPCG
#check_PROGRAMS += testGaussianISAM2 check_PROGRAMS += testGaussianISAM2
check_PROGRAMS += testExtendedKalmanFilter check_PROGRAMS += testExtendedKalmanFilter
check_PROGRAMS += testRot3Optimization check_PROGRAMS += testRot3Optimization

View File

@ -365,8 +365,8 @@ public:
TEST( ExtendedKalmanFilter, nonlinear ) { TEST( ExtendedKalmanFilter, nonlinear ) {
// Create the set of expected output TestValues (generated using Matlab Kalman Filter) // Create the set of expected output TestValues (generated using Matlab Kalman Filter)
Point2 expected_predict[10]; Point2 expected_predict[11];
Point2 expected_update[10]; Point2 expected_update[11];
expected_predict[1] = Point2(0.81,0.99); expected_predict[1] = Point2(0.81,0.99);
expected_update[1] = Point2(0.824926197027,0.29509808); expected_update[1] = Point2(0.824926197027,0.29509808);
expected_predict[2] = Point2(0.680503230541,0.24343413); expected_predict[2] = Point2(0.680503230541,0.24343413);

View File

@ -75,8 +75,12 @@ TEST( Graph, keys )
/* ************************************************************************* */ /* ************************************************************************* */
TEST( Graph, GET_ORDERING) TEST( Graph, GET_ORDERING)
{ {
Ordering expected; expected += "x1","l1","x2"; // Ordering expected; expected += "x1","l1","x2"; // For starting with x1,x2,l1
Ordering expected; expected += "l1","x2","x1"; // For starting with l1,x1,x2
Graph nlfg = createNonlinearFactorGraph(); Graph nlfg = createNonlinearFactorGraph();
SymbolicFactorGraph::shared_ptr symbolic;
Ordering::shared_ptr ordering;
boost::tie(symbolic, ordering) = nlfg.symbolic(createNoisyValues());
Ordering actual = *nlfg.orderingCOLAMD(createNoisyValues()); Ordering actual = *nlfg.orderingCOLAMD(createNoisyValues());
CHECK(assert_equal(expected,actual)); CHECK(assert_equal(expected,actual));
} }