testGroup.cpp
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 
18 #include <gtsam/base/Group.h>
19 #include <gtsam/base/Testable.h>
20 #include <Eigen/Core>
21 #include <iostream>
22 
23 namespace gtsam {
24 
26 template<int N>
30  }
31 public:
32  static Symmetric identity() { return Symmetric(); }
35  }
36  static Symmetric Transposition(int i, int j) {
37  Symmetric g;
38  return g.applyTranspositionOnTheRight(i, j);
39  }
40  Symmetric operator*(const Symmetric& other) const {
42  }
43  bool operator==(const Symmetric& other) const {
44  for (size_t i = 0; i < N; i++)
45  if (this->indices()[i] != other.indices()[i])
46  return false;
47  return true;
48  }
49  Symmetric inverse() const {
51  }
52  friend std::ostream &operator<<(std::ostream &os, const Symmetric& m) {
53  for (size_t i = 0; i < N; i++)
54  os << m.indices()[i] << " ";
55  return os;
56  }
57  void print(const std::string& s = "") const {
58  std::cout << s << *this << std::endl;
59  }
60  bool equals(const Symmetric<N>& other, double tol = 0) const {
61  return this->indices() == other.indices();
62  }
63 };
64 
66 template<int N>
67 struct traits<Symmetric<N> > : internal::MultiplicativeGroupTraits<Symmetric<N> >,
68  Testable<Symmetric<N> > {
69 };
70 
71 } // namespace gtsam
72 
73 #include <gtsam/base/Testable.h>
75 
76 using namespace std;
77 using namespace gtsam;
78 
79 //******************************************************************************
80 typedef Symmetric<2> S2;
81 TEST(Group, S2) {
82  S2 e, s1 = S2::Transposition(0, 1);
84  EXPECT(check_group_invariants(e, s1));
85 }
86 
87 //******************************************************************************
88 typedef Symmetric<3> S3;
89 TEST(Group, S3) {
90  S3 e, s1 = S3::Transposition(0, 1), s2 = S3::Transposition(1, 2);
92  EXPECT(check_group_invariants(e, s1));
93  EXPECT(assert_equal(s1, s1 * e));
94  EXPECT(assert_equal(s1, e * s1));
95  EXPECT(assert_equal(e, s1 * s1));
96  S3 g = s1 * s2; // 1 2 0
97  EXPECT(assert_equal(s1, g * s2));
98  EXPECT(assert_equal(e, compose_pow(g, 0)));
99  EXPECT(assert_equal(g, compose_pow(g, 1)));
100  EXPECT(assert_equal(e, compose_pow(g, 3))); // g is generator of Z3 subgroup
101 }
102 
103 //******************************************************************************
104 // The direct product of S2=Z2 and S3 is the symmetry group of a hexagon,
105 // i.e., the dihedral group of order 12 (denoted Dih6 because 6-sided polygon)
106 namespace gtsam {
108 
109 std::ostream &operator<<(std::ostream &os, const Dih6& m) {
110  os << "( " << m.first << ", " << m.second << ")";
111  return os;
112 }
113 
114 // Provide traits with Testable
115 
116 template<>
117 struct traits<Dih6> : internal::MultiplicativeGroupTraits<Dih6> {
118  static void Print(const Dih6& m, const string& s = "") {
119  cout << s << m << endl;
120  }
121  static bool Equals(const Dih6& m1, const Dih6& m2, double tol = 1e-8) {
122  return m1 == m2;
123  }
124 };
125 } // namespace gtsam
126 
127 TEST(Group, Dih6) {
128  Dih6 e, g(S2::Transposition(0, 1),
129  S3::Transposition(0, 1) * S3::Transposition(1, 2));
131  EXPECT(check_group_invariants(e, g));
132  EXPECT(assert_equal(e, compose_pow(g, 0)));
133  EXPECT(assert_equal(g, compose_pow(g, 1)));
134  EXPECT(assert_equal(e, compose_pow(g, 6))); // g is generator of Z6 subgroup
135 }
136 
137 //******************************************************************************
138 int main() {
139  TestResult tr;
140  return TestRegistry::runAllTests(tr);
141 }
142 //******************************************************************************
143 
Matrix3f m
Concept check for values that can be used in unit tests.
Symmetric< 2 > S2
Definition: testGroup.cpp:80
static int runAllTests(TestResult &result)
static Symmetric identity()
Definition: testGroup.cpp:32
Concept check class for variable types with Group properties.
MatrixType m2(n_dims)
BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept< ListOfOneContainer< int > >))
static void Print(const Dih6 &m, const string &s="")
Definition: testGroup.cpp:118
Symmetric group.
Definition: testGroup.cpp:27
Derived & applyTranspositionOnTheRight(Index i, Index j)
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Definition: Half.h:150
void print(const std::string &s="") const
Definition: testGroup.cpp:57
#define N
Definition: gksort.c:12
void g(const string &key, int i)
Definition: testBTree.cpp:43
static Symmetric Transposition(int i, int j)
Definition: testGroup.cpp:36
Permutation matrix.
DirectProduct< S2, S3 > Dih6
Definition: testGroup.cpp:107
bool operator==(const Symmetric &other) const
Definition: testGroup.cpp:43
static bool Equals(const Dih6 &m1, const Dih6 &m2, double tol=1e-8)
Definition: testGroup.cpp:121
Matrix3d m1
Definition: IOFormat.cpp:2
#define EXPECT(condition)
Definition: Test.h:151
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
Symmetric inverse() const
Definition: testGroup.cpp:49
bool equals(const Symmetric< N > &other, double tol=0) const
Definition: testGroup.cpp:60
ofstream os("timeSchurFactors.csv")
friend std::ostream & operator<<(std::ostream &os, const Symmetric &m)
Definition: testGroup.cpp:52
const IndicesType & indices() const
TEST(LPInitSolver, InfiniteLoopSingleVar)
Symmetric(const Eigen::PermutationMatrix< N > &P)
Definition: testGroup.cpp:28
Symmetric operator*(const Symmetric &other) const
Definition: testGroup.cpp:40
const G double tol
Definition: Group.h:83
std::ptrdiff_t j
int main()
Definition: testGroup.cpp:138
Symmetric< 3 > S3
Definition: testGroup.cpp:88


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:47:15