in-place colamd

release/4.3a0
Frank Dellaert 2010-02-24 06:13:11 +00:00
parent 71089a6354
commit 51281ea78f
2 changed files with 18 additions and 17 deletions

View File

@ -146,7 +146,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>
boost::shared_ptr<Ordering> colamd(int n_col, int n_row, int nrNonZeros, const map<Key, vector<int> >& columns) { void colamd(int n_col, int n_row, int nrNonZeros, const map<Key, vector<int> >& columns, Ordering& ordering) {
// 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;
@ -177,16 +177,14 @@ boost::shared_ptr<Ordering> colamd(int n_col, int n_row, int nrNonZeros, const m
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
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[p[j]]); ordering.push_back(initialOrder[p[j]]);
delete [] p; // delete colamd result vector delete [] p; // delete colamd result vector
return result;
} }
/* ************************************************************************* */ /* ************************************************************************* */
template<class Factor> template<class Factor>
boost::shared_ptr<Ordering> FactorGraph<Factor>::getOrdering_() const{ void FactorGraph<Factor>::getOrdering(Ordering& ordering) 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.
@ -202,18 +200,24 @@ boost::shared_ptr<Ordering> FactorGraph<Factor>::getOrdering_() const{
nrNonZeros+= keys.size(); nrNonZeros+= keys.size();
} }
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 colamd(n_col, n_row, nrNonZeros, columns, ordering);
return boost::shared_ptr<Ordering>(new Ordering); // empty ordering
else
return colamd(n_col, n_row, nrNonZeros, columns);
} }
/* ************************************************************************* */
template<class Factor>
boost::shared_ptr<Ordering> FactorGraph<Factor>::getOrdering_() const{
boost::shared_ptr<Ordering> ordering(new Ordering);
getOrdering(*ordering);
}
/* ************************************************************************* */ /* ************************************************************************* */
template<class Factor> template<class Factor>
Ordering FactorGraph<Factor>::getOrdering() const { Ordering FactorGraph<Factor>::getOrdering() const {
return *getOrdering_(); // empty ordering Ordering ordering;
getOrdering(ordering);
return ordering;
} }
/* ************************************************************************* */ /* ************************************************************************* */

View File

@ -98,13 +98,10 @@ namespace gtsam {
} }
/** /**
* Compute colamd ordering * Compute colamd ordering, including I/O and shared pointer version
*/ */
void getOrdering(Ordering& ordering) const;
Ordering getOrdering() const; Ordering getOrdering() const;
/**
* shared pointer versions for MATLAB
*/
boost::shared_ptr<Ordering> getOrdering_() const; boost::shared_ptr<Ordering> getOrdering_() const;
/** /**