From 483e2ec9592f56bc47a1c0682abc93fd0c58f206 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 1 Aug 2012 13:42:38 +0000 Subject: [PATCH] Converted VariableIndex to use a deque instead of a vector. The deque performs incremental memory allocation, resulting in a significant speed improvement in iSAM2. --- gtsam/inference/VariableIndex.cpp | 2 +- gtsam/inference/VariableIndex.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gtsam/inference/VariableIndex.cpp b/gtsam/inference/VariableIndex.cpp index 4e5eb8649..b24e2f5fc 100644 --- a/gtsam/inference/VariableIndex.cpp +++ b/gtsam/inference/VariableIndex.cpp @@ -68,7 +68,7 @@ void VariableIndex::outputMetisFormat(ostream& os) const { /* ************************************************************************* */ void VariableIndex::permuteInPlace(const Permutation& permutation) { // Create new index and move references to data into it in permuted order - vector newIndex(this->size()); + deque newIndex(this->size()); for(Index i = 0; i < newIndex.size(); ++i) newIndex[i].swap(this->index_[permutation[i]]); diff --git a/gtsam/inference/VariableIndex.h b/gtsam/inference/VariableIndex.h index 739067dd2..d747d1122 100644 --- a/gtsam/inference/VariableIndex.h +++ b/gtsam/inference/VariableIndex.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include #include @@ -33,7 +34,7 @@ namespace gtsam { * factor graph. The factor graph stores a collection of factors, each of * which involves a set of variables. In contrast, the VariableIndex is built * from a factor graph prior to elimination, and stores the list of factors - * that involve each variable. This information is stored as a vector of + * that involve each variable. This information is stored as a deque of * lists of factor indices. * \nosubgrouping */ @@ -46,7 +47,7 @@ public: typedef Factors::const_iterator Factor_const_iterator; protected: - std::vector index_; + std::deque index_; size_t nFactors_; // Number of factors in the original factor graph. size_t nEntries_; // Sum of involved variable counts of each factor.