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 <limits.h>
22 #include <list>
23 #include <iostream>
24 #include <sstream>
25 #include <cstdio>
26 
27 namespace gtsam {
28 
29 static const size_t keyBits = sizeof(Key) * 8;
30 static const size_t chrBits = sizeof(unsigned char) * 8;
31 static const size_t indexBits = keyBits - chrBits;
32 static const Key chrMask = Key(UCHAR_MAX) << indexBits; // For some reason, std::numeric_limits<unsigned char>::max() fails
33 static const Key indexMask = ~chrMask;
34 
36  c_((unsigned char) ((key & chrMask) >> indexBits)),
37  j_ (key & indexMask) {
38 }
39 
40 Key Symbol::key() const {
41  if (j_ > indexMask) {
42  std::stringstream msg;
43  msg << "Symbol index is too large, j=" << j_ << ", indexMask=" << indexMask;
44  throw std::invalid_argument(msg.str());
45  }
46  Key key = (Key(c_) << indexBits) | j_;
47  return key;
48 }
49 
50 void Symbol::print(const std::string& s) const {
51  std::cout << s << (std::string) (*this) << std::endl;
52 }
53 
54 bool Symbol::equals(const Symbol& expected, double tol) const {
55  return (*this) == expected;
56 }
57 
58 Symbol::operator std::string() const {
59  char buffer[10];
60  snprintf(buffer, 10, "%c%llu", c_, static_cast<unsigned long long>(j_));
61  return std::string(buffer);
62 }
63 
64 static Symbol make(gtsam::Key key) { return Symbol(key);}
65 
66 std::function<bool(Key)> Symbol::ChrTest(unsigned char c) {
67  auto equals = [](unsigned char s, unsigned char c) { return s == c; };
68  return std::bind(
69  equals, std::bind(&Symbol::chr, std::bind(make, std::placeholders::_1)),
70  c);
71 }
72 
73 GTSAM_EXPORT std::ostream &operator<<(std::ostream &os, const Symbol &symbol) {
74  os << StreamedKey(symbol);
75  return os;
76 }
77 
78 } // namespace gtsam
79 
const gtsam::Symbol key('X', 0)
static LabeledSymbol make(gtsam::Key key)
Matrix expected
Definition: testMatrix.cpp:971
static const Key chrMask
Definition: Symbol.cpp:32
static const Key indexMask
Definition: Symbol.cpp:33
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:73
void print(const std::string &s="") const
Print.
Definition: Symbol.cpp:50
static const size_t indexBits
Definition: Symbol.cpp:31
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 key() const
Definition: Symbol.cpp:40
Key symbol(unsigned char c, std::uint64_t j)
static const size_t chrBits
Definition: Symbol.cpp:30
traits
Definition: chartTesting.h:28
bool equals(const Symbol &expected, double tol=0.0) const
Check equality.
Definition: Symbol.cpp:54
unsigned char chr() const
static const size_t keyBits
Definition: Symbol.cpp:29
ofstream os("timeSchurFactors.csv")
static std::function< bool(Key)> ChrTest(unsigned char c)
Definition: Symbol.cpp:66
const G double tol
Definition: Group.h:86
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:36:34