new method [keys]
parent
78ac705d05
commit
14102e259e
|
@ -15,6 +15,7 @@ namespace ublas = boost::numeric::ublas;
|
||||||
// trick from some reading group
|
// trick from some reading group
|
||||||
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
|
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
|
|
||||||
typedef pair<const string, Matrix>& mypair;
|
typedef pair<const string, Matrix>& mypair;
|
||||||
|
@ -75,6 +76,15 @@ bool LinearFactor::equals(const Factor& f, double tol) const {
|
||||||
return false;
|
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 LinearFactor::variables() const {
|
||||||
VariableSet result;
|
VariableSet result;
|
||||||
|
|
|
@ -144,6 +144,12 @@ public:
|
||||||
*/
|
*/
|
||||||
int numberOfRows() const { return b.size();}
|
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
|
* Find all variables and their dimensions
|
||||||
* @return The set of all variable/dimension pairs
|
* @return The set of all variable/dimension pairs
|
||||||
|
|
|
@ -42,6 +42,18 @@ TEST( LinearFactor, linearFactor )
|
||||||
CHECK( lf->equals(expected) );
|
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 )
|
TEST( LinearFactor, variables )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue