diff --git a/gtsam/base/FastVector.h b/gtsam/base/FastVector.h index 18af63006..cb08871d9 100644 --- a/gtsam/base/FastVector.h +++ b/gtsam/base/FastVector.h @@ -50,29 +50,14 @@ public: /** Constructor from a range, passes through to base class */ template - explicit FastVector(INPUTITERATOR first, INPUTITERATOR last) { - // This if statement works around a bug in boost pool allocator and/or - // STL vector where if the size is zero, the pool allocator will allocate - // huge amounts of memory. - if(first != last) - Base::assign(first, last); - } + explicit FastVector(INPUTITERATOR first, INPUTITERATOR last) : Base(first, last) {} /** Copy constructor from another FastSet */ FastVector(const FastVector& x) : Base(x) {} - /** Copy constructor from the base class */ + /** Copy constructor from the base map class */ FastVector(const Base& x) : Base(x) {} - /** Copy constructor from a standard STL container */ - FastVector(const std::vector& x) { - // This if statement works around a bug in boost pool allocator and/or - // STL vector where if the size is zero, the pool allocator will allocate - // huge amounts of memory. - if(x.size() > 0) - Base::assign(x.begin(), x.end()); - } - private: /** Serialization function */ friend class boost::serialization::access; diff --git a/gtsam/base/Lie.h b/gtsam/base/Lie.h index a770d9975..bc530a9f5 100644 --- a/gtsam/base/Lie.h +++ b/gtsam/base/Lie.h @@ -133,7 +133,7 @@ template Matrix wedge(const Vector& x); template T expm(const Vector& x, int K=7) { Matrix xhat = wedge(x); - return T(expm(xhat,K)); + return expm(xhat,K); } } // namespace gtsam diff --git a/gtsam/inference/BayesTree.h b/gtsam/inference/BayesTree.h index 3dc73519a..87788e3d8 100644 --- a/gtsam/inference/BayesTree.h +++ b/gtsam/inference/BayesTree.h @@ -297,7 +297,7 @@ namespace gtsam { /* ************************************************************************* */ template void _BayesTree_dim_adder( - FastVector& dims, + std::vector& dims, const typename BayesTree::sharedClique& clique) { if(clique) { @@ -316,7 +316,7 @@ namespace gtsam { /* ************************************************************************* */ template boost::shared_ptr allocateVectorValues(const BayesTree& bt) { - FastVector dimensions(bt.nodes().size(), 0); + std::vector dimensions(bt.nodes().size(), 0); _BayesTree_dim_adder(dimensions, bt.root()); return boost::shared_ptr(new VectorValues(dimensions)); } diff --git a/gtsam/inference/BayesTreeCliqueBase-inl.h b/gtsam/inference/BayesTreeCliqueBase-inl.h index 1b4d92cae..dfc8864f7 100644 --- a/gtsam/inference/BayesTreeCliqueBase-inl.h +++ b/gtsam/inference/BayesTreeCliqueBase-inl.h @@ -223,7 +223,7 @@ namespace gtsam { assertInvariants(); GenericSequentialSolver solver(p_FSR); - return *solver.jointFactorGraph(vector(conditional_->keys().begin(), conditional_->keys().end()), function); + return *solver.jointFactorGraph(conditional_->keys(), function); } /* ************************************************************************* */ @@ -243,8 +243,8 @@ namespace gtsam { joint.push_back(R->conditional()->toFactor()); // P(R) // Find the keys of both C1 and C2 - const FastVector& keys1(conditional_->keys()); - const FastVector& keys2(C2->conditional_->keys()); + std::vector keys1(conditional_->keys()); + std::vector keys2(C2->conditional_->keys()); FastSet keys12; keys12.insert(keys1.begin(), keys1.end()); keys12.insert(keys2.begin(), keys2.end()); diff --git a/gtsam/inference/ClusterTree.h b/gtsam/inference/ClusterTree.h index 9e82aae18..7544587c1 100644 --- a/gtsam/inference/ClusterTree.h +++ b/gtsam/inference/ClusterTree.h @@ -20,13 +20,12 @@ #pragma once #include +#include #include #include #include -#include -#include namespace gtsam { @@ -47,13 +46,13 @@ namespace gtsam { typedef typename boost::shared_ptr shared_ptr; typedef typename boost::weak_ptr weak_ptr; - const FastVector frontal; // the frontal variables - const FastVector separator; // the separator variables + const std::vector frontal; // the frontal variables + const std::vector separator; // the separator variables protected: weak_ptr parent_; // the parent cluster - FastList children_; // the child clusters + std::list children_; // the child clusters const typename FG::sharedFactor eliminated_; // the eliminated factor to pass on to the parent public: @@ -83,7 +82,7 @@ namespace gtsam { bool equals(const Cluster& other) const; /// get a reference to the children - const FastList& children() const { return children_; } + const std::list& children() const { return children_; } /// add a child void addChild(shared_ptr child); diff --git a/gtsam/inference/Conditional.h b/gtsam/inference/Conditional.h index a2f5bd7a1..2fa5f691d 100644 --- a/gtsam/inference/Conditional.h +++ b/gtsam/inference/Conditional.h @@ -45,8 +45,8 @@ private: /** Create keys by adding key in front */ template - static FastVector MakeKeys(KEY key, ITERATOR firstParent, ITERATOR lastParent) { - FastVector keys((lastParent - firstParent) + 1); + static std::vector MakeKeys(KEY key, ITERATOR firstParent, ITERATOR lastParent) { + std::vector keys((lastParent - firstParent) + 1); std::copy(firstParent, lastParent, keys.begin() + 1); keys[0] = key; return keys; @@ -116,14 +116,8 @@ public: assertInvariants(); } - /** Constructor from a frontal variable and a vector of parents */ - Conditional(Key key, const FastVector& parents) : - FactorType(MakeKeys(key, parents.begin(), parents.end())), nrFrontals_(1) { - assertInvariants(); - } - /** Constructor from keys and nr of frontal variables */ - Conditional(const FastVector& keys, size_t nrFrontals) : + Conditional(const std::vector& keys, size_t nrFrontals) : FactorType(keys), nrFrontals_(nrFrontals) { assertInvariants(); } diff --git a/gtsam/inference/EliminationTree-inl.h b/gtsam/inference/EliminationTree-inl.h index 002a5639c..462a2fd4a 100644 --- a/gtsam/inference/EliminationTree-inl.h +++ b/gtsam/inference/EliminationTree-inl.h @@ -58,7 +58,7 @@ typename EliminationTree::sharedFactor EliminationTree::eliminat /* ************************************************************************* */ template -FastVector EliminationTree::ComputeParents(const VariableIndex& structure) { +vector EliminationTree::ComputeParents(const VariableIndex& structure) { // Number of factors and variables const size_t m = structure.nFactors(); @@ -67,8 +67,8 @@ FastVector EliminationTree::ComputeParents(const VariableIndex& s static const Index none = numeric_limits::max(); // Allocate result parent vector and vector of last factor columns - FastVector parents(n, none); - FastVector prevCol(m, none); + vector parents(n, none); + vector prevCol(m, none); // for column j \in 1 to n do for (Index j = 0; j < n; j++) { @@ -100,7 +100,7 @@ typename EliminationTree::shared_ptr EliminationTree::Create( tic(1, "ET ComputeParents"); // Compute the tree structure - FastVector parents(ComputeParents(structure)); + vector parents(ComputeParents(structure)); toc(1, "ET ComputeParents"); // Number of variables @@ -110,7 +110,7 @@ typename EliminationTree::shared_ptr EliminationTree::Create( // Create tree structure tic(2, "assemble tree"); - FastVector trees(n); + vector trees(n); for (Index k = 1; k <= n; k++) { Index j = n - k; // Start at the last variable and loop down to 0 trees[j].reset(new EliminationTree(j)); // Create a new node on this variable diff --git a/gtsam/inference/EliminationTree.h b/gtsam/inference/EliminationTree.h index 4dab46dd3..4d0ccce56 100644 --- a/gtsam/inference/EliminationTree.h +++ b/gtsam/inference/EliminationTree.h @@ -54,7 +54,7 @@ private: typedef FastList Factors; typedef FastList SubTrees; - typedef FastVector Conditionals; + typedef std::vector Conditionals; Index key_; ///< index associated with root Factors factors_; ///< factors associated with root @@ -74,7 +74,7 @@ private: * Static internal function to build a vector of parent pointers using the * algorithm of Gilbert et al., 2001, BIT. */ - static FastVector ComputeParents(const VariableIndex& structure); + static std::vector ComputeParents(const VariableIndex& structure); /** add a factor, for Create use only */ void add(const sharedFactor& factor) { factors_.push_back(factor); } diff --git a/gtsam/inference/Factor.h b/gtsam/inference/Factor.h index f51276ddc..5a0b1e333 100644 --- a/gtsam/inference/Factor.h +++ b/gtsam/inference/Factor.h @@ -22,10 +22,10 @@ #pragma once #include +#include #include #include - -#include +#include namespace gtsam { @@ -68,15 +68,15 @@ public: typedef boost::shared_ptr shared_ptr; /// Iterator over keys - typedef typename FastVector::iterator iterator; + typedef typename std::vector::iterator iterator; /// Const iterator over keys - typedef typename FastVector::const_iterator const_iterator; + typedef typename std::vector::const_iterator const_iterator; protected: /// The keys involved in this factor - FastVector keys_; + std::vector keys_; friend class JacobianFactor; friend class HessianFactor; @@ -132,11 +132,6 @@ public: assertInvariants(); } - /** Construct n-way factor */ - Factor(const FastVector& keys) : keys_(keys) { - assertInvariants(); - } - /** Constructor from a collection of keys */ template Factor(KEYITERATOR beginKey, KEYITERATOR endKey) : keys_(beginKey, endKey) { assertInvariants(); } @@ -170,8 +165,8 @@ public: /// find const_iterator find(Key key) const { return std::find(begin(), end(), key); } - /// @return keys involved in this factor - const FastVector& keys() const { return keys_; } + ///TODO: comment + const std::vector& keys() const { return keys_; } /** iterators */ const_iterator begin() const { return keys_.begin(); } ///TODO: comment @@ -199,7 +194,7 @@ public: /** * @return keys involved in this factor */ - FastVector& keys() { return keys_; } + std::vector& keys() { return keys_; } /** mutable iterators */ iterator begin() { return keys_.begin(); } ///TODO: comment diff --git a/gtsam/inference/FactorGraph-inl.h b/gtsam/inference/FactorGraph-inl.h index 6244c959a..337b571c6 100644 --- a/gtsam/inference/FactorGraph-inl.h +++ b/gtsam/inference/FactorGraph-inl.h @@ -104,8 +104,8 @@ namespace gtsam { /* ************************************************************************* */ template typename DERIVED::shared_ptr Combine(const FactorGraph& factors, - const FastMap >& variableSlots) { - typedef const pair > KeySlotPair; + const FastMap >& variableSlots) { + typedef const pair > KeySlotPair; return typename DERIVED::shared_ptr(new DERIVED( boost::make_transform_iterator(variableSlots.begin(), boost::bind(&KeySlotPair::first, _1)), boost::make_transform_iterator(variableSlots.end(), boost::bind(&KeySlotPair::first, _1)))); diff --git a/gtsam/inference/FactorGraph.h b/gtsam/inference/FactorGraph.h index fcbd02a29..458588b7b 100644 --- a/gtsam/inference/FactorGraph.h +++ b/gtsam/inference/FactorGraph.h @@ -232,7 +232,7 @@ template class BayesTree; /** Create a combined joint factor (new style for EliminationTree). */ template typename DERIVED::shared_ptr Combine(const FactorGraph& factors, - const FastMap >& variableSlots); + const FastMap >& variableSlots); /** * static function that combines two factor graphs diff --git a/gtsam/inference/IndexConditional.h b/gtsam/inference/IndexConditional.h index e8cb3f9c1..c1cbbdaac 100644 --- a/gtsam/inference/IndexConditional.h +++ b/gtsam/inference/IndexConditional.h @@ -74,23 +74,12 @@ namespace gtsam { assertInvariants(); } - /** Constructor from a frontal variable and a vector of parents (FastVector version) */ - IndexConditional(Index j, const FastVector& parents) : Base(j, parents) { - assertInvariants(); - } - /** Constructor from keys and nr of frontal variables */ IndexConditional(const std::vector& keys, size_t nrFrontals) : Base(keys, nrFrontals) { assertInvariants(); } - /** Constructor from keys and nr of frontal variables (FastVector version) */ - IndexConditional(const FastVector& keys, size_t nrFrontals) : - Base(keys, nrFrontals) { - assertInvariants(); - } - /// @} /// @name Standard Interface /// @{ diff --git a/gtsam/inference/IndexFactor.h b/gtsam/inference/IndexFactor.h index 32488a9d5..9b2d39727 100644 --- a/gtsam/inference/IndexFactor.h +++ b/gtsam/inference/IndexFactor.h @@ -114,12 +114,6 @@ namespace gtsam { assertInvariants(); } - /** Construct n-way factor (FastVector version) */ - IndexFactor(const FastVector& js) : - Base(js) { - assertInvariants(); - } - /** Constructor from a collection of keys */ template IndexFactor(KeyIterator beginKey, KeyIterator endKey) : diff --git a/gtsam/inference/JunctionTree-inl.h b/gtsam/inference/JunctionTree-inl.h index 739b51048..ad8b389ab 100644 --- a/gtsam/inference/JunctionTree-inl.h +++ b/gtsam/inference/JunctionTree-inl.h @@ -83,7 +83,7 @@ namespace gtsam { // Two stages - first build an array of the lowest-ordered variable in each // factor and find the last variable to be eliminated. - FastVector lowestOrdered(fg.size(), numeric_limits::max()); + vector lowestOrdered(fg.size(), numeric_limits::max()); Index maxVar = 0; for(size_t i=0; i > targets(maxVar+1); + vector > targets(maxVar+1); for(size_t i=0; i::max()) targets[lowestOrdered[i]].push_back(i); @@ -108,7 +108,7 @@ namespace gtsam { /* ************************************************************************* */ template typename JunctionTree::sharedClique JunctionTree::distributeFactors(const FG& fg, - const FastVector >& targets, + const std::vector >& targets, const SymbolicBayesTree::sharedClique& bayesClique) { if(bayesClique) { diff --git a/gtsam/inference/JunctionTree.h b/gtsam/inference/JunctionTree.h index a068be991..33a9aa5e4 100644 --- a/gtsam/inference/JunctionTree.h +++ b/gtsam/inference/JunctionTree.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ namespace gtsam { const SymbolicBayesTree::sharedClique& clique); /// distribute the factors along the cluster tree - sharedClique distributeFactors(const FG& fg, const FastVector >& targets, + sharedClique distributeFactors(const FG& fg, const std::vector >& targets, const SymbolicBayesTree::sharedClique& clique); /// recursive elimination function diff --git a/gtsam/inference/Permutation.h b/gtsam/inference/Permutation.h index bde6dd459..5cbd8e187 100644 --- a/gtsam/inference/Permutation.h +++ b/gtsam/inference/Permutation.h @@ -17,12 +17,12 @@ #pragma once +#include #include #include #include #include -#include namespace gtsam { @@ -46,12 +46,12 @@ class Inference; */ class Permutation { protected: - FastVector rangeIndices_; + std::vector rangeIndices_; public: typedef boost::shared_ptr shared_ptr; - typedef FastVector::const_iterator const_iterator; - typedef FastVector::iterator iterator; + typedef std::vector::const_iterator const_iterator; + typedef std::vector::iterator iterator; /// @name Standard Constructors /// @{ diff --git a/gtsam/inference/SymbolicFactorGraph.cpp b/gtsam/inference/SymbolicFactorGraph.cpp index 233c1e21c..2d5190f45 100644 --- a/gtsam/inference/SymbolicFactorGraph.cpp +++ b/gtsam/inference/SymbolicFactorGraph.cpp @@ -66,7 +66,7 @@ namespace gtsam { /* ************************************************************************* */ IndexFactor::shared_ptr CombineSymbolic( const FactorGraph& factors, const FastMap >& variableSlots) { + std::vector >& variableSlots) { IndexFactor::shared_ptr combined(Combine (factors, variableSlots)); // combined->assertInvariants(); @@ -84,11 +84,9 @@ namespace gtsam { if (keys.size() < 1) throw invalid_argument( "IndexFactor::CombineAndEliminate called on factors with no variables."); - if(nrFrontals > keys.size()) throw invalid_argument( - "Requesting to eliminate more variables than are present in the factors"); pair result; - FastVector newKeys(keys.begin(),keys.end()); + std::vector newKeys(keys.begin(),keys.end()); result.first.reset(new IndexConditional(newKeys, nrFrontals)); result.second.reset(new IndexFactor(newKeys.begin()+nrFrontals, newKeys.end())); diff --git a/gtsam/inference/SymbolicFactorGraph.h b/gtsam/inference/SymbolicFactorGraph.h index e39e4a70b..4da2baf13 100644 --- a/gtsam/inference/SymbolicFactorGraph.h +++ b/gtsam/inference/SymbolicFactorGraph.h @@ -84,7 +84,7 @@ namespace gtsam { /** Create a combined joint factor (new style for EliminationTree). */ IndexFactor::shared_ptr CombineSymbolic( const FactorGraph& factors, const FastMap >& variableSlots); + std::vector >& variableSlots); /** * CombineAndEliminate provides symbolic elimination. diff --git a/gtsam/inference/inference.cpp b/gtsam/inference/inference.cpp index 8ec67b26c..d30ea79c4 100644 --- a/gtsam/inference/inference.cpp +++ b/gtsam/inference/inference.cpp @@ -29,12 +29,12 @@ using namespace std; namespace gtsam { -Permutation::shared_ptr Inference::PermutationCOLAMD_(const VariableIndex& variableIndex, FastVector& cmember) { +Permutation::shared_ptr Inference::PermutationCOLAMD_(const VariableIndex& variableIndex, std::vector& cmember) { size_t nEntries = variableIndex.nEntries(), nFactors = variableIndex.nFactors(), nVars = variableIndex.size(); // Convert to compressed column major format colamd wants it in (== MATLAB format!) int Alen = ccolamd_recommended(nEntries, nFactors, nVars); /* colamd arg 3: size of the array A */ - vector A(Alen); /* colamd arg 4: row indices of A, of size Alen */ - vector p(nVars + 1); /* colamd arg 5: column pointers of A, of size n_col+1 */ + 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 */ static const bool debug = false; diff --git a/gtsam/inference/inference.h b/gtsam/inference/inference.h index 728d2c4bd..d853ff91b 100644 --- a/gtsam/inference/inference.h +++ b/gtsam/inference/inference.h @@ -18,7 +18,6 @@ #pragma once -#include #include #include @@ -49,7 +48,7 @@ namespace gtsam { /** * Compute a CCOLAMD permutation using the constraint groups in cmember. */ - static Permutation::shared_ptr PermutationCOLAMD_(const VariableIndex& variableIndex, FastVector& cmember); + static Permutation::shared_ptr PermutationCOLAMD_(const VariableIndex& variableIndex, std::vector& cmember); }; @@ -57,7 +56,7 @@ namespace gtsam { template Permutation::shared_ptr Inference::PermutationCOLAMD(const VariableIndex& variableIndex, const CONSTRAINED& constrainLast) { - FastVector cmember(variableIndex.size(), 0); + std::vector cmember(variableIndex.size(), 0); // If at least some variables are not constrained to be last, constrain the // ones that should be constrained. @@ -73,7 +72,7 @@ namespace gtsam { /* ************************************************************************* */ inline Permutation::shared_ptr Inference::PermutationCOLAMD(const VariableIndex& variableIndex) { - FastVector cmember(variableIndex.size(), 0); + std::vector cmember(variableIndex.size(), 0); return PermutationCOLAMD_(variableIndex, cmember); } diff --git a/gtsam/inference/tests/testJunctionTree.cpp b/gtsam/inference/tests/testJunctionTree.cpp index 9695afc56..7374bbad8 100644 --- a/gtsam/inference/tests/testJunctionTree.cpp +++ b/gtsam/inference/tests/testJunctionTree.cpp @@ -56,15 +56,15 @@ TEST( JunctionTree, constructor ) SymbolicJunctionTree actual(fg); - FastVector frontal1; frontal1 += x3, x4; - FastVector frontal2; frontal2 += x2, x1; - FastVector sep1; - FastVector sep2; sep2 += x3; - CHECK(assert_container_equality(frontal1, actual.root()->frontal)); - CHECK(assert_container_equality(sep1, actual.root()->separator)); + vector frontal1; frontal1 += x3, x4; + vector frontal2; frontal2 += x2, x1; + vector sep1; + vector sep2; sep2 += x3; + CHECK(assert_equal(frontal1, actual.root()->frontal)); + CHECK(assert_equal(sep1, actual.root()->separator)); LONGS_EQUAL(1, actual.root()->size()); - CHECK(assert_container_equality(frontal2, actual.root()->children().front()->frontal)); - CHECK(assert_container_equality(sep2, actual.root()->children().front()->separator)); + CHECK(assert_equal(frontal2, actual.root()->children().front()->frontal)); + CHECK(assert_equal(sep2, actual.root()->children().front()->separator)); LONGS_EQUAL(2, actual.root()->children().front()->size()); CHECK(assert_equal(*fg[2], *(*actual.root())[0])); CHECK(assert_equal(*fg[0], *(*actual.root()->children().front())[0])); diff --git a/gtsam/linear/GaussianConditional.h b/gtsam/linear/GaussianConditional.h index af83a6f44..f2a77c894 100644 --- a/gtsam/linear/GaussianConditional.h +++ b/gtsam/linear/GaussianConditional.h @@ -268,7 +268,7 @@ template GaussianConditional::GaussianConditional(ITERATOR firstKey, ITERATOR lastKey, size_t nrFrontals, const VerticalBlockView& matrices, const Vector& sigmas, const GaussianConditional::TranspositionType& permutation) : - IndexConditional(FastVector(firstKey, lastKey), nrFrontals), rsd_( + IndexConditional(std::vector(firstKey, lastKey), nrFrontals), rsd_( matrix_), sigmas_(sigmas), permutation_(permutation) { rsd_.assignNoalias(matrices); } diff --git a/gtsam/linear/GaussianFactor.h b/gtsam/linear/GaussianFactor.h index 771a3de8f..2d889ee64 100644 --- a/gtsam/linear/GaussianFactor.h +++ b/gtsam/linear/GaussianFactor.h @@ -74,9 +74,6 @@ namespace gtsam { /** Construct n-way factor */ GaussianFactor(const std::vector& js) : IndexFactor(js) {} - /** Construct n-way factor */ - GaussianFactor(const FastVector& js) : IndexFactor(js) {} - public: typedef GaussianConditional ConditionalType; @@ -113,8 +110,8 @@ namespace gtsam { /** make keys from list, vector, or map of matrices */ template - static FastVector GetKeys(size_t n, ITERATOR begin, ITERATOR end) { - FastVector keys; + static std::vector GetKeys(size_t n, ITERATOR begin, ITERATOR end) { + std::vector keys; keys.reserve(n); for (ITERATOR it=begin;it!=end;++it) keys.push_back(it->first); return keys; diff --git a/gtsam/linear/GaussianFactorGraph.cpp b/gtsam/linear/GaussianFactorGraph.cpp index 16c2ce12d..56a377c61 100644 --- a/gtsam/linear/GaussianFactorGraph.cpp +++ b/gtsam/linear/GaussianFactorGraph.cpp @@ -167,11 +167,11 @@ namespace gtsam { /* ************************************************************************* */ // Helper functions for Combine - static boost::tuple, size_t, size_t> countDims(const std::vector& factors, const VariableSlots& variableSlots) { + static boost::tuple, size_t, size_t> countDims(const std::vector& factors, const VariableSlots& variableSlots) { #ifndef NDEBUG - FastVector varDims(variableSlots.size(), numeric_limits::max()); + vector varDims(variableSlots.size(), numeric_limits::max()); #else - FastVector varDims(variableSlots.size()); + vector varDims(variableSlots.size()); #endif size_t m = 0; size_t n = 0; @@ -220,7 +220,7 @@ break; if (debug) cout << "Determine dimensions" << endl; tic(1, "countDims"); - FastVector varDims; + vector varDims; size_t m, n; boost::tie(varDims, m, n) = countDims(factors, variableSlots); if (debug) { @@ -232,7 +232,7 @@ break; if (debug) cout << "Sort rows" << endl; tic(2, "sort rows"); - FastVector rowSources; + vector rowSources; rowSources.reserve(m); bool anyConstrained = false; for (size_t sourceFactorI = 0; sourceFactorI < factors.size(); ++sourceFactorI) { @@ -366,7 +366,7 @@ break; // Pull out keys and dimensions tic(2, "keys"); - FastVector dimensions(scatter.size() + 1); + vector dimensions(scatter.size() + 1); BOOST_FOREACH(const Scatter::value_type& var_slot, scatter) { dimensions[var_slot.second.slot] = var_slot.second.dimension; } @@ -568,7 +568,7 @@ break; // Pull out keys and dimensions tic(2, "keys"); - FastVector dimensions(scatter.size() + 1); + vector dimensions(scatter.size() + 1); BOOST_FOREACH(const Scatter::value_type& var_slot, scatter) { dimensions[var_slot.second.slot] = var_slot.second.dimension; } diff --git a/gtsam/linear/GaussianJunctionTree.cpp b/gtsam/linear/GaussianJunctionTree.cpp index 0db558a10..e2e1c2951 100644 --- a/gtsam/linear/GaussianJunctionTree.cpp +++ b/gtsam/linear/GaussianJunctionTree.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include namespace gtsam { @@ -66,7 +68,7 @@ namespace gtsam { // Allocate solution vector and copy RHS tic(2, "allocate VectorValues"); - FastVector dims(rootClique->conditional()->back()+1, 0); + vector dims(rootClique->conditional()->back()+1, 0); countDims(rootClique, dims); VectorValues result(dims); btreeRHS(rootClique, result); diff --git a/gtsam/linear/HessianFactor.cpp b/gtsam/linear/HessianFactor.cpp index eedecc4ed..8402e4f91 100644 --- a/gtsam/linear/HessianFactor.cpp +++ b/gtsam/linear/HessianFactor.cpp @@ -248,7 +248,7 @@ HessianFactor::HessianFactor(const GaussianFactor& gf) : info_(matrix_) { /* ************************************************************************* */ HessianFactor::HessianFactor(const FactorGraph& factors, - const FastVector& dimensions, const Scatter& scatter) : + const vector& dimensions, const Scatter& scatter) : info_(matrix_) { const bool debug = ISDEBUG("EliminateCholesky") || ISDEBUG("EliminateLDL"); @@ -505,7 +505,7 @@ HessianFactor::splitEliminatedFactor(size_t nrFrontals, const Eigen::LDLT remainingKeys(keys_.size() - nrFrontals); + vector remainingKeys(keys_.size() - nrFrontals); remainingKeys.assign(keys_.begin() + nrFrontals, keys_.end()); keys_.swap(remainingKeys); toc(2, "remaining factor"); diff --git a/gtsam/linear/HessianFactor.h b/gtsam/linear/HessianFactor.h index 6225fcde9..2a16c0e38 100644 --- a/gtsam/linear/HessianFactor.h +++ b/gtsam/linear/HessianFactor.h @@ -204,7 +204,7 @@ namespace gtsam { /** Special constructor used in EliminateCholesky which combines the given factors */ HessianFactor(const FactorGraph& factors, - const FastVector& dimensions, const Scatter& scatter); + const std::vector& dimensions, const Scatter& scatter); /** Destructor */ virtual ~HessianFactor() {} diff --git a/gtsam/linear/JacobianFactor.cpp b/gtsam/linear/JacobianFactor.cpp index 064143512..0218ecc8d 100644 --- a/gtsam/linear/JacobianFactor.cpp +++ b/gtsam/linear/JacobianFactor.cpp @@ -113,7 +113,7 @@ namespace gtsam { } /* ************************************************************************* */ - JacobianFactor::JacobianFactor(const FastVector > &terms, + JacobianFactor::JacobianFactor(const std::vector > &terms, const Vector &b, const SharedDiagonal& model) : GaussianFactor(GetKeys(terms.size(), terms.begin(), terms.end())), model_(model), firstNonzeroBlocks_(b.size(), 0), Ab_(matrix_) @@ -260,7 +260,7 @@ namespace gtsam { sourceSlots.insert(make_pair(inversePermutation[keys_[j]], j)); // Build a vector of variable dimensions in the new order - FastVector dimensions(size() + 1); + vector dimensions(size() + 1); size_t j = 0; BOOST_FOREACH(const SourceSlots::value_type& sourceSlot, sourceSlots) { dimensions[j++] = Ab_(sourceSlot.second).cols(); @@ -269,7 +269,7 @@ namespace gtsam { dimensions.back() = 1; // Copy the variables and matrix into the new order - FastVector oldKeys(size()); + vector oldKeys(size()); keys_.swap(oldKeys); AbMatrix oldMatrix; BlockAb oldAb(oldMatrix, dimensions.begin(), dimensions.end(), Ab_.rows()); @@ -506,7 +506,7 @@ namespace gtsam { } /* ************************************************************************* */ - void JacobianFactor::collectInfo(size_t index, FastVector<_RowSource>& rowSources) const { + void JacobianFactor::collectInfo(size_t index, vector<_RowSource>& rowSources) const { assertInvariants(); for (size_t row = 0; row < rows(); ++row) { Index firstNonzeroVar; @@ -522,7 +522,7 @@ namespace gtsam { } /* ************************************************************************* */ - void JacobianFactor::allocate(const VariableSlots& variableSlots, FastVector< + void JacobianFactor::allocate(const VariableSlots& variableSlots, vector< size_t>& varDims, size_t m) { keys_.resize(variableSlots.size()); std::transform(variableSlots.begin(), variableSlots.end(), begin(), @@ -551,7 +551,7 @@ namespace gtsam { /* ************************************************************************* */ void JacobianFactor::copyFNZ(size_t m, size_t n, - FastVector<_RowSource>& rowSources) { + vector<_RowSource>& rowSources) { Index i = 0; for (size_t row = 0; row < m; ++row) { while (i < n && rowSources[row].firstNonzeroVar > keys_[i]) diff --git a/gtsam/linear/JacobianFactor.h b/gtsam/linear/JacobianFactor.h index 90270ce95..079cb9292 100644 --- a/gtsam/linear/JacobianFactor.h +++ b/gtsam/linear/JacobianFactor.h @@ -85,7 +85,7 @@ namespace gtsam { protected: SharedDiagonal model_; // Gaussian noise model with diagonal covariance matrix - FastVector firstNonzeroBlocks_; + std::vector firstNonzeroBlocks_; AbMatrix matrix_; // the full matrix corresponding to the factor BlockAb Ab_; // the block view of the full matrix typedef GaussianFactor Base; // typedef to base @@ -123,7 +123,7 @@ namespace gtsam { const Vector& b, const SharedDiagonal& model); /** Construct an n-ary factor */ - JacobianFactor(const FastVector > &terms, + JacobianFactor(const std::vector > &terms, const Vector &b, const SharedDiagonal& model); JacobianFactor(const std::list > &terms, @@ -268,18 +268,18 @@ namespace gtsam { // Many imperative, perhaps all need to be combined in constructor /** Collect information on Jacobian rows */ - void collectInfo(size_t index, FastVector<_RowSource>& rowSources) const; + void collectInfo(size_t index, std::vector<_RowSource>& rowSources) const; /** allocate space */ void allocate(const VariableSlots& variableSlots, - FastVector& varDims, size_t m); + std::vector& varDims, size_t m); /** copy a slot from source */ void copyRow(const JacobianFactor& source, Index sourceRow, size_t sourceSlot, size_t row, Index slot); /** copy firstNonzeroBlocks structure */ - void copyFNZ(size_t m, size_t n, FastVector<_RowSource>& rowSources); + void copyFNZ(size_t m, size_t n, std::vector<_RowSource>& rowSources); /** set noiseModel correctly */ void setModel(bool anyConstrained, const Vector& sigmas); diff --git a/gtsam/linear/NoiseModel.cpp b/gtsam/linear/NoiseModel.cpp index 37584af2e..fd93d39fc 100644 --- a/gtsam/linear/NoiseModel.cpp +++ b/gtsam/linear/NoiseModel.cpp @@ -163,7 +163,7 @@ SharedDiagonal Gaussian::Cholesky(Matrix& Ab, size_t nFrontals) const { return Unit::Create(maxrank); } -void Gaussian::WhitenSystem(FastVector& A, Vector& b) const { +void Gaussian::WhitenSystem(vector& A, Vector& b) const { BOOST_FOREACH(Matrix& Aj, A) { WhitenInPlace(Aj); } whitenInPlace(b); } @@ -513,7 +513,7 @@ Vector Base::sqrtWeight(const Vector &error) const { * according to their weight implementation */ /** Reweight n block matrices with one error vector */ -void Base::reweight(FastVector &A, Vector &error) const { +void Base::reweight(vector &A, Vector &error) const { if ( reweight_ == Block ) { const double w = sqrtWeight(error.norm()); BOOST_FOREACH(Matrix& Aj, A) { @@ -662,7 +662,7 @@ bool Robust::equals(const Base& expected, double tol) const { return noise_->equals(*p->noise_,tol) && robust_->equals(*p->robust_,tol); } -void Robust::WhitenSystem(FastVector& A, Vector& b) const { +void Robust::WhitenSystem(vector& A, Vector& b) const { noise_->WhitenSystem(A,b); robust_->reweight(A,b); } diff --git a/gtsam/linear/NoiseModel.h b/gtsam/linear/NoiseModel.h index 640eadfba..ee5d9e00c 100644 --- a/gtsam/linear/NoiseModel.h +++ b/gtsam/linear/NoiseModel.h @@ -20,7 +20,6 @@ #include #include -#include namespace gtsam { @@ -77,7 +76,7 @@ namespace gtsam { virtual double distance(const Vector& v) const = 0; - virtual void WhitenSystem(FastVector& A, Vector& b) const = 0; + virtual void WhitenSystem(std::vector& A, Vector& b) const = 0; virtual void WhitenSystem(Matrix& A, Vector& b) const = 0; virtual void WhitenSystem(Matrix& A1, Matrix& A2, Vector& b) const = 0; virtual void WhitenSystem(Matrix& A1, Matrix& A2, Matrix& A3, Vector& b) const = 0; @@ -186,7 +185,7 @@ namespace gtsam { /** * Whiten a system, in place as well */ - virtual void WhitenSystem(FastVector& A, Vector& b) const ; + virtual void WhitenSystem(std::vector& A, Vector& b) const ; virtual void WhitenSystem(Matrix& A, Vector& b) const ; virtual void WhitenSystem(Matrix& A1, Matrix& A2, Vector& b) const ; virtual void WhitenSystem(Matrix& A1, Matrix& A2, Matrix& A3, Vector& b) const; @@ -620,7 +619,7 @@ namespace gtsam { Vector sqrtWeight(const Vector &error) const; /** reweight block matrices and a vector according to their weight implementation */ - void reweight(FastVector &A, Vector &error) const; + void reweight(std::vector &A, Vector &error) const; void reweight(Matrix &A, Vector &error) const; void reweight(Matrix &A1, Matrix &A2, Vector &error) const; void reweight(Matrix &A1, Matrix &A2, Matrix &A3, Vector &error) const; @@ -715,7 +714,7 @@ namespace gtsam { // TODO: these are really robust iterated re-weighting support functions - virtual void WhitenSystem(FastVector& A, Vector& b) const; + virtual void WhitenSystem(std::vector& A, Vector& b) const; virtual void WhitenSystem(Matrix& A, Vector& b) const; virtual void WhitenSystem(Matrix& A1, Matrix& A2, Vector& b) const; virtual void WhitenSystem(Matrix& A1, Matrix& A2, Matrix& A3, Vector& b) const; diff --git a/gtsam/nonlinear/GaussianISAM2-inl.h b/gtsam/nonlinear/GaussianISAM2-inl.h index b90b2c4ea..d0d37d886 100644 --- a/gtsam/nonlinear/GaussianISAM2-inl.h +++ b/gtsam/nonlinear/GaussianISAM2-inl.h @@ -57,7 +57,7 @@ namespace gtsam { if(recalculate) { // Temporary copy of the original values, to check how much they change - FastVector originalValues((*clique)->nrFrontals()); + vector originalValues((*clique)->nrFrontals()); GaussianConditional::const_iterator it; for(it = (*clique)->beginFrontals(); it!=(*clique)->endFrontals(); it++) { originalValues[it - (*clique)->beginFrontals()] = delta[*it]; diff --git a/gtsam/nonlinear/ISAM2-impl-inl.h b/gtsam/nonlinear/ISAM2-impl-inl.h index 4858b1900..eae39bf52 100644 --- a/gtsam/nonlinear/ISAM2-impl-inl.h +++ b/gtsam/nonlinear/ISAM2-impl-inl.h @@ -126,7 +126,7 @@ void ISAM2::Impl::AddVariables( theta.insert(newTheta); if(debug) newTheta.print("The new variables are: "); // Add the new keys onto the ordering, add zeros to the delta for the new variables - FastVector dims(newTheta.dims(*newTheta.orderingArbitrary())); + std::vector dims(newTheta.dims(*newTheta.orderingArbitrary())); if(debug) cout << "New variables have total dimensionality " << accumulate(dims.begin(), dims.end(), 0) << endl; const size_t newDim = accumulate(dims.begin(), dims.end(), 0); const size_t originalDim = delta->dim(); @@ -287,7 +287,7 @@ ISAM2::Impl::PartialSolve(GaussianFactorGraph& factors, if(debug) affectedFactorsIndex.print("affectedFactorsIndex: "); toc(2,"variable index"); tic(3,"ccolamd"); - FastVector cmember(affectedKeysSelector.size(), 0); + vector cmember(affectedKeysSelector.size(), 0); if(reorderingMode.constrain == ReorderingMode::CONSTRAIN_LAST) { assert(reorderingMode.constrainedKeys); if(keys.size() > reorderingMode.constrainedKeys->size()) { diff --git a/gtsam/nonlinear/ISAM2-inl.h b/gtsam/nonlinear/ISAM2-inl.h index 6dc47131f..5c87d1dda 100644 --- a/gtsam/nonlinear/ISAM2-inl.h +++ b/gtsam/nonlinear/ISAM2-inl.h @@ -229,7 +229,7 @@ boost::shared_ptr > ISAM2::recalculate( tic(1,"reorder"); tic(1,"CCOLAMD"); // Do a batch step - reorder and relinearize all variables - FastVector cmember(theta_.size(), 0); + vector cmember(theta_.size(), 0); FastSet constrainedKeysSet; if(constrainKeys) constrainedKeysSet = *constrainKeys; diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 512d7af91..166ad6980 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -35,6 +36,19 @@ namespace gtsam { +using boost::make_tuple; + +// Helper function to fill a vector from a tuple function of any length +template +inline void __fill_from_tuple(std::vector& vector, size_t position, const CONS& tuple) { + vector[position] = tuple.get_head(); + __fill_from_tuple(vector, position+1, tuple.get_tail()); +} +template<> +inline void __fill_from_tuple(std::vector& vector, size_t position, const boost::tuples::null_type& tuple) { + // Do nothing +} + /* ************************************************************************* */ /** * Nonlinear factor base class @@ -125,7 +139,7 @@ public: * variable indices. */ virtual IndexFactor::shared_ptr symbolic(const Ordering& ordering) const { - FastVector indices(this->size()); + std::vector indices(this->size()); for(size_t j=0; jsize(); ++j) indices[j] = ordering[this->keys()[j]]; return IndexFactor::shared_ptr(new IndexFactor(indices)); @@ -214,7 +228,7 @@ public: * If any of the optional Matrix reference arguments are specified, it should compute * both the function evaluation and its derivative(s) in X1 (and/or X2, X3...). */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const = 0; + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const = 0; /** * Vector of errors, whitened @@ -250,12 +264,12 @@ public: // Create the set of terms - Jacobians for each index Vector b; // Call evaluate error to get Jacobians and b vector - FastVector A(this->size()); + std::vector A(this->size()); b = -unwhitenedError(x, A); this->noiseModel_->WhitenSystem(A,b); - FastVector > terms(this->size()); + std::vector > terms(this->size()); // Fill in terms for(size_t j=0; jsize(); ++j) { terms[j].first = ordering[this->keys()[j]]; @@ -325,7 +339,7 @@ public: /** Calls the 1-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if(this->active(x)) { const X& x1 = x.at(keys_[0]); if(H) { @@ -408,7 +422,7 @@ public: /** Calls the 2-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if(this->active(x)) { const X1& x1 = x.at(keys_[0]); const X2& x2 = x.at(keys_[1]); @@ -498,7 +512,7 @@ public: /** Calls the 3-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if(this->active(x)) { if(H) return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), (*H)[0], (*H)[1], (*H)[2]); @@ -593,7 +607,7 @@ public: /** Calls the 4-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if(this->active(x)) { if(H) return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), (*H)[0], (*H)[1], (*H)[2], (*H)[3]); @@ -693,7 +707,7 @@ public: /** Calls the 5-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if(this->active(x)) { if(H) return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), x.at(keys_[4]), (*H)[0], (*H)[1], (*H)[2], (*H)[3], (*H)[4]); @@ -799,7 +813,7 @@ public: /** Calls the 6-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ - virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { + virtual Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const { if(this->active(x)) { if(H) return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), x.at(keys_[4]), x.at(keys_[5]), (*H)[0], (*H)[1], (*H)[2], (*H)[3], (*H)[4], (*H)[5]); diff --git a/tests/testGaussianJunctionTree.cpp b/tests/testGaussianJunctionTree.cpp index 24d8e0046..19b0c676d 100644 --- a/tests/testGaussianJunctionTree.cpp +++ b/tests/testGaussianJunctionTree.cpp @@ -59,29 +59,29 @@ TEST( GaussianJunctionTree, constructor2 ) // create an ordering GaussianJunctionTree actual(fg); - FastVector frontal1; frontal1 += ordering["x5"], ordering["x6"], ordering["x4"]; - FastVector frontal2; frontal2 += ordering["x3"], ordering["x2"]; - FastVector frontal3; frontal3 += ordering["x1"]; - FastVector frontal4; frontal4 += ordering["x7"]; - FastVector sep1; - FastVector sep2; sep2 += ordering["x4"]; - FastVector sep3; sep3 += ordering["x2"]; - FastVector sep4; sep4 += ordering["x6"]; - EXPECT(assert_container_equality(frontal1, actual.root()->frontal)); - EXPECT(assert_container_equality(sep1, actual.root()->separator)); + vector frontal1; frontal1 += ordering["x5"], ordering["x6"], ordering["x4"]; + vector frontal2; frontal2 += ordering["x3"], ordering["x2"]; + vector frontal3; frontal3 += ordering["x1"]; + vector frontal4; frontal4 += ordering["x7"]; + vector sep1; + vector sep2; sep2 += ordering["x4"]; + vector sep3; sep3 += ordering["x2"]; + vector sep4; sep4 += ordering["x6"]; + EXPECT(assert_equal(frontal1, actual.root()->frontal)); + EXPECT(assert_equal(sep1, actual.root()->separator)); LONGS_EQUAL(5, actual.root()->size()); list::const_iterator child0it = actual.root()->children().begin(); list::const_iterator child1it = child0it; ++child1it; GaussianJunctionTree::sharedClique child0 = *child0it; GaussianJunctionTree::sharedClique child1 = *child1it; - EXPECT(assert_container_equality(frontal2, child0->frontal)); - EXPECT(assert_container_equality(sep2, child0->separator)); + EXPECT(assert_equal(frontal2, child0->frontal)); + EXPECT(assert_equal(sep2, child0->separator)); LONGS_EQUAL(4, child0->size()); - EXPECT(assert_container_equality(frontal3, child0->children().front()->frontal)); - EXPECT(assert_container_equality(sep3, child0->children().front()->separator)); + EXPECT(assert_equal(frontal3, child0->children().front()->frontal)); + EXPECT(assert_equal(sep3, child0->children().front()->separator)); LONGS_EQUAL(2, child0->children().front()->size()); - EXPECT(assert_container_equality(frontal4, child1->frontal)); - EXPECT(assert_container_equality(sep4, child1->separator)); + EXPECT(assert_equal(frontal4, child1->frontal)); + EXPECT(assert_equal(sep4, child1->separator)); LONGS_EQUAL(2, child1->size()); }