Cyclic.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 
18 #pragma once
19 
20 #include <gtsam/base/Group.h>
21 #include <gtsam/base/Testable.h>
22 
23 #include <cassert>
24 #include <iostream> // for cout :-(
25 
26 namespace gtsam {
27 
29 template<size_t N>
30 class Cyclic {
31  size_t i_;
32 public:
34  Cyclic(size_t i) :
35  i_(i) {
36  assert(i < N);
37  }
39  Cyclic():i_(0) {
40  }
41  static Cyclic Identity() { return Cyclic();}
42 
44  operator size_t() const {
45  return i_;
46  }
48  Cyclic operator+(const Cyclic& h) const {
49  return (i_ + h.i_) % N;
50  }
52  Cyclic operator-(const Cyclic& h) const {
53  return (N + i_ - h.i_) % N;
54  }
56  Cyclic operator-() const {
57  return (N - i_) % N;
58  }
60  void print(const std::string& s = "") const {
61  std::cout << s << i_ << std::endl;
62  }
64  bool equals(const Cyclic& other, double tol = 1e-9) const {
65  return other.i_ == i_;
66  }
67 };
68 
70 template<size_t N>
71 struct traits<Cyclic<N> > : internal::AdditiveGroupTraits<Cyclic<N> >, //
72  Testable<Cyclic<N> > {
73 };
74 
75 } // \namespace gtsam
76 
gtsam::Cyclic::Cyclic
Cyclic(size_t i)
Constructor.
Definition: Cyclic.h:34
s
RealScalar s
Definition: level1_cplx_impl.h:126
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::Cyclic::operator-
Cyclic operator-(const Cyclic &h) const
Subtraction modulo N.
Definition: Cyclic.h:52
gtsam::Cyclic
Cyclic group of order N.
Definition: Cyclic.h:30
Group.h
Concept check class for variable types with Group properties.
gtsam::Cyclic::print
void print(const std::string &s="") const
print with optional string
Definition: Cyclic.h:60
h
const double h
Definition: testSimpleHelicopter.cpp:19
gtsam::Cyclic::equals
bool equals(const Cyclic &other, double tol=1e-9) const
equals with an tolerance, prints out message if unequal
Definition: Cyclic.h:64
gtsam::Cyclic::Identity
static Cyclic Identity()
Definition: Cyclic.h:41
gtsam::Cyclic::Cyclic
Cyclic()
Default constructor yields identity.
Definition: Cyclic.h:39
gtsam::Cyclic::i_
size_t i_
we just use an unsigned int
Definition: Cyclic.h:31
gtsam::Cyclic::operator+
Cyclic operator+(const Cyclic &h) const
Addition modulo N.
Definition: Cyclic.h:48
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
gtsam::tol
const G double tol
Definition: Group.h:79
N
#define N
Definition: igam.h:9
gtsam::Cyclic::operator-
Cyclic operator-() const
Inverse.
Definition: Cyclic.h:56
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:02:10