From 51281ea78f3feb458705192cffe3932ea7db92aa Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Wed, 24 Feb 2010 06:13:11 +0000 Subject: [PATCH] in-place colamd --- cpp/FactorGraph-inl.h | 28 ++++++++++++++++------------ cpp/FactorGraph.h | 7 ++----- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cpp/FactorGraph-inl.h b/cpp/FactorGraph-inl.h index 79d3b2e80..6ba612d0e 100644 --- a/cpp/FactorGraph-inl.h +++ b/cpp/FactorGraph-inl.h @@ -146,7 +146,7 @@ Ordering FactorGraph::keys() const { * @param columns map from keys to a sparse column of non-zero row indices */ template -boost::shared_ptr colamd(int n_col, int n_row, int nrNonZeros, const map >& columns) { +void colamd(int n_col, int n_row, int nrNonZeros, const map >& columns, Ordering& ordering) { // Convert to compressed column major format colamd wants it in (== MATLAB format!) vector initialOrder; @@ -177,16 +177,14 @@ boost::shared_ptr colamd(int n_col, int n_row, int nrNonZeros, const m delete [] A; // delete symbolic A // Convert elimination ordering in p to an ordering - boost::shared_ptr result(new Ordering); 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 - - return result; } + /* ************************************************************************* */ template -boost::shared_ptr FactorGraph::getOrdering_() const{ +void FactorGraph::getOrdering(Ordering& ordering) const{ // 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. @@ -202,18 +200,24 @@ boost::shared_ptr FactorGraph::getOrdering_() const{ nrNonZeros+= keys.size(); } int n_col = (int)(columns.size()); /* colamd arg 2: number of columns in A */ - - if(n_col == 0) - return boost::shared_ptr(new Ordering); // empty ordering - else - return colamd(n_col, n_row, nrNonZeros, columns); + if(n_col != 0) + return colamd(n_col, n_row, nrNonZeros, columns, ordering); } +/* ************************************************************************* */ +template +boost::shared_ptr FactorGraph::getOrdering_() const{ + boost::shared_ptr ordering(new Ordering); + getOrdering(*ordering); +} + /* ************************************************************************* */ template Ordering FactorGraph::getOrdering() const { - return *getOrdering_(); // empty ordering + Ordering ordering; + getOrdering(ordering); + return ordering; } /* ************************************************************************* */ diff --git a/cpp/FactorGraph.h b/cpp/FactorGraph.h index 101a5e9ee..fb0d32d79 100644 --- a/cpp/FactorGraph.h +++ b/cpp/FactorGraph.h @@ -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; - - /** - * shared pointer versions for MATLAB - */ boost::shared_ptr getOrdering_() const; /**