Added shared_ptr versions of named constructors in SymbolicFactor and SymbolicConditional, for a slight performance boost.
parent
39b4090b21
commit
eba4ca79a4
|
@ -69,12 +69,30 @@ namespace gtsam {
|
||||||
SymbolicConditional result;
|
SymbolicConditional result;
|
||||||
(BaseFactor&)result = BaseFactor::FromIterators(firstKey, lastKey);
|
(BaseFactor&)result = BaseFactor::FromIterators(firstKey, lastKey);
|
||||||
result.nrFrontals_ = nrFrontals;
|
result.nrFrontals_ = nrFrontals;
|
||||||
return result; }
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Named constructor from an arbitrary number of keys and frontals */
|
||||||
|
template<typename ITERATOR>
|
||||||
|
static SymbolicConditional::shared_ptr FromIteratorsShared(ITERATOR firstKey, ITERATOR lastKey, size_t nrFrontals)
|
||||||
|
{
|
||||||
|
SymbolicConditional::shared_ptr result = boost::make_shared<SymbolicConditional>();
|
||||||
|
result->keys_.assign(firstKey, lastKey);
|
||||||
|
result->nrFrontals_ = nrFrontals;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** Named constructor from an arbitrary number of keys and frontals */
|
/** Named constructor from an arbitrary number of keys and frontals */
|
||||||
template<class CONTAINER>
|
template<class CONTAINER>
|
||||||
static SymbolicConditional FromKeys(const CONTAINER& keys, size_t nrFrontals) {
|
static SymbolicConditional FromKeys(const CONTAINER& keys, size_t nrFrontals) {
|
||||||
return FromIterators(keys.begin(), keys.end(), nrFrontals); }
|
return FromIterators(keys.begin(), keys.end(), nrFrontals);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Named constructor from an arbitrary number of keys and frontals */
|
||||||
|
template<class CONTAINER>
|
||||||
|
static SymbolicConditional::shared_ptr FromKeysShared(const CONTAINER& keys, size_t nrFrontals) {
|
||||||
|
return FromIteratorsShared(keys.begin(), keys.end(), nrFrontals);
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~SymbolicConditional() {}
|
virtual ~SymbolicConditional() {}
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,8 @@ namespace gtsam
|
||||||
|
|
||||||
// Return resulting conditional and factor
|
// Return resulting conditional and factor
|
||||||
return std::make_pair(
|
return std::make_pair(
|
||||||
boost::make_shared<SymbolicConditional>(
|
SymbolicConditional::FromKeysShared(orderedKeys, nFrontals),
|
||||||
SymbolicConditional::FromKeys(orderedKeys, nFrontals)),
|
SymbolicFactor::FromIteratorsShared(orderedKeys.begin() + nFrontals, orderedKeys.end()));
|
||||||
boost::make_shared<SymbolicFactor>(
|
|
||||||
SymbolicFactor::FromIterators(orderedKeys.begin() + nFrontals, orderedKeys.end())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,13 +98,30 @@ namespace gtsam {
|
||||||
/** Constructor from a collection of keys */
|
/** Constructor from a collection of keys */
|
||||||
template<typename KEYITERATOR>
|
template<typename KEYITERATOR>
|
||||||
static SymbolicFactor FromIterators(KEYITERATOR beginKey, KEYITERATOR endKey) {
|
static SymbolicFactor FromIterators(KEYITERATOR beginKey, KEYITERATOR endKey) {
|
||||||
return SymbolicFactor(Base::FromIterators(beginKey, endKey)); }
|
return SymbolicFactor(Base::FromIterators(beginKey, endKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Constructor from a collection of keys */
|
||||||
|
template<typename KEYITERATOR>
|
||||||
|
static SymbolicFactor::shared_ptr FromIteratorsShared(KEYITERATOR beginKey, KEYITERATOR endKey) {
|
||||||
|
SymbolicFactor::shared_ptr result = boost::make_shared<SymbolicFactor>();
|
||||||
|
result->keys_.assign(beginKey, endKey);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** Constructor from a collection of keys - compatible with boost::assign::list_of and
|
/** Constructor from a collection of keys - compatible with boost::assign::list_of and
|
||||||
* boost::assign::cref_list_of */
|
* boost::assign::cref_list_of */
|
||||||
template<class CONTAINER>
|
template<class CONTAINER>
|
||||||
static SymbolicFactor FromKeys(const CONTAINER& keys) {
|
static SymbolicFactor FromKeys(const CONTAINER& keys) {
|
||||||
return SymbolicFactor(Base::FromKeys(keys)); }
|
return SymbolicFactor(Base::FromKeys(keys));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Constructor from a collection of keys - compatible with boost::assign::list_of and
|
||||||
|
* boost::assign::cref_list_of */
|
||||||
|
template<class CONTAINER>
|
||||||
|
static SymbolicFactor::shared_ptr FromKeysShared(const CONTAINER& keys) {
|
||||||
|
return FromIteratorsShared(keys.begin(), keys.end());
|
||||||
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ using namespace boost::assign;
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
#include <CppUnitLite/TestHarness.h>
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
#include <gtsam/base/TestableAssertions.h>
|
||||||
#include <gtsam/symbolic/SymbolicConditional.h>
|
#include <gtsam/symbolic/SymbolicConditional.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -84,6 +85,22 @@ TEST( SymbolicConditional, FromRange )
|
||||||
LONGS_EQUAL(3, (long)c0->nrParents());
|
LONGS_EQUAL(3, (long)c0->nrParents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(SymbolicConditional, Constructors)
|
||||||
|
{
|
||||||
|
SymbolicConditional expected(3, 4);
|
||||||
|
|
||||||
|
SymbolicConditional actual1 = SymbolicConditional::FromKeys(expected.keys(), 1);
|
||||||
|
SymbolicConditional actual2 = SymbolicConditional::FromIterators(expected.begin(), expected.end(), 1);
|
||||||
|
SymbolicConditional actual3 = *SymbolicConditional::FromKeysShared(expected.keys(), 1);
|
||||||
|
SymbolicConditional actual4 = *SymbolicConditional::FromIteratorsShared(expected.begin(), expected.end(), 1);
|
||||||
|
|
||||||
|
EXPECT(assert_equal(expected, actual1));
|
||||||
|
EXPECT(assert_equal(expected, actual2));
|
||||||
|
EXPECT(assert_equal(expected, actual3));
|
||||||
|
EXPECT(assert_equal(expected, actual4));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( SymbolicConditional, equals )
|
TEST( SymbolicConditional, equals )
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,23 @@ TEST(SymbolicFactor, eliminate) {
|
||||||
CHECK(assert_equal(**fragmentCond++, *expected2));
|
CHECK(assert_equal(**fragmentCond++, *expected2));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST(SymbolicFactor, Constructors)
|
||||||
|
{
|
||||||
|
SymbolicFactor expected(3, 4);
|
||||||
|
|
||||||
|
SymbolicFactor actual1 = SymbolicFactor::FromKeys(expected.keys());
|
||||||
|
SymbolicFactor actual2 = SymbolicFactor::FromIterators(expected.begin(), expected.end());
|
||||||
|
SymbolicFactor actual3 = *SymbolicFactor::FromKeysShared(expected.keys());
|
||||||
|
SymbolicFactor actual4 = *SymbolicFactor::FromIteratorsShared(expected.begin(), expected.end());
|
||||||
|
|
||||||
|
EXPECT(assert_equal(expected, actual1));
|
||||||
|
EXPECT(assert_equal(expected, actual2));
|
||||||
|
EXPECT(assert_equal(expected, actual3));
|
||||||
|
EXPECT(assert_equal(expected, actual4));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST(SymbolicFactor, EliminateSymbolic)
|
TEST(SymbolicFactor, EliminateSymbolic)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue