new method [keys]

release/4.3a0
Frank Dellaert 2009-09-12 03:50:44 +00:00
parent 78ac705d05
commit 14102e259e
3 changed files with 28 additions and 0 deletions

View File

@ -15,6 +15,7 @@ namespace ublas = boost::numeric::ublas;
// trick from some reading group
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
using namespace std;
using namespace gtsam;
typedef pair<const string, Matrix>& mypair;
@ -75,6 +76,15 @@ bool LinearFactor::equals(const Factor& f, double tol) const {
return false;
}
/* ************************************************************************* */
set<string> LinearFactor::keys() const {
set<string> result;
string j; Matrix A;
FOREACH_PAIR(j,A,As)
result.insert(j);
return result;
}
/* ************************************************************************* */
VariableSet LinearFactor::variables() const {
VariableSet result;

View File

@ -144,6 +144,12 @@ public:
*/
int numberOfRows() const { return b.size();}
/**
* Find all variables
* @return The set of all variable keys
*/
std::set<std::string> keys() const;
/**
* Find all variables and their dimensions
* @return The set of all variable/dimension pairs

View File

@ -42,6 +42,18 @@ TEST( LinearFactor, linearFactor )
CHECK( lf->equals(expected) );
}
/* ************************************************************************* */
TEST( LinearFactor, keys )
{
// get the factor "f2" from the small linear factor graph
LinearFactorGraph fg = createLinearFactorGraph();
LinearFactor::shared_ptr lf = fg[1];
set<string> expected;
expected.insert("x1");
expected.insert("x2");
CHECK(lf->keys() == expected);
}
/* ************************************************************************* */
TEST( LinearFactor, variables )
{