From 83d87d09614d48765538dc383d124a284961f128 Mon Sep 17 00:00:00 2001 From: dellaert Date: Sat, 16 Apr 2016 13:12:36 -0700 Subject: [PATCH] A bit of cleanup --- gtsam/inference/Ordering.cpp | 27 ++++++++++++-------------- gtsam/inference/tests/testOrdering.cpp | 11 ++++++++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/gtsam/inference/Ordering.cpp b/gtsam/inference/Ordering.cpp index 3e3b40f8f..931610639 100644 --- a/gtsam/inference/Ordering.cpp +++ b/gtsam/inference/Ordering.cpp @@ -53,10 +53,10 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex, gttic(Ordering_COLAMDConstrained); gttic(Prepare); - size_t nEntries = variableIndex.nEntries(), nFactors = + const size_t nEntries = variableIndex.nEntries(), nFactors = variableIndex.nFactors(), nVars = variableIndex.size(); // Convert to compressed column major format colamd wants it in (== MATLAB format!) - size_t Alen = ccolamd_recommended((int) nEntries, (int) nFactors, + const size_t Alen = ccolamd_recommended((int) nEntries, (int) nFactors, (int) nVars); /* colamd arg 3: size of the array A */ vector A = vector(Alen); /* colamd arg 4: row indices of A, of size Alen */ vector p = vector(nVars + 1); /* colamd arg 5: column pointers of A, of size n_col+1 */ @@ -66,13 +66,10 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex, int count = 0; vector keys(nVars); // Array to store the keys in the order we add them so we can retrieve them in permuted order size_t index = 0; - BOOST_FOREACH(const VariableIndex::value_type key_factors, variableIndex) { + for (auto key_factors: variableIndex) { // Arrange factor indices into COLAMD format const VariableIndex::Factors& column = key_factors.second; - size_t lastFactorId = numeric_limits::max(); - BOOST_FOREACH(size_t factorIndex, column) { - if (lastFactorId != numeric_limits::max()) - assert(factorIndex > lastFactorId); + for(size_t factorIndex: column) { A[count++] = (int) factorIndex; // copy sparse column } p[index + 1] = count; // column j (base 1) goes from A[j-1] to A[j]-1 @@ -106,8 +103,8 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex, // ccolamd_report(stats); - gttic(Fill_Ordering); // Convert elimination ordering in p to an ordering + gttic(Fill_Ordering); Ordering result; result.resize(nVars); for (size_t j = 0; j < nVars; ++j) @@ -128,13 +125,13 @@ Ordering Ordering::ColamdConstrainedLast(const VariableIndex& variableIndex, // Build a mapping to look up sorted Key indices by Key FastMap keyIndices; size_t j = 0; - BOOST_FOREACH(const VariableIndex::value_type key_factors, variableIndex) + for (auto key_factors: variableIndex) keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++)); // If at least some variables are not constrained to be last, constrain the // ones that should be constrained. int group = (constrainLast.size() != n ? 1 : 0); - BOOST_FOREACH(Key key, constrainLast) { + for (Key key: constrainLast) { cmember[keyIndices.at(key)] = group; if (forceOrder) ++group; @@ -155,13 +152,13 @@ Ordering Ordering::ColamdConstrainedFirst(const VariableIndex& variableIndex, // Build a mapping to look up sorted Key indices by Key FastMap keyIndices; size_t j = 0; - BOOST_FOREACH(const VariableIndex::value_type key_factors, variableIndex) + for (auto key_factors: variableIndex) keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++)); // If at least some variables are not constrained to be last, constrain the // ones that should be constrained. int group = 0; - BOOST_FOREACH(Key key, constrainFirst) { + for (Key key: constrainFirst) { cmember[keyIndices.at(key)] = group; if (forceOrder) ++group; @@ -169,7 +166,7 @@ Ordering Ordering::ColamdConstrainedFirst(const VariableIndex& variableIndex, if (!forceOrder && !constrainFirst.empty()) ++group; - BOOST_FOREACH(int& c, cmember) + for(int& c: cmember) if (c == none) c = group; @@ -186,12 +183,12 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex, // Build a mapping to look up sorted Key indices by Key FastMap keyIndices; size_t j = 0; - BOOST_FOREACH(const VariableIndex::value_type key_factors, variableIndex) + for (auto key_factors: variableIndex) keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++)); // Assign groups typedef FastMap::value_type key_group; - BOOST_FOREACH(const key_group& p, groups) { + for(const key_group& p: groups) { // FIXME: check that no groups are skipped cmember[keyIndices.at(p.first)] = p.second; } diff --git a/gtsam/inference/tests/testOrdering.cpp b/gtsam/inference/tests/testOrdering.cpp index c209d086b..52528ad7f 100644 --- a/gtsam/inference/tests/testOrdering.cpp +++ b/gtsam/inference/tests/testOrdering.cpp @@ -172,6 +172,7 @@ TEST(Ordering, csr_format_3) { } /* ************************************************************************* */ +#ifdef GTSAM_SUPPORT_NESTED_DISSECTION TEST(Ordering, csr_format_4) { SymbolicFactorGraph sfg; @@ -206,8 +207,9 @@ TEST(Ordering, csr_format_4) { Ordering metOrder2 = Ordering::Metis(sfg); } - +#endif /* ************************************************************************* */ +#ifdef GTSAM_SUPPORT_NESTED_DISSECTION TEST(Ordering, metis) { SymbolicFactorGraph sfg; @@ -228,8 +230,9 @@ TEST(Ordering, metis) { Ordering metis = Ordering::Metis(sfg); } - +#endif /* ************************************************************************* */ +#ifdef GTSAM_SUPPORT_NESTED_DISSECTION TEST(Ordering, MetisLoop) { // create linear graph @@ -261,7 +264,7 @@ TEST(Ordering, MetisLoop) { } #endif } - +#endif /* ************************************************************************* */ TEST(Ordering, Create) { @@ -280,6 +283,7 @@ TEST(Ordering, Create) { EXPECT(assert_equal(expected, actual)); } +#ifdef GTSAM_SUPPORT_NESTED_DISSECTION // METIS { Ordering actual = Ordering::Create(Ordering::METIS, sfg); @@ -289,6 +293,7 @@ TEST(Ordering, Create) { Ordering expected = Ordering(list_of(5)(3)(4)(1)(0)(2)); EXPECT(assert_equal(expected, actual)); } +#endif // CUSTOM CHECK_EXCEPTION(Ordering::Create(Ordering::CUSTOM, sfg), runtime_error);