Refactored templates so we can get rid of FactorGraph include for faster/tighter compile

release/4.3a0
Frank Dellaert 2018-11-06 00:18:45 -05:00
parent f7bd2a5fa4
commit 68f1cbdb08
1 changed files with 18 additions and 17 deletions

View File

@ -11,8 +11,10 @@
/** /**
* @file Ordering.h * @file Ordering.h
* @brief Variable ordering for the elimination algorithm
* @author Richard Roberts * @author Richard Roberts
* @author Andrew Melim * @author Andrew Melim
* @author Frank Dellaert
* @date Sep 2, 2010 * @date Sep 2, 2010
*/ */
@ -21,7 +23,6 @@
#include <gtsam/inference/Key.h> #include <gtsam/inference/Key.h>
#include <gtsam/inference/VariableIndex.h> #include <gtsam/inference/VariableIndex.h>
#include <gtsam/inference/MetisIndex.h> #include <gtsam/inference/MetisIndex.h>
#include <gtsam/inference/FactorGraph.h>
#include <gtsam/base/FastSet.h> #include <gtsam/base/FastSet.h>
#include <boost/assign/list_inserter.hpp> #include <boost/assign/list_inserter.hpp>
@ -77,8 +78,8 @@ public:
/// Compute a fill-reducing ordering using COLAMD from a factor graph (see details for note on /// Compute a fill-reducing ordering using COLAMD from a factor graph (see details for note on
/// performance). This internally builds a VariableIndex so if you already have a VariableIndex, /// performance). This internally builds a VariableIndex so if you already have a VariableIndex,
/// it is faster to use COLAMD(const VariableIndex&) /// it is faster to use COLAMD(const VariableIndex&)
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering Colamd(const FactorGraph<FACTOR>& graph) { static Ordering Colamd(const FACTOR_GRAPH& graph) {
if (graph.empty()) if (graph.empty())
return Ordering(); return Ordering();
else else
@ -96,8 +97,8 @@ public:
/// constrainLast will be ordered in the same order specified in the vector<Key> \c /// constrainLast will be ordered in the same order specified in the vector<Key> \c
/// constrainLast. If \c forceOrder is false, the variables in \c constrainLast will be /// constrainLast. If \c forceOrder is false, the variables in \c constrainLast will be
/// ordered after all the others, but will be rearranged by CCOLAMD to reduce fill-in as well. /// ordered after all the others, but will be rearranged by CCOLAMD to reduce fill-in as well.
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering ColamdConstrainedLast(const FactorGraph<FACTOR>& graph, static Ordering ColamdConstrainedLast(const FACTOR_GRAPH& graph,
const std::vector<Key>& constrainLast, bool forceOrder = false) { const std::vector<Key>& constrainLast, bool forceOrder = false) {
if (graph.empty()) if (graph.empty())
return Ordering(); return Ordering();
@ -123,8 +124,8 @@ public:
/// constrainFirst will be ordered in the same order specified in the vector<Key> \c /// constrainFirst will be ordered in the same order specified in the vector<Key> \c
/// constrainFirst. If \c forceOrder is false, the variables in \c constrainFirst will be /// constrainFirst. If \c forceOrder is false, the variables in \c constrainFirst will be
/// ordered before all the others, but will be rearranged by CCOLAMD to reduce fill-in as well. /// ordered before all the others, but will be rearranged by CCOLAMD to reduce fill-in as well.
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering ColamdConstrainedFirst(const FactorGraph<FACTOR>& graph, static Ordering ColamdConstrainedFirst(const FACTOR_GRAPH& graph,
const std::vector<Key>& constrainFirst, bool forceOrder = false) { const std::vector<Key>& constrainFirst, bool forceOrder = false) {
if (graph.empty()) if (graph.empty())
return Ordering(); return Ordering();
@ -152,8 +153,8 @@ public:
/// arbitrary order. Any variables not present in \c groups will be assigned to group 0. This /// arbitrary order. Any variables not present in \c groups will be assigned to group 0. This
/// function simply fills the \c cmember argument to CCOLAMD with the supplied indices, see the /// function simply fills the \c cmember argument to CCOLAMD with the supplied indices, see the
/// CCOLAMD documentation for more information. /// CCOLAMD documentation for more information.
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering ColamdConstrained(const FactorGraph<FACTOR>& graph, static Ordering ColamdConstrained(const FACTOR_GRAPH& graph,
const FastMap<Key, int>& groups) { const FastMap<Key, int>& groups) {
if (graph.empty()) if (graph.empty())
return Ordering(); return Ordering();
@ -172,8 +173,8 @@ public:
const VariableIndex& variableIndex, const FastMap<Key, int>& groups); const VariableIndex& variableIndex, const FastMap<Key, int>& groups);
/// Return a natural Ordering. Typically used by iterative solvers /// Return a natural Ordering. Typically used by iterative solvers
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering Natural(const FactorGraph<FACTOR> &fg) { static Ordering Natural(const FACTOR_GRAPH &fg) {
KeySet src = fg.keys(); KeySet src = fg.keys();
std::vector<Key> keys(src.begin(), src.end()); std::vector<Key> keys(src.begin(), src.end());
std::stable_sort(keys.begin(), keys.end()); std::stable_sort(keys.begin(), keys.end());
@ -181,15 +182,15 @@ public:
} }
/// METIS Formatting function /// METIS Formatting function
template<class FACTOR> template<class FACTOR_GRAPH>
static GTSAM_EXPORT void CSRFormat(std::vector<int>& xadj, static GTSAM_EXPORT void CSRFormat(std::vector<int>& xadj,
std::vector<int>& adj, const FactorGraph<FACTOR>& graph); std::vector<int>& adj, const FACTOR_GRAPH& graph);
/// Compute an ordering determined by METIS from a VariableIndex /// Compute an ordering determined by METIS from a VariableIndex
static GTSAM_EXPORT Ordering Metis(const MetisIndex& met); static GTSAM_EXPORT Ordering Metis(const MetisIndex& met);
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering Metis(const FactorGraph<FACTOR>& graph) { static Ordering Metis(const FACTOR_GRAPH& graph) {
return Metis(MetisIndex(graph)); return Metis(MetisIndex(graph));
} }
@ -197,9 +198,9 @@ public:
/// @name Named Constructors @{ /// @name Named Constructors @{
template<class FACTOR> template<class FACTOR_GRAPH>
static Ordering Create(OrderingType orderingType, static Ordering Create(OrderingType orderingType,
const FactorGraph<FACTOR>& graph) { const FACTOR_GRAPH& graph) {
if (graph.empty()) if (graph.empty())
return Ordering(); return Ordering();