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 
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::operator<<
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
Definition: testGroup.cpp:109
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::Symbol::equals
bool equals(const Symbol &expected, double tol=0.0) const
Check equality.
Definition: Symbol.cpp:54
gtsam::Symbol::c_
unsigned char c_
Definition: inference/Symbol.h:39
gtsam::indexMask
static const Key indexMask
Definition: Symbol.cpp:33
gtsam::indexBits
static const size_t indexBits
Definition: Symbol.cpp:31
buffer
Definition: pytypes.h:2270
os
ofstream os("timeSchurFactors.csv")
gtsam::Symbol::ChrTest
static std::function< bool(Key)> ChrTest(unsigned char c)
Definition: Symbol.cpp:66
gtsam::Symbol::chr
unsigned char chr() const
Definition: inference/Symbol.h:75
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::symbol
Key symbol(unsigned char c, std::uint64_t j)
Definition: inference/Symbol.h:139
Symbol.h
gtsam::chrBits
static const size_t chrBits
Definition: Symbol.cpp:30
gtsam::Symbol::key
Key key() const
Definition: Symbol.cpp:40
gtsam::equals
Definition: Testable.h:112
gtsam::Symbol::print
void print(const std::string &s="") const
Print.
Definition: Symbol.cpp:50
key
const gtsam::Symbol key('X', 0)
gtsam::StreamedKey
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
Definition: Key.h:64
gtsam
traits
Definition: SFMdata.h:40
gtsam::chrMask
static const Key chrMask
Definition: Symbol.cpp:32
gtsam::Symbol::Symbol
Symbol()
Definition: inference/Symbol.h:45
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::keyBits
static const size_t keyBits
Definition: Symbol.cpp:29
gtsam::Symbol::j_
std::uint64_t j_
Definition: inference/Symbol.h:40
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::make
static LabeledSymbol make(gtsam::Key key)
Definition: LabeledSymbol.cpp:109
gtsam::Symbol
Definition: inference/Symbol.h:37
pybind11.msg
msg
Definition: wrap/pybind11/pybind11/__init__.py:6


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:05:21