Finally gave in and made LinearFactorSet into a vector. Pragmatism wins.
parent
82d541f6a3
commit
ed616a26ed
|
@ -149,7 +149,7 @@ void MutableLinearFactor::append_factor(LinearFactor::shared_ptr f, const size_t
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
MutableLinearFactor::MutableLinearFactor(const set<shared_ptr> & factors)
|
MutableLinearFactor::MutableLinearFactor(const vector<shared_ptr> & factors)
|
||||||
{
|
{
|
||||||
// Create RHS vector of the right size by adding together row counts
|
// Create RHS vector of the right size by adding together row counts
|
||||||
size_t m = 0;
|
size_t m = 0;
|
||||||
|
|
|
@ -187,13 +187,10 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that combines a set of factors
|
* Constructor that combines a set of factors
|
||||||
* NOTE: the combined factor will be depends on a system-dependent
|
|
||||||
* ordering of the input set of factors. Do not rely on this order
|
|
||||||
* when using the function.
|
|
||||||
* @param factors Set of factors to combine
|
* @param factors Set of factors to combine
|
||||||
*/
|
*/
|
||||||
CONSTRUCTOR
|
CONSTRUCTOR
|
||||||
MutableLinearFactor(const std::set<shared_ptr> & factors);
|
MutableLinearFactor(const std::vector<shared_ptr> & factors);
|
||||||
|
|
||||||
/** Construct unary mutable factor */
|
/** Construct unary mutable factor */
|
||||||
CONSTRUCTOR
|
CONSTRUCTOR
|
||||||
|
|
|
@ -57,7 +57,7 @@ LinearFactorGraph::find_factors_and_remove(const string& key)
|
||||||
|
|
||||||
for(iterator factor=factors_.begin(); factor!=factors_.end(); )
|
for(iterator factor=factors_.begin(); factor!=factors_.end(); )
|
||||||
if ((*factor)->involves(key)) {
|
if ((*factor)->involves(key)) {
|
||||||
found.insert(*factor);
|
found.push_back(*factor);
|
||||||
factor = factors_.erase(factor);
|
factor = factors_.erase(factor);
|
||||||
} else {
|
} else {
|
||||||
factor++; // important, erase will have effect of ++
|
factor++; // important, erase will have effect of ++
|
||||||
|
@ -219,7 +219,7 @@ pair<Matrix,Vector> LinearFactorGraph::matrix(const Ordering& ordering) const {
|
||||||
// get all factors
|
// get all factors
|
||||||
LinearFactorSet found;
|
LinearFactorSet found;
|
||||||
BOOST_FOREACH(shared_factor factor,factors_)
|
BOOST_FOREACH(shared_factor factor,factors_)
|
||||||
found.insert(factor);
|
found.push_back(factor);
|
||||||
|
|
||||||
// combine them
|
// combine them
|
||||||
MutableLinearFactor lf(found);
|
MutableLinearFactor lf(found);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "LinearFactor.h"
|
#include "LinearFactor.h"
|
||||||
//#include "Ordering.h"
|
|
||||||
#include "VectorConfig.h"
|
#include "VectorConfig.h"
|
||||||
#include "FactorGraph.h"
|
#include "FactorGraph.h"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ namespace gtsam {
|
||||||
|
|
||||||
class LinearFactor;
|
class LinearFactor;
|
||||||
|
|
||||||
struct LinearFactorSet : std::set<boost::shared_ptr<LinearFactor> > {
|
// We use a vector not a an STL set, to get predictable ordering across platforms
|
||||||
|
struct LinearFactorSet : std::vector<boost::shared_ptr<LinearFactor> > {
|
||||||
LinearFactorSet() {}
|
LinearFactorSet() {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,19 +64,15 @@ TEST( LinearFactor, variables )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
||||||
// NOTE: This test fails due to order dependency in the extraction of factors
|
|
||||||
// To fix it, it will be necessary to construct the expected version
|
|
||||||
// of the combined factor taking into account the ordering in the set
|
|
||||||
TEST( LinearFactor, linearFactor2 )
|
TEST( LinearFactor, linearFactor2 )
|
||||||
{
|
{
|
||||||
// create a small linear factor graph
|
// create a small linear factor graph
|
||||||
LinearFactorGraph fg = createLinearFactorGraph();
|
LinearFactorGraph fg = createLinearFactorGraph();
|
||||||
|
|
||||||
// get two factors from it and insert the factors into a set
|
// get two factors from it and insert the factors into a set
|
||||||
std::set<LinearFactor::shared_ptr> lfg;
|
vector<LinearFactor::shared_ptr> lfg;
|
||||||
lfg.insert(fg[4 - 1]);
|
lfg.push_back(fg[4 - 1]);
|
||||||
lfg.insert(fg[2 - 1]);
|
lfg.push_back(fg[2 - 1]);
|
||||||
|
|
||||||
// combine in a factor
|
// combine in a factor
|
||||||
MutableLinearFactor combined(lfg);
|
MutableLinearFactor combined(lfg);
|
||||||
|
@ -137,11 +133,11 @@ TEST( NonlinearFactorGraph, linearFactor3){
|
||||||
b(0) = 5 ; b(1) = -6;
|
b(0) = 5 ; b(1) = -6;
|
||||||
LinearFactor::shared_ptr f4(new LinearFactor("x1", A11, b));
|
LinearFactor::shared_ptr f4(new LinearFactor("x1", A11, b));
|
||||||
|
|
||||||
std::set<LinearFactor::shared_ptr> lfg;
|
vector<LinearFactor::shared_ptr> lfg;
|
||||||
lfg.insert(f1);
|
lfg.push_back(f1);
|
||||||
lfg.insert(f2);
|
lfg.push_back(f2);
|
||||||
lfg.insert(f3);
|
lfg.push_back(f3);
|
||||||
lfg.insert(f4);
|
lfg.push_back(f4);
|
||||||
MutableLinearFactor combined(lfg);
|
MutableLinearFactor combined(lfg);
|
||||||
|
|
||||||
Matrix A22(8,2);
|
Matrix A22(8,2);
|
||||||
|
|
Loading…
Reference in New Issue