Symbol.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 
19 #include <gtsam/inference/Symbol.h>
20 
21 #include <boost/format.hpp>
22 #include <boost/bind.hpp>
23 
24 #include <limits.h>
25 #include <list>
26 #include <iostream>
27 
28 namespace gtsam {
29 
30 static const size_t keyBits = sizeof(Key) * 8;
31 static const size_t chrBits = sizeof(unsigned char) * 8;
32 static const size_t indexBits = keyBits - chrBits;
33 static const Key chrMask = Key(UCHAR_MAX) << indexBits; // For some reason, std::numeric_limits<unsigned char>::max() fails
34 static const Key indexMask = ~chrMask;
35 
37  c_((unsigned char) ((key & chrMask) >> indexBits)),
38  j_ (key & indexMask) {
39 }
40 
41 Key Symbol::key() const {
42  if (j_ > indexMask) {
43  boost::format msg("Symbol index is too large, j=%d, indexMask=%d");
44  msg % j_ % indexMask;
45  throw std::invalid_argument(msg.str());
46  }
47  Key key = (Key(c_) << indexBits) | j_;
48  return key;
49 }
50 
51 void Symbol::print(const std::string& s) const {
52  std::cout << s << (std::string) (*this) << std::endl;
53 }
54 
55 bool Symbol::equals(const Symbol& expected, double tol) const {
56  return (*this) == expected;
57 }
58 
59 Symbol::operator std::string() const {
60  return str(boost::format("%c%d") % c_ % j_);
61 }
62 
63 static Symbol make(gtsam::Key key) { return Symbol(key);}
64 
65 boost::function<bool(Key)> Symbol::ChrTest(unsigned char c) {
66  return bind(&Symbol::chr, bind(make, _1)) == c;
67 }
68 
69 GTSAM_EXPORT std::ostream &operator<<(std::ostream &os, const Symbol &symbol) {
70  os << StreamedKey(symbol);
71  return os;
72 }
73 
74 } // namespace gtsam
75 
void print(const std::string &s="") const
Print.
Definition: Symbol.cpp:51
static LabeledSymbol make(gtsam::Key key)
Matrix expected
Definition: testMatrix.cpp:974
unsigned char chr() const
static const Key chrMask
Definition: Symbol.cpp:33
static const Key indexMask
Definition: Symbol.cpp:34
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
unsigned char c_
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &, const Symbol &)
Output stream operator that can be used with key_formatter (see Key.h).
Definition: Symbol.cpp:69
bool equals(const Symbol &expected, double tol=0.0) const
Check equality.
Definition: Symbol.cpp:55
static const size_t indexBits
Definition: Symbol.cpp:32
std::uint64_t j_
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
Definition: Key.h:58
RealScalar s
Key symbol(unsigned char c, std::uint64_t j)
Key key() const
Definition: Symbol.cpp:41
static const size_t chrBits
Definition: Symbol.cpp:31
traits
Definition: chartTesting.h:28
static const size_t keyBits
Definition: Symbol.cpp:30
ofstream os("timeSchurFactors.csv")
static boost::function< bool(Key)> ChrTest(unsigned char c)
Definition: Symbol.cpp:65
const G double tol
Definition: Group.h:83
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:45:07