implement getOrdering_ to work in matlab
parent
a1e90af90f
commit
8a9f05059c
|
@ -127,7 +127,7 @@ Ordering FactorGraph<Factor>::keys() const {
|
||||||
* @param columns map from keys to a sparse column of non-zero row indices
|
* @param columns map from keys to a sparse column of non-zero row indices
|
||||||
*/
|
*/
|
||||||
template <class Key>
|
template <class Key>
|
||||||
Ordering colamd(int n_col, int n_row, int nrNonZeros, const map<Key, vector<int> >& columns) {
|
boost::shared_ptr<Ordering> colamd(int n_col, int n_row, int nrNonZeros, const map<Key, vector<int> >& columns) {
|
||||||
|
|
||||||
// Convert to compressed column major format colamd wants it in (== MATLAB format!)
|
// Convert to compressed column major format colamd wants it in (== MATLAB format!)
|
||||||
vector<Key> initialOrder;
|
vector<Key> initialOrder;
|
||||||
|
@ -158,17 +158,16 @@ Ordering colamd(int n_col, int n_row, int nrNonZeros, const map<Key, vector<int>
|
||||||
delete [] A; // delete symbolic A
|
delete [] A; // delete symbolic A
|
||||||
|
|
||||||
// Convert elimination ordering in p to an ordering
|
// Convert elimination ordering in p to an ordering
|
||||||
Ordering result;
|
boost::shared_ptr<Ordering> result(new Ordering);
|
||||||
for(int j = 0; j < n_col; j++)
|
for(int j = 0; j < n_col; j++)
|
||||||
result.push_back(initialOrder[j]);
|
result->push_back(initialOrder[j]);
|
||||||
delete [] p; // delete colamd result vector
|
delete [] p; // delete colamd result vector
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class Factor>
|
template<class Factor>
|
||||||
Ordering FactorGraph<Factor>::getOrdering() const {
|
boost::shared_ptr<Ordering> FactorGraph<Factor>::getOrdering_() const{
|
||||||
|
|
||||||
// A factor graph is really laid out in row-major format, each factor a row
|
// A factor graph is really laid out in row-major format, each factor a row
|
||||||
// Below, we compute a symbolic matrix stored in sparse columns.
|
// Below, we compute a symbolic matrix stored in sparse columns.
|
||||||
|
@ -187,11 +186,18 @@ Ordering FactorGraph<Factor>::getOrdering() const {
|
||||||
int n_col = (int)(columns.size()); /* colamd arg 2: number of columns in A */
|
int n_col = (int)(columns.size()); /* colamd arg 2: number of columns in A */
|
||||||
|
|
||||||
if(n_col == 0)
|
if(n_col == 0)
|
||||||
return Ordering(); // empty ordering
|
return boost::shared_ptr<Ordering>(new Ordering); // empty ordering
|
||||||
else
|
else
|
||||||
return colamd(n_col, n_row, nrNonZeros, columns);
|
return colamd(n_col, n_row, nrNonZeros, columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
template<class Factor>
|
||||||
|
Ordering FactorGraph<Factor>::getOrdering() const {
|
||||||
|
return *getOrdering_(); // empty ordering
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
/** O(1) */
|
/** O(1) */
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -92,6 +92,11 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
Ordering getOrdering() const;
|
Ordering getOrdering() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shared pointer versions for MATLAB
|
||||||
|
*/
|
||||||
|
boost::shared_ptr<Ordering> getOrdering_() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return indices for all factors that involve the given node
|
* Return indices for all factors that involve the given node
|
||||||
* @param key the key for the given node
|
* @param key the key for the given node
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "Pose2Factor.h"
|
#include "Pose2Factor.h"
|
||||||
#include "Pose2Config.h"
|
#include "Pose2Config.h"
|
||||||
#include "Testable.h"
|
#include "Testable.h"
|
||||||
|
#include "Ordering.h"
|
||||||
|
|
||||||
namespace gtsam{
|
namespace gtsam{
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,7 @@ class Pose2Graph{
|
||||||
bool equals(const Pose2Graph& p, double tol) const;
|
bool equals(const Pose2Graph& p, double tol) const;
|
||||||
GaussianFactorGraph* linearize_(const Pose2Config& config) const;
|
GaussianFactorGraph* linearize_(const Pose2Config& config) const;
|
||||||
void push_back(Pose2Factor* factor);
|
void push_back(Pose2Factor* factor);
|
||||||
|
Ordering* getOrdering_() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ double tol=1e-4;
|
||||||
TEST( GaussianFactorGraph, equals ){
|
TEST( GaussianFactorGraph, equals ){
|
||||||
|
|
||||||
GaussianFactorGraph fg = createGaussianFactorGraph();
|
GaussianFactorGraph fg = createGaussianFactorGraph();
|
||||||
fg.print("fg");
|
|
||||||
GaussianFactorGraph fg2 = createGaussianFactorGraph();
|
GaussianFactorGraph fg2 = createGaussianFactorGraph();
|
||||||
CHECK(fg.equals(fg2));
|
CHECK(fg.equals(fg2));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue