A bit of cleanup
parent
2c7d2dfff4
commit
83d87d0961
|
@ -53,10 +53,10 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex,
|
||||||
gttic(Ordering_COLAMDConstrained);
|
gttic(Ordering_COLAMDConstrained);
|
||||||
|
|
||||||
gttic(Prepare);
|
gttic(Prepare);
|
||||||
size_t nEntries = variableIndex.nEntries(), nFactors =
|
const size_t nEntries = variableIndex.nEntries(), nFactors =
|
||||||
variableIndex.nFactors(), nVars = variableIndex.size();
|
variableIndex.nFactors(), nVars = variableIndex.size();
|
||||||
// Convert to compressed column major format colamd wants it in (== MATLAB format!)
|
// 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 */
|
(int) nVars); /* colamd arg 3: size of the array A */
|
||||||
vector<int> A = vector<int>(Alen); /* colamd arg 4: row indices of A, of size Alen */
|
vector<int> A = vector<int>(Alen); /* colamd arg 4: row indices of A, of size Alen */
|
||||||
vector<int> p = vector<int>(nVars + 1); /* colamd arg 5: column pointers of A, of size n_col+1 */
|
vector<int> p = vector<int>(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;
|
int count = 0;
|
||||||
vector<Key> keys(nVars); // Array to store the keys in the order we add them so we can retrieve them in permuted order
|
vector<Key> 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;
|
size_t index = 0;
|
||||||
BOOST_FOREACH(const VariableIndex::value_type key_factors, variableIndex) {
|
for (auto key_factors: variableIndex) {
|
||||||
// Arrange factor indices into COLAMD format
|
// Arrange factor indices into COLAMD format
|
||||||
const VariableIndex::Factors& column = key_factors.second;
|
const VariableIndex::Factors& column = key_factors.second;
|
||||||
size_t lastFactorId = numeric_limits<size_t>::max();
|
for(size_t factorIndex: column) {
|
||||||
BOOST_FOREACH(size_t factorIndex, column) {
|
|
||||||
if (lastFactorId != numeric_limits<size_t>::max())
|
|
||||||
assert(factorIndex > lastFactorId);
|
|
||||||
A[count++] = (int) factorIndex; // copy sparse 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
|
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);
|
// ccolamd_report(stats);
|
||||||
|
|
||||||
gttic(Fill_Ordering);
|
|
||||||
// Convert elimination ordering in p to an ordering
|
// Convert elimination ordering in p to an ordering
|
||||||
|
gttic(Fill_Ordering);
|
||||||
Ordering result;
|
Ordering result;
|
||||||
result.resize(nVars);
|
result.resize(nVars);
|
||||||
for (size_t j = 0; j < nVars; ++j)
|
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
|
// Build a mapping to look up sorted Key indices by Key
|
||||||
FastMap<Key, size_t> keyIndices;
|
FastMap<Key, size_t> keyIndices;
|
||||||
size_t j = 0;
|
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++));
|
keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
|
||||||
|
|
||||||
// If at least some variables are not constrained to be last, constrain the
|
// If at least some variables are not constrained to be last, constrain the
|
||||||
// ones that should be constrained.
|
// ones that should be constrained.
|
||||||
int group = (constrainLast.size() != n ? 1 : 0);
|
int group = (constrainLast.size() != n ? 1 : 0);
|
||||||
BOOST_FOREACH(Key key, constrainLast) {
|
for (Key key: constrainLast) {
|
||||||
cmember[keyIndices.at(key)] = group;
|
cmember[keyIndices.at(key)] = group;
|
||||||
if (forceOrder)
|
if (forceOrder)
|
||||||
++group;
|
++group;
|
||||||
|
@ -155,13 +152,13 @@ Ordering Ordering::ColamdConstrainedFirst(const VariableIndex& variableIndex,
|
||||||
// Build a mapping to look up sorted Key indices by Key
|
// Build a mapping to look up sorted Key indices by Key
|
||||||
FastMap<Key, size_t> keyIndices;
|
FastMap<Key, size_t> keyIndices;
|
||||||
size_t j = 0;
|
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++));
|
keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
|
||||||
|
|
||||||
// If at least some variables are not constrained to be last, constrain the
|
// If at least some variables are not constrained to be last, constrain the
|
||||||
// ones that should be constrained.
|
// ones that should be constrained.
|
||||||
int group = 0;
|
int group = 0;
|
||||||
BOOST_FOREACH(Key key, constrainFirst) {
|
for (Key key: constrainFirst) {
|
||||||
cmember[keyIndices.at(key)] = group;
|
cmember[keyIndices.at(key)] = group;
|
||||||
if (forceOrder)
|
if (forceOrder)
|
||||||
++group;
|
++group;
|
||||||
|
@ -169,7 +166,7 @@ Ordering Ordering::ColamdConstrainedFirst(const VariableIndex& variableIndex,
|
||||||
|
|
||||||
if (!forceOrder && !constrainFirst.empty())
|
if (!forceOrder && !constrainFirst.empty())
|
||||||
++group;
|
++group;
|
||||||
BOOST_FOREACH(int& c, cmember)
|
for(int& c: cmember)
|
||||||
if (c == none)
|
if (c == none)
|
||||||
c = group;
|
c = group;
|
||||||
|
|
||||||
|
@ -186,12 +183,12 @@ Ordering Ordering::ColamdConstrained(const VariableIndex& variableIndex,
|
||||||
// Build a mapping to look up sorted Key indices by Key
|
// Build a mapping to look up sorted Key indices by Key
|
||||||
FastMap<Key, size_t> keyIndices;
|
FastMap<Key, size_t> keyIndices;
|
||||||
size_t j = 0;
|
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++));
|
keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
|
||||||
|
|
||||||
// Assign groups
|
// Assign groups
|
||||||
typedef FastMap<Key, int>::value_type key_group;
|
typedef FastMap<Key, int>::value_type key_group;
|
||||||
BOOST_FOREACH(const key_group& p, groups) {
|
for(const key_group& p: groups) {
|
||||||
// FIXME: check that no groups are skipped
|
// FIXME: check that no groups are skipped
|
||||||
cmember[keyIndices.at(p.first)] = p.second;
|
cmember[keyIndices.at(p.first)] = p.second;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,6 +172,7 @@ TEST(Ordering, csr_format_3) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
#ifdef GTSAM_SUPPORT_NESTED_DISSECTION
|
||||||
TEST(Ordering, csr_format_4) {
|
TEST(Ordering, csr_format_4) {
|
||||||
SymbolicFactorGraph sfg;
|
SymbolicFactorGraph sfg;
|
||||||
|
|
||||||
|
@ -206,8 +207,9 @@ TEST(Ordering, csr_format_4) {
|
||||||
|
|
||||||
Ordering metOrder2 = Ordering::Metis(sfg);
|
Ordering metOrder2 = Ordering::Metis(sfg);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
#ifdef GTSAM_SUPPORT_NESTED_DISSECTION
|
||||||
TEST(Ordering, metis) {
|
TEST(Ordering, metis) {
|
||||||
|
|
||||||
SymbolicFactorGraph sfg;
|
SymbolicFactorGraph sfg;
|
||||||
|
@ -228,8 +230,9 @@ TEST(Ordering, metis) {
|
||||||
|
|
||||||
Ordering metis = Ordering::Metis(sfg);
|
Ordering metis = Ordering::Metis(sfg);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
#ifdef GTSAM_SUPPORT_NESTED_DISSECTION
|
||||||
TEST(Ordering, MetisLoop) {
|
TEST(Ordering, MetisLoop) {
|
||||||
|
|
||||||
// create linear graph
|
// create linear graph
|
||||||
|
@ -261,7 +264,7 @@ TEST(Ordering, MetisLoop) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(Ordering, Create) {
|
TEST(Ordering, Create) {
|
||||||
|
|
||||||
|
@ -280,6 +283,7 @@ TEST(Ordering, Create) {
|
||||||
EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef GTSAM_SUPPORT_NESTED_DISSECTION
|
||||||
// METIS
|
// METIS
|
||||||
{
|
{
|
||||||
Ordering actual = Ordering::Create(Ordering::METIS, sfg);
|
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));
|
Ordering expected = Ordering(list_of(5)(3)(4)(1)(0)(2));
|
||||||
EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// CUSTOM
|
// CUSTOM
|
||||||
CHECK_EXCEPTION(Ordering::Create(Ordering::CUSTOM, sfg), runtime_error);
|
CHECK_EXCEPTION(Ordering::Create(Ordering::CUSTOM, sfg), runtime_error);
|
||||||
|
|
Loading…
Reference in New Issue