Loading...
Searching...
No Matches
Cyclic.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/base/Group.h>
#include <gtsam/base/Testable.h>
#include <cassert>
#include <iostream> // for cout :-(
namespace gtsam {
template<size_t N>
class Cyclic {
size_t i_;
public:
Cyclic(size_t i) :
i_(i) {
assert(i < N);
}
Cyclic():i_(0) {
}
static Cyclic Identity() { return Cyclic();}
operator size_t() const {
return i_;
}
Cyclic operator+(const Cyclic& h) const {
return (i_ + h.i_) % N;
}
Cyclic operator-(const Cyclic& h) const {
return (N + i_ - h.i_) % N;
}
Cyclic operator-() const {
return (N - i_) % N;
}
void print(const std::string& s = "") const {
std::cout << s << i_ << std::endl;
}
bool equals(const Cyclic& other, double tol = 1e-9) const {
return other.i_ == i_;
}
};
template<size_t N>
struct traits<Cyclic<N> > : internal::AdditiveGroupTraits<Cyclic<N> >, //
Testable<Cyclic<N> > {
};
} // \namespace gtsam
Testable.h
Concept check for values that can be used in unit tests.
Group.h
Concept check class for variable types with Group properties.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::Cyclic
Cyclic group of order N.
Definition Cyclic.h:30
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::print
void print(const std::string &s="") const
print with optional string
Definition Cyclic.h:60
gtsam::Cyclic::Cyclic
Cyclic()
Default constructor yields identity.
Definition Cyclic.h:39
gtsam::Cyclic::Cyclic
Cyclic(size_t i)
Constructor.
Definition Cyclic.h:34
gtsam::Cyclic::operator-
Cyclic operator-(const Cyclic &h) const
Subtraction modulo N.
Definition Cyclic.h:52
gtsam::Cyclic::operator+
Cyclic operator+(const Cyclic &h) const
Addition modulo N.
Definition Cyclic.h:48
gtsam::Cyclic::operator-
Cyclic operator-() const
Inverse.
Definition Cyclic.h:56