Tweaks to factor constructors and other small cleanups
parent
083c7213b5
commit
b9016adbd6
|
|
@ -56,6 +56,10 @@ namespace gtsam {
|
||||||
static const KeyFormatter DefaultKeyFormatter = &_defaultKeyFormatter;
|
static const KeyFormatter DefaultKeyFormatter = &_defaultKeyFormatter;
|
||||||
|
|
||||||
|
|
||||||
|
/// The index type for Eigen objects
|
||||||
|
typedef ptrdiff_t DenseIndex;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class that uses templates to select between two types based on
|
* Helper class that uses templates to select between two types based on
|
||||||
* whether TEST_TYPE is const or not.
|
* whether TEST_TYPE is const or not.
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ namespace gtsam {
|
||||||
size_t nrFrontals_;
|
size_t nrFrontals_;
|
||||||
|
|
||||||
/** Iterator over keys */
|
/** Iterator over keys */
|
||||||
typedef typename FACTOR::iterator iterator;
|
using typename FACTOR::iterator; // 'using' instead of typedef to avoid ambiguous symbol from multiple inheritance
|
||||||
|
|
||||||
/** Const iterator over keys */
|
/** Const iterator over keys */
|
||||||
typedef typename FACTOR::const_iterator const_iterator;
|
using typename FACTOR::const_iterator; // 'using' instead of typedef to avoid ambiguous symbol from multiple inheritance
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,13 @@ namespace gtsam {
|
||||||
* during symbolic elimination. GaussianFactor and NonlinearFactor are virtual.
|
* during symbolic elimination. GaussianFactor and NonlinearFactor are virtual.
|
||||||
* \nosubgrouping
|
* \nosubgrouping
|
||||||
*/
|
*/
|
||||||
class GTSAM_EXPORT FactorUnordered {
|
class GTSAM_EXPORT FactorUnordered
|
||||||
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// These typedefs are private because they must be overridden in derived classes.
|
||||||
typedef FactorUnordered This; ///< This class
|
typedef FactorUnordered This; ///< This class
|
||||||
|
typedef boost::shared_ptr<FactorUnordered> shared_ptr; ///< A shared_ptr to this class.
|
||||||
/// A shared_ptr to this class, derived classes must redefine this.
|
|
||||||
typedef boost::shared_ptr<FactorUnordered> shared_ptr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Iterator over keys
|
/// Iterator over keys
|
||||||
|
|
@ -74,45 +74,27 @@ protected:
|
||||||
/** Default constructor for I/O */
|
/** Default constructor for I/O */
|
||||||
FactorUnordered() {}
|
FactorUnordered() {}
|
||||||
|
|
||||||
/** Construct unary factor */
|
/** Construct factor from container of keys. This constructor is used internally from derived factor
|
||||||
FactorUnordered(Key key) : keys_(1) {
|
* constructors, either from a container of keys or from a boost::assign::list_of. */
|
||||||
keys_[0] = key; }
|
template<typename CONTAINER>
|
||||||
|
FactorUnordered(const CONTAINER& keys) : keys_(keys.begin(), keys.end()) {}
|
||||||
|
|
||||||
/** Construct binary factor */
|
/** Construct factor from iterator keys. This constructor may be used internally from derived
|
||||||
FactorUnordered(Key key1, Key key2) : keys_(2) {
|
* factor constructors, although our code currently does not use this. */
|
||||||
keys_[0] = key1; keys_[1] = key2; }
|
template<typename ITERATOR>
|
||||||
|
FactorUnordered(ITERATOR first, ITERATOR last) : keys_(first, last) {}
|
||||||
|
|
||||||
/** Construct ternary factor */
|
/** Construct factor from container of keys. This is called internally from derived factor static
|
||||||
FactorUnordered(Key key1, Key key2, Key key3) : keys_(3) {
|
* factor methods, as a workaround for not being able to call the protected constructors above. */
|
||||||
keys_[0] = key1; keys_[1] = key2; keys_[2] = key3; }
|
template<typename CONTAINER>
|
||||||
|
static FactorUnordered FromKeys(const CONTAINER& keys) {
|
||||||
|
return FactorUnordered(keys.begin(), keys.end()); }
|
||||||
|
|
||||||
/** Construct 4-way factor */
|
/** Construct factor from iterator keys. This is called internally from derived factor static
|
||||||
FactorUnordered(Key key1, Key key2, Key key3, Key key4) : keys_(4) {
|
* factor methods, as a workaround for not being able to call the protected constructors above. */
|
||||||
keys_[0] = key1; keys_[1] = key2; keys_[2] = key3; keys_[3] = key4; }
|
template<typename ITERATOR>
|
||||||
|
static FactorUnordered FromIterators(ITERATOR first, ITERATOR last) {
|
||||||
/** Construct 5-way factor */
|
return FactorUnordered(first, last); }
|
||||||
FactorUnordered(Key key1, Key key2, Key key3, Key key4, Key key5) : keys_(5) {
|
|
||||||
keys_[0] = key1; keys_[1] = key2; keys_[2] = key3; keys_[3] = key4; keys_[4] = key5; }
|
|
||||||
|
|
||||||
/** Construct 6-way factor */
|
|
||||||
FactorUnordered(Key key1, Key key2, Key key3, Key key4, Key key5, Key key6) : keys_(6) {
|
|
||||||
keys_[0] = key1; keys_[1] = key2; keys_[2] = key3; keys_[3] = key4; keys_[4] = key5; keys_[5] = key6; }
|
|
||||||
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
|
|
||||||
/// @name Advanced Constructors
|
|
||||||
/// @{
|
|
||||||
|
|
||||||
/** Construct n-way factor from iterator over keys. */
|
|
||||||
template<typename ITERATOR> static FactorUnordered FromIterator(ITERATOR first, ITERATOR last) {
|
|
||||||
FactorUnordered result;
|
|
||||||
result.keys_.assign(first, last);
|
|
||||||
return result; }
|
|
||||||
|
|
||||||
/** Construct n-way factor from container of keys. */
|
|
||||||
template<class CONTAINER>
|
|
||||||
static FactorUnordered FromKeys(const CONTAINER& keys) { return FromIterator(keys.begin(), keys.end()); }
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,4 +114,40 @@ on gtsam::IndeterminantLinearSystemException for more information.\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
/** An exception indicating that the noise model dimension passed into a
|
||||||
|
* JacobianFactor has a different dimensionality than the factor. */
|
||||||
|
class InvalidNoiseModel : public std::exception {
|
||||||
|
public:
|
||||||
|
const DenseIndex factorDims; ///< The dimensionality of the factor
|
||||||
|
const DenseIndex noiseModelDims; ///< The dimensionality of the noise model
|
||||||
|
|
||||||
|
InvalidNoiseModel(DenseIndex factorDims, DenseIndex noiseModelDims) :
|
||||||
|
factorDims(factorDims), noiseModelDims(noiseModelDims) {}
|
||||||
|
virtual ~InvalidNoiseModel() throw() {}
|
||||||
|
|
||||||
|
virtual const char* what() const throw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable std::string description_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
/** An exception indicating that a matrix block passed into a
|
||||||
|
* JacobianFactor has a different dimensionality than the factor. */
|
||||||
|
class InvalidMatrixBlock : public std::exception {
|
||||||
|
public:
|
||||||
|
const DenseIndex factorRows; ///< The dimensionality of the factor
|
||||||
|
const DenseIndex blockRows; ///< The dimensionality of the noise model
|
||||||
|
|
||||||
|
InvalidMatrixBlock(DenseIndex factorRows, DenseIndex blockRows) :
|
||||||
|
factorRows(factorRows), blockRows(noiseModelDims) {}
|
||||||
|
virtual ~InvalidMatrixBlock() throw() {}
|
||||||
|
|
||||||
|
virtual const char* what() const throw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable std::string description_;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,14 @@ namespace gtsam {
|
||||||
* class for conditionals.
|
* class for conditionals.
|
||||||
* \nosubgrouping
|
* \nosubgrouping
|
||||||
*/
|
*/
|
||||||
class GTSAM_EXPORT SymbolicConditionalUnordered : public SymbolicFactorUnordered, public ConditionalUnordered<SymbolicFactorUnordered,SymbolicConditionalUnordered> {
|
class GTSAM_EXPORT SymbolicConditionalUnordered :
|
||||||
|
public SymbolicFactorUnordered,
|
||||||
|
public ConditionalUnordered<SymbolicFactorUnordered, SymbolicConditionalUnordered> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef SymbolicConditionalUnordered This; /// Typedef to this class
|
typedef SymbolicConditionalUnordered This; /// Typedef to this class
|
||||||
typedef SymbolicFactorUnordered BaseFactor; /// Typedef to the factor base class
|
typedef SymbolicFactorUnordered BaseFactor; /// Typedef to the factor base class
|
||||||
typedef ConditionalUnordered<SymbolicFactorUnordered,SymbolicConditionalUnordered> BaseConditional; /// Typedef to the conditional base class
|
typedef ConditionalUnordered<BaseFactor, This> BaseConditional; /// Typedef to the conditional base class
|
||||||
typedef boost::shared_ptr<This> shared_ptr; /// Boost shared_ptr to this class
|
typedef boost::shared_ptr<This> shared_ptr; /// Boost shared_ptr to this class
|
||||||
typedef BaseFactor::iterator iterator; /// iterator to keys
|
typedef BaseFactor::iterator iterator; /// iterator to keys
|
||||||
typedef BaseFactor::const_iterator const_iterator; /// const_iterator to keys
|
typedef BaseFactor::const_iterator const_iterator; /// const_iterator to keys
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/assign/list_of.hpp>
|
||||||
|
|
||||||
#include <gtsam/inference/FactorUnordered.h>
|
#include <gtsam/inference/FactorUnordered.h>
|
||||||
#include <gtsam/inference/Key.h>
|
#include <gtsam/inference/Key.h>
|
||||||
|
|
@ -54,41 +55,47 @@ namespace gtsam {
|
||||||
SymbolicFactorUnordered() {}
|
SymbolicFactorUnordered() {}
|
||||||
|
|
||||||
/** Construct unary factor */
|
/** Construct unary factor */
|
||||||
SymbolicFactorUnordered(Key j) : Base(j) {}
|
SymbolicFactorUnordered(Key j) :
|
||||||
|
Base(boost::assign::cref_list_of<1>(j)) {}
|
||||||
|
|
||||||
/** Construct binary factor */
|
/** Construct binary factor */
|
||||||
SymbolicFactorUnordered(Key j1, Key j2) : Base(j1, j2) {}
|
SymbolicFactorUnordered(Key j1, Key j2) :
|
||||||
|
Base(boost::assign::cref_list_of<2>(j1)(j2)) {}
|
||||||
|
|
||||||
/** Construct ternary factor */
|
/** Construct ternary factor */
|
||||||
SymbolicFactorUnordered(Key j1, Key j2, Key j3) : Base(j1, j2, j3) {}
|
SymbolicFactorUnordered(Key j1, Key j2, Key j3) :
|
||||||
|
Base(boost::assign::cref_list_of<3>(j1)(j2)(j3)) {}
|
||||||
|
|
||||||
/** Construct 4-way factor */
|
/** Construct 4-way factor */
|
||||||
SymbolicFactorUnordered(Key j1, Key j2, Key j3, Key j4) : Base(j1, j2, j3, j4) {}
|
SymbolicFactorUnordered(Key j1, Key j2, Key j3, Key j4) :
|
||||||
|
Base(boost::assign::cref_list_of<4>(j1)(j2)(j3)(j4)) {}
|
||||||
|
|
||||||
/** Construct 5-way factor */
|
/** Construct 5-way factor */
|
||||||
SymbolicFactorUnordered(Key j1, Key j2, Key j3, Key j4, Key j5) : Base(j1, j2, j3, j4, j5) {}
|
SymbolicFactorUnordered(Key j1, Key j2, Key j3, Key j4, Key j5) :
|
||||||
|
Base(boost::assign::cref_list_of<5>(j1)(j2)(j3)(j4)(j5)) {}
|
||||||
|
|
||||||
/** Construct 6-way factor */
|
/** Construct 6-way factor */
|
||||||
SymbolicFactorUnordered(Key j1, Key j2, Key j3, Key j4, Key j5, Key j6) : Base(j1, j2, j3, j4, j5, j6) {}
|
SymbolicFactorUnordered(Key j1, Key j2, Key j3, Key j4, Key j5, Key j6) :
|
||||||
|
Base(boost::assign::cref_list_of<6>(j1)(j2)(j3)(j4)(j5)(j6)) {}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// @name Advanced Constructors
|
/// @name Advanced Constructors
|
||||||
/// @{
|
/// @{
|
||||||
|
private:
|
||||||
|
explicit SymbolicFactorUnordered(const Base& base) :
|
||||||
|
Base(base) {}
|
||||||
|
|
||||||
|
public:
|
||||||
/** Constructor from a collection of keys */
|
/** Constructor from a collection of keys */
|
||||||
template<typename KEYITERATOR>
|
template<typename KEYITERATOR>
|
||||||
static SymbolicFactorUnordered FromIterator(KEYITERATOR beginKey, KEYITERATOR endKey) {
|
static SymbolicFactorUnordered FromIterator(KEYITERATOR beginKey, KEYITERATOR endKey) {
|
||||||
SymbolicFactorUnordered result;
|
return SymbolicFactorUnordered(Base::FromIterators(beginKey, endKey)); }
|
||||||
(Base&)result = Base::FromIterator(beginKey, endKey);
|
|
||||||
return result; }
|
|
||||||
|
|
||||||
/** Constructor from a collection of keys */
|
/** Constructor from a collection of keys */
|
||||||
template<class CONTAINER>
|
template<class CONTAINER>
|
||||||
static SymbolicFactorUnordered FromKeys(const CONTAINER& keys) {
|
static SymbolicFactorUnordered FromKeys(const CONTAINER& keys) {
|
||||||
SymbolicFactorUnordered result;
|
return SymbolicFactorUnordered(Base::FromKeys(keys)); }
|
||||||
(Base&)result = Base::FromKeys(keys);
|
|
||||||
return result; }
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue