From 36d6b706671279263288b978152445ea636fd3ad Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Mon, 9 Jan 2023 19:21:54 -0800 Subject: [PATCH] Fix gcc compilation errors by using correct allocator. --- gtsam/symbolic/tests/symbolicExampleGraphs.h | 48 +++++++++++-------- .../symbolic/tests/testSymbolicBayesTree.cpp | 2 - 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gtsam/symbolic/tests/symbolicExampleGraphs.h b/gtsam/symbolic/tests/symbolicExampleGraphs.h index 4f98188dd..716f502a4 100644 --- a/gtsam/symbolic/tests/symbolicExampleGraphs.h +++ b/gtsam/symbolic/tests/symbolicExampleGraphs.h @@ -20,6 +20,7 @@ #pragma once +#include #include #include #include @@ -32,8 +33,10 @@ namespace gtsam { // A small helper class to replace Boost's `list_of` function. template - class ChainedVector { - public: + struct ChainedVector { + using Result = std::vector::type>; + Result result; + ChainedVector(const T& c) { result.push_back(c); } ChainedVector& operator()(const T& c) { @@ -41,10 +44,7 @@ namespace gtsam { return *this; } - operator std::vector() { return result; } - - private: - std::vector result; + operator Result() { return result; } }; const SymbolicFactorGraph simpleTestGraph1 { @@ -76,18 +76,18 @@ namespace gtsam { boost::make_shared(2,3)}; /* ************************************************************************* * - * 2 3 - * 0 1 : 2 - ****************************************************************************/ + * 2 3 + * 0 1 : 2 + ****************************************************************************/ SymbolicBayesTree __simpleChainBayesTree() { SymbolicBayesTree result; result.insertRoot(boost::make_shared( - boost::make_shared( + boost::make_shared( SymbolicConditional::FromKeys(KeyVector{2,3}, 2)))); result.addClique(boost::make_shared( - boost::make_shared( + boost::make_shared( SymbolicConditional::FromKeys(KeyVector{0,1,2}, 2))), - result.roots().front()); + result.roots().front()); return result; } @@ -95,9 +95,12 @@ namespace gtsam { /* ************************************************************************* */ // Keys for ASIA example from the tutorial with A and D evidence - const Key _X_=gtsam::symbol_shorthand::X(0), _T_=gtsam::symbol_shorthand::T(0), - _S_=gtsam::symbol_shorthand::S(0), _E_=gtsam::symbol_shorthand::E(0), - _L_=gtsam::symbol_shorthand::L(0), _B_=gtsam::symbol_shorthand::B(0); + const Key _X_ = symbol_shorthand::X(0), + _T_ = symbol_shorthand::T(0), + _S_ = symbol_shorthand::S(0), + _E_ = symbol_shorthand::E(0), + _L_ = symbol_shorthand::L(0), + _B_ = symbol_shorthand::B(0); // Factor graph for Asia example const SymbolicFactorGraph asiaGraph = { @@ -117,25 +120,30 @@ namespace gtsam { boost::make_shared(_L_, _B_), boost::make_shared(_B_)}; + /* ************************************************************************* */ + // Allow creating Cliques and Keys in `list_of` chaining style: using sharedClique = SymbolicBayesTreeClique::shared_ptr; using Children = ChainedVector; + using Keys = ChainedVector; - inline sharedClique LeafClique(const std::vector& keys, + inline sharedClique LeafClique(const Keys::Result& keys, DenseIndex nrFrontals) { return boost::make_shared( boost::make_shared( SymbolicConditional::FromKeys(keys, nrFrontals))); } - inline sharedClique NodeClique(const std::vector& keys, + inline sharedClique NodeClique(const Keys::Result& keys, DenseIndex nrFrontals, - const std::vector& children) { + const Children::Result& children) { sharedClique clique = LeafClique(keys, nrFrontals); clique->children.assign(children.begin(), children.end()); for (auto&& child : children) child->parent_ = clique; return clique; } + /* ************************************************************************* */ + // BayesTree for Asia example SymbolicBayesTree __asiaBayesTree() { SymbolicBayesTree result; result.insertRoot(LeafClique({_E_, _L_, _B_}, 3)); @@ -149,5 +157,5 @@ namespace gtsam { /* ************************************************************************* */ const Ordering asiaOrdering{_X_, _T_, _S_, _E_, _L_, _B_}; - } -} + } // namespace +} // namespace gtsam diff --git a/gtsam/symbolic/tests/testSymbolicBayesTree.cpp b/gtsam/symbolic/tests/testSymbolicBayesTree.cpp index 458579c60..0095c9293 100644 --- a/gtsam/symbolic/tests/testSymbolicBayesTree.cpp +++ b/gtsam/symbolic/tests/testSymbolicBayesTree.cpp @@ -34,8 +34,6 @@ using namespace gtsam::symbol_shorthand; static bool debug = false; -using Keys = ChainedVector; // Create Keys a la list_of - /* ************************************************************************* */ TEST(SymbolicBayesTree, clear) { SymbolicBayesTree bayesTree = asiaBayesTree;