Group.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
21 #pragma once
22 
23 #include <gtsam/base/Testable.h>
24 
25 #include <utility>
26 
27 namespace gtsam {
28 
30 struct group_tag {};
31 
35 
36 template <typename T> struct traits;
37 
41 template<typename G>
42 class IsGroup {
43 public:
46  //typedef typename traits<G>::identity::value_type identity_value_type;
47 
49  static_assert(
51  "This type's structure_category trait does not assert it as a group (or derived)");
53  e = traits<G>::Compose(g, h);
54  e = traits<G>::Between(g, h);
57  // todo: how do we test the act concept? or do we even need to?
58  }
59 
60 private:
62  e = g * h;
63  //e = -g; // todo this should work, but it is failing for Quaternions
64  }
66  e = g + h;
67  e = h - g;
68  e = -g;
69  }
70 
72  G e, g, h;
73  bool b;
74 };
75 
77 template<typename G>
79 check_group_invariants(const G& a, const G& b, double tol = 1e-9) {
84 }
85 
86 namespace internal {
87 
90 template<class Class>
91 struct MultiplicativeGroupTraits {
92  typedef group_tag structure_category;
93  typedef multiplicative_group_tag group_flavor;
94  static Class Identity() { return Class::Identity(); }
95  static Class Compose(const Class &g, const Class & h) { return g * h;}
96  static Class Between(const Class &g, const Class & h) { return g.inverse() * h;}
97  static Class Inverse(const Class &g) { return g.inverse();}
98 };
99 
101 template<class Class>
102 struct MultiplicativeGroup : MultiplicativeGroupTraits<Class>, Testable<Class> {};
103 
106 template<class Class>
107 struct AdditiveGroupTraits {
108  typedef group_tag structure_category;
109  typedef additive_group_tag group_flavor;
110  static Class Identity() { return Class::Identity(); }
111  static Class Compose(const Class &g, const Class & h) { return g + h;}
112  static Class Between(const Class &g, const Class & h) { return h - g;}
113  static Class Inverse(const Class &g) { return -g;}
114 };
115 
117 template<class Class>
118 struct AdditiveGroup : AdditiveGroupTraits<Class>, Testable<Class> {};
119 
120 } // namespace internal
121 
123 template<typename G>
124 GTSAM_CONCEPT_REQUIRES(IsGroup<G>,G) //
125 compose_pow(const G& g, size_t n) {
126  if (n == 0) return traits<G>::Identity();
127  else if (n == 1) return g;
128  else return traits<G>::Compose(compose_pow(g, n - 1), g);
129 }
130 
133 template<typename G, typename H>
134 class DirectProduct: public std::pair<G, H> {
137 
138 public:
141 
142  // Construct from two subgroup elements
143  DirectProduct(const G& g, const H& h):std::pair<G,H>(g,h) {}
144 
145  // identity
146  static DirectProduct Identity() { return DirectProduct(); }
147 
149  return DirectProduct(traits<G>::Compose(this->first, other.first),
150  traits<H>::Compose(this->second, other.second));
151  }
153  return DirectProduct(this->first.inverse(), this->second.inverse());
154  }
155 };
156 
157 // Define any direct product group to be a model of the multiplicative Group concept
158 template<typename G, typename H>
159 struct traits<DirectProduct<G, H> > :
160  internal::MultiplicativeGroupTraits<DirectProduct<G, H> > {};
161 
164 template<typename G, typename H>
165 class DirectSum: public std::pair<G, H> {
166  GTSAM_CONCEPT_ASSERT(IsGroup<G>); // TODO(frank): check additive
167  GTSAM_CONCEPT_ASSERT(IsGroup<H>); // TODO(frank): check additive
168 
169  const G& g() const { return this->first; }
170  const H& h() const { return this->second;}
171 
172 public:
174  DirectSum():std::pair<G,H>(traits<G>::Identity(),traits<H>::Identity()) {}
175 
176  // Construct from two subgroup elements
177  DirectSum(const G& g, const H& h):std::pair<G,H>(g,h) {}
178 
179  // identity
180  static DirectSum Identity() { return DirectSum(); }
181 
183  return DirectSum(g()+other.g(), h()+other.h());
184  }
186  return DirectSum(g()-other.g(), h()-other.h());
187  }
189  return DirectSum(- g(), - h());
190  }
191 };
192 
193 // Define direct sums to be a model of the Additive Group concept
194 template<typename G, typename H>
195 struct traits<DirectSum<G, H> > :
196  internal::AdditiveGroupTraits<DirectSum<G, H> > {};
197 
198 } // namespace gtsam
199 
208 #define GTSAM_CONCEPT_GROUP_INST(T) template class gtsam::IsGroup<T>;
209 #define GTSAM_CONCEPT_GROUP_TYPE(T) typedef gtsam::IsGroup<T> _gtsam_IsGroup_##T;
gtsam::DirectSum::operator+
DirectSum operator+(const DirectSum &other) const
Definition: Group.h:182
gtsam::DirectSum::DirectSum
DirectSum()
Default constructor yields identity.
Definition: Group.h:174
H
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Definition: gnuplot_common_settings.hh:74
gtsam::IsGroup::structure_category_tag
traits< G >::structure_category structure_category_tag
Definition: Group.h:44
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Testable.h
Concept check for values that can be used in unit tests.
gtsam::DirectProduct::DirectProduct
DirectProduct(const G &g, const H &h)
Definition: Group.h:143
gtsam::IsGroup::h
G h
Definition: Group.h:72
pybind_wrapper_test_script.this
this
Definition: pybind_wrapper_test_script.py:38
gtsam::DirectProduct
Definition: Group.h:134
gtsam::DirectSum::operator-
DirectSum operator-() const
Definition: Group.h:188
gtsam::DirectSum::DirectSum
DirectSum(const G &g, const H &h)
Definition: Group.h:177
h
const double h
Definition: testSimpleHelicopter.cpp:19
gtsam::DirectProduct::DirectProduct
DirectProduct()
Default constructor yields identity.
Definition: Group.h:140
gtsam::IsGroup
Definition: Group.h:42
gtsam::multiplicative_group_tag
Group operator syntax flavors.
Definition: Group.h:33
gtsam::DirectSum::Identity
static DirectSum Identity()
Definition: Group.h:180
gtsam::IsGroup::flavor_tag
traits< G >::group_flavor flavor_tag
Definition: Group.h:45
n
int n
Definition: BiCGSTAB_simple.cpp:1
gtsam::DirectProduct::operator*
DirectProduct operator*(const DirectProduct &other) const
Definition: Group.h:148
gtsam::IsGroup::g
G g
Definition: Group.h:72
gtsam::DirectProduct::inverse
DirectProduct inverse() const
Definition: Group.h:152
gtsam::DirectSum::operator-
DirectSum operator-(const DirectSum &other) const
Definition: Group.h:185
gtsam::DirectProduct::GTSAM_CONCEPT_ASSERT
GTSAM_CONCEPT_ASSERT(IsGroup< G >)
gtsam::DirectProduct::Identity
static DirectProduct Identity()
Definition: Group.h:146
gtsam::additive_group_tag
Definition: Group.h:34
gtsam::IsGroup::operator_usage
void operator_usage(multiplicative_group_tag)
Definition: Group.h:61
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
gtsam::DirectSum::g
const G & g() const
Definition: Group.h:169
gtsam::b
const G & b
Definition: Group.h:79
Between
BetweenFactor< Rot3 > Between
Definition: testRot3Optimization.cpp:31
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
gtsam::IsGroup::operator_usage
void operator_usage(additive_group_tag)
Definition: Group.h:65
gtsam::IsGroup::flavor
flavor_tag flavor
Definition: Group.h:71
gtsam
traits
Definition: SFMdata.h:40
Class::Identity
static Class Identity()
Definition: testExpression.cpp:121
gtsam::traits
Definition: Group.h:36
gtsam::DirectSum::GTSAM_CONCEPT_ASSERT
GTSAM_CONCEPT_ASSERT(IsGroup< G >)
gtsam::group_tag
tag to assert a type is a group
Definition: Group.h:30
Class
Definition: testExpression.cpp:116
std
Definition: BFloat16.h:88
G
JacobiRotation< float > G
Definition: Jacobi_makeGivens.cpp:2
gtsam::GTSAM_CONCEPT_REQUIRES
GTSAM_CONCEPT_REQUIRES(IsGroup< G >, bool) check_group_invariants(const G &a
Check invariants.
Inverse
Definition: Inverse.java:13
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::IsGroup::b
bool b
Definition: Group.h:73
internal
Definition: BandTriangularSolver.h:13
gtsam::IsGroup::e
G e
Definition: Group.h:72
gtsam::IsGroup::BOOST_CONCEPT_USAGE
BOOST_CONCEPT_USAGE(IsGroup)
Definition: Group.h:48
test_callbacks.value
value
Definition: test_callbacks.py:160
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::DirectSum::h
const H & h() const
Definition: Group.h:170
gtsam::DirectSum
Definition: Group.h:165


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:23