Fixed calculate_nnz and added unit test

release/4.3a0
Richard Roberts 2013-10-03 16:50:20 +00:00
parent 19602bbb0b
commit 3c68d20ff2
2 changed files with 13 additions and 3 deletions

View File

@ -283,11 +283,11 @@ size_t optimizeWildfireNonRecursive(const boost::shared_ptr<CLIQUE>& root, doubl
/* ************************************************************************* */ /* ************************************************************************* */
template<class CLIQUE> template<class CLIQUE>
void nnz_internal(const boost::shared_ptr<CLIQUE>& clique, int& result) { void nnz_internal(const boost::shared_ptr<CLIQUE>& clique, int& result) {
int dimR = (*clique)->dim(); int dimR = clique->conditional()->rows();
int dimSep = (*clique)->get_S().cols() - dimR; int dimSep = clique->conditional()->get_S().cols();
result += ((dimR+1)*dimR)/2 + dimSep*dimR; result += ((dimR+1)*dimR)/2 + dimSep*dimR;
// traverse the children // traverse the children
BOOST_FOREACH(const typename CLIQUE::shared_ptr& child, clique->children_) { BOOST_FOREACH(const typename CLIQUE::shared_ptr& child, clique->children) {
nnz_internal(child, result); nnz_internal(child, result);
} }
} }

View File

@ -815,6 +815,16 @@ TEST(ISAM2, marginalCovariance)
EXPECT(assert_equal(expected, actual)); EXPECT(assert_equal(expected, actual));
} }
/* ************************************************************************* */
TEST(ISAM2, calculate_nnz)
{
ISAM2 isam = createSlamlikeISAM2();
int expected = 262;
int actual = calculate_nnz(isam.roots().front());
EXPECT_LONGS_EQUAL(expected, actual);
}
/* ************************************************************************* */ /* ************************************************************************* */
int main() { TestResult tr; return TestRegistry::runAllTests(tr);} int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
/* ************************************************************************* */ /* ************************************************************************* */