Put Derived in Group, as well

release/4.3a0
dellaert 2015-05-25 16:31:56 -07:00
parent fe8f519109
commit 6569bd49aa
1 changed files with 17 additions and 17 deletions

View File

@ -128,7 +128,7 @@ compose_pow(const G& g, size_t n) {
/// Template to construct the direct product of two arbitrary groups /// Template to construct the direct product of two arbitrary groups
/// Assumes nothing except group structure from G and H /// Assumes nothing except group structure from G and H
template<typename G, typename H> template<class Derived, typename G, typename H>
class DirectProduct: public std::pair<G, H> { class DirectProduct: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsGroup<G>)); BOOST_CONCEPT_ASSERT((IsGroup<G>));
BOOST_CONCEPT_ASSERT((IsGroup<H>)); BOOST_CONCEPT_ASSERT((IsGroup<H>));
@ -143,23 +143,22 @@ public:
// Construct from two subgroup elements // Construct from two subgroup elements
DirectProduct(const G& g, const H& h):std::pair<G,H>(g,h) {} DirectProduct(const G& g, const H& h):std::pair<G,H>(g,h) {}
DirectProduct operator*(const DirectProduct& other) const { Derived operator*(const Derived& other) const {
return DirectProduct(traits<G>::Compose(g(),other.g()), traits<H>::Compose(h(),other.h())); return Derived(traits<G>::Compose(g(),other.g()), traits<H>::Compose(h(),other.h()));
} }
DirectProduct inverse() const { Derived inverse() const {
return DirectProduct(g().inverse(), h().inverse()); return Derived(g().inverse(), h().inverse());
} }
}; };
// Define any direct product group to be a model of the multiplicative Group concept // Define any direct product group to be a model of the multiplicative Group concept
template<typename G, typename H> template<class Derived, typename G, typename H>
struct traits<DirectProduct<G, H> > : internal::MultiplicativeGroupTraits< struct traits<DirectProduct<Derived, G, H> > :
DirectProduct<G, H> > { internal::MultiplicativeGroupTraits<DirectProduct<Derived, G, H> > {};
};
/// Template to construct the direct sum of two additive groups /// Template to construct the direct sum of two additive groups
/// Assumes existence of three additive operators for both groups /// Assumes existence of three additive operators for both groups
template<typename G, typename H> template<class Derived, typename G, typename H>
class DirectSum: public std::pair<G, H> { class DirectSum: public std::pair<G, H> {
BOOST_CONCEPT_ASSERT((IsGroup<G>)); // TODO(frank): check additive BOOST_CONCEPT_ASSERT((IsGroup<G>)); // TODO(frank): check additive
BOOST_CONCEPT_ASSERT((IsGroup<H>)); // TODO(frank): check additive BOOST_CONCEPT_ASSERT((IsGroup<H>)); // TODO(frank): check additive
@ -174,20 +173,21 @@ public:
// Construct from two subgroup elements // Construct from two subgroup elements
DirectSum(const G& g, const H& h):std::pair<G,H>(g,h) {} DirectSum(const G& g, const H& h):std::pair<G,H>(g,h) {}
DirectSum operator+(const DirectSum& other) const { Derived operator+(const Derived& other) const {
return DirectSum(g()+other.g(), h()+other.h()); return DirectSum(g()+other.g(), h()+other.h());
} }
DirectSum operator-(const DirectSum& other) const { Derived operator-(const Derived& other) const {
return DirectSum(g()-other.g(), h()-other.h()); return Derived(g()-other.g(), h()-other.h());
} }
DirectSum operator-() const { Derived operator-() const {
return DirectSum(- g(), - h()); return Derived(- g(), - h());
} }
}; };
// Define direct sums to be a model of the Additive Group concept // Define direct sums to be a model of the Additive Group concept
template<typename G, typename H> template<class Derived, typename G, typename H>
struct traits<DirectSum<G, H> > : internal::AdditiveGroupTraits<DirectSum<G, H> > {}; struct traits<DirectSum<Derived, G, H> > :
internal::AdditiveGroupTraits<DirectSum<Derived, G, H> > {};
} // namespace gtsam } // namespace gtsam