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;
|
||||
(BaseFactor&)result = BaseFactor::FromIterators(firstKey, lastKey);
|
||||
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 */
|
||||
template<class CONTAINER>
|
||||
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() {}
|
||||
|
||||
|
|
|
@ -60,10 +60,8 @@ namespace gtsam
|
|||
|
||||
// Return resulting conditional and factor
|
||||
return std::make_pair(
|
||||
boost::make_shared<SymbolicConditional>(
|
||||
SymbolicConditional::FromKeys(orderedKeys, nFrontals)),
|
||||
boost::make_shared<SymbolicFactor>(
|
||||
SymbolicFactor::FromIterators(orderedKeys.begin() + nFrontals, orderedKeys.end())));
|
||||
SymbolicConditional::FromKeysShared(orderedKeys, nFrontals),
|
||||
SymbolicFactor::FromIteratorsShared(orderedKeys.begin() + nFrontals, orderedKeys.end()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,13 +98,30 @@ namespace gtsam {
|
|||
/** Constructor from a collection of keys */
|
||||
template<typename KEYITERATOR>
|
||||
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
|
||||
* boost::assign::cref_list_of */
|
||||
template<class CONTAINER>
|
||||
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 <CppUnitLite/TestHarness.h>
|
||||
#include <gtsam/base/TestableAssertions.h>
|
||||
#include <gtsam/symbolic/SymbolicConditional.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -84,6 +85,22 @@ TEST( SymbolicConditional, FromRange )
|
|||
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 )
|
||||
{
|
||||
|
|
|
@ -50,6 +50,23 @@ TEST(SymbolicFactor, eliminate) {
|
|||
CHECK(assert_equal(**fragmentCond++, *expected2));
|
||||
}
|
||||
#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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue