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  }
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 
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
TEST
TEST(Group, S2)
Definition: testGroup.cpp:81
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::operator<<
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
Definition: testGroup.cpp:109
Eigen::PermutationMatrix< N >::indices
const IndicesType & indices() const
Definition: PermutationMatrix.h:360
gtsam::Symmetric::equals
bool equals(const Symmetric< N > &other, double tol=0) const
Definition: testGroup.cpp:60
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::Symmetric::operator<<
friend std::ostream & operator<<(std::ostream &os, const Symmetric &m)
Definition: testGroup.cpp:52
Group.h
Concept check class for variable types with Group properties.
gtsam::Symmetric::operator*
Symmetric operator*(const Symmetric &other) const
Definition: testGroup.cpp:40
m1
Matrix3d m1
Definition: IOFormat.cpp:2
gtsam::traits< Dih6 >::Print
static void Print(const Dih6 &m, const string &s="")
Definition: testGroup.cpp:118
gtsam::DirectProduct
Definition: Group.h:134
gtsam::traits< Dih6 >::Equals
static bool Equals(const Dih6 &m1, const Dih6 &m2, double tol=1e-8)
Definition: testGroup.cpp:121
os
ofstream os("timeSchurFactors.csv")
gtsam::Symmetric::Transposition
static Symmetric Transposition(int i, int j)
Definition: testGroup.cpp:36
gtsam::IsGroup
Definition: Group.h:42
Eigen::PermutationMatrix< N >::PermutationMatrix
PermutationMatrix()
Definition: PermutationMatrix.h:310
gtsam::Dih6
DirectProduct< S2, S3 > Dih6
Definition: testGroup.cpp:107
m2
MatrixType m2(n_dims)
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
S2
Symmetric< 2 > S2
Definition: testGroup.cpp:80
gtsam::Symmetric::operator==
bool operator==(const Symmetric &other) const
Definition: testGroup.cpp:43
gtsam::Symmetric
Symmetric group.
Definition: testGroup.cpp:27
gtsam::Symmetric::print
void print(const std::string &s="") const
Definition: testGroup.cpp:57
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
main
int main()
Definition: testGroup.cpp:138
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
TestResult
Definition: TestResult.h:26
gtsam::Symmetric::Identity
static Symmetric Identity()
Definition: testGroup.cpp:32
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
gtsam::Symmetric::Symmetric
Symmetric(const Eigen::PermutationMatrix< N > &P)
Definition: testGroup.cpp:28
Eigen::PermutationBase< PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex > >::operator*
PlainPermutationType operator*(const PermutationBase< Other > &other) const
Definition: PermutationMatrix.h:219
S3
Symmetric< 3 > S3
Definition: testGroup.cpp:88
std
Definition: BFloat16.h:88
Eigen::PermutationMatrix
Permutation matrix.
Definition: PermutationMatrix.h:297
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
P
static double P[]
Definition: ellpe.c:68
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Symmetric::inverse
Symmetric inverse() const
Definition: testGroup.cpp:49
gtsam::Symmetric::Symmetric
Symmetric()
Definition: testGroup.cpp:33
N
#define N
Definition: igam.h:9
Eigen::PermutationBase< PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex > >::setIdentity
void setIdentity()
Definition: PermutationMatrix.h:131
GTSAM_CONCEPT_ASSERT
#define GTSAM_CONCEPT_ASSERT(concept)
Definition: base/concepts.h:22
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:38