Fix gcc compilation errors by using correct allocator.

release/4.3a0
Frank Dellaert 2023-01-09 19:21:54 -08:00
parent c486472ca1
commit 36d6b70667
2 changed files with 28 additions and 22 deletions

View File

@ -20,6 +20,7 @@
#pragma once
#include <gtsam/base/FastDefaultAllocator.h>
#include <gtsam/symbolic/SymbolicFactorGraph.h>
#include <gtsam/symbolic/SymbolicFactor.h>
#include <gtsam/symbolic/SymbolicConditional.h>
@ -32,8 +33,10 @@ namespace gtsam {
// A small helper class to replace Boost's `list_of` function.
template <typename T>
class ChainedVector {
public:
struct ChainedVector {
using Result = std::vector<T, typename internal::FastDefaultAllocator<T>::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<T>() { return result; }
private:
std::vector<T> result;
operator Result() { return result; }
};
const SymbolicFactorGraph simpleTestGraph1 {
@ -76,18 +76,18 @@ namespace gtsam {
boost::make_shared<SymbolicFactor>(2,3)};
/* ************************************************************************* *
* 2 3
* 0 1 : 2
****************************************************************************/
* 2 3
* 0 1 : 2
****************************************************************************/
SymbolicBayesTree __simpleChainBayesTree() {
SymbolicBayesTree result;
result.insertRoot(boost::make_shared<SymbolicBayesTreeClique>(
boost::make_shared<SymbolicConditional>(
boost::make_shared<SymbolicConditional>(
SymbolicConditional::FromKeys(KeyVector{2,3}, 2))));
result.addClique(boost::make_shared<SymbolicBayesTreeClique>(
boost::make_shared<SymbolicConditional>(
boost::make_shared<SymbolicConditional>(
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<SymbolicConditional>(_L_, _B_),
boost::make_shared<SymbolicConditional>(_B_)};
/* ************************************************************************* */
// Allow creating Cliques and Keys in `list_of` chaining style:
using sharedClique = SymbolicBayesTreeClique::shared_ptr;
using Children = ChainedVector<sharedClique>;
using Keys = ChainedVector<Key>;
inline sharedClique LeafClique(const std::vector<Key>& keys,
inline sharedClique LeafClique(const Keys::Result& keys,
DenseIndex nrFrontals) {
return boost::make_shared<SymbolicBayesTreeClique>(
boost::make_shared<SymbolicConditional>(
SymbolicConditional::FromKeys(keys, nrFrontals)));
}
inline sharedClique NodeClique(const std::vector<Key>& keys,
inline sharedClique NodeClique(const Keys::Result& keys,
DenseIndex nrFrontals,
const std::vector<sharedClique>& 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

View File

@ -34,8 +34,6 @@ using namespace gtsam::symbol_shorthand;
static bool debug = false;
using Keys = ChainedVector<Key>; // Create Keys a la list_of
/* ************************************************************************* */
TEST(SymbolicBayesTree, clear) {
SymbolicBayesTree bayesTree = asiaBayesTree;