DiscreteKey.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 <iostream>
20 #include "DiscreteKey.h"
21 
22 namespace gtsam {
23 
24  using namespace std;
25 
26  DiscreteKeys::DiscreteKeys(const vector<int>& cs) {
27  for (size_t i = 0; i < cs.size(); i++) {
28  string name = "v" + std::to_string(i);
29  push_back(DiscreteKey(i, cs[i]));
30  }
31  }
32 
34  KeyVector js;
35  for (const DiscreteKey& key : *this) js.push_back(key.first);
36  return js;
37  }
38 
39  map<Key, size_t> DiscreteKeys::cardinalities() const {
40  map<Key, size_t> cs;
41  cs.insert(begin(), end());
42  return cs;
43  }
44 
47  return keys & key2;
48  }
49 
50  void DiscreteKeys::print(const std::string& s,
51  const KeyFormatter& keyFormatter) const {
52  std::cout << (s.empty() ? "" : s + " ") << std::endl;
53  for (auto&& dkey : *this) {
54  std::cout << DefaultKeyFormatter(dkey.first) << " " << dkey.second
55  << std::endl;
56  }
57  }
58 
59  bool DiscreteKeys::equals(const DiscreteKeys& other, double tol) const {
60  if (this->size() != other.size()) {
61  return false;
62  }
63 
64  for (size_t i = 0; i < this->size(); i++) {
65  if (this->at(i).first != other.at(i).first ||
66  this->at(i).second != other.at(i).second) {
67  return false;
68  }
69  }
70  return true;
71  }
72 }
key1
const Symbol key1('v', 1)
name
Annotation for function names.
Definition: attr.h:51
s
RealScalar s
Definition: level1_cplx_impl.h:126
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
gtsam::DiscreteKeys::equals
bool equals(const DiscreteKeys &other, double tol=0) const
Check equality to another DiscreteKeys object.
Definition: DiscreteKey.cpp:59
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::DiscreteKeys::cardinalities
std::map< Key, size_t > cardinalities() const
Return a map from index to cardinality.
Definition: DiscreteKey.cpp:39
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys()
Constructor for serialization.
Definition: DiscreteKey.h:47
key2
const Symbol key2('v', 2)
gtsam::KeyFormatter
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
gtsam::DiscreteKeys::indices
KeyVector indices() const
Return a vector of indices.
Definition: DiscreteKey.cpp:33
DiscreteKey.h
specialized key for discrete variables
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
std
Definition: BFloat16.h:88
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteKeys::print
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print the keys and cardinalities.
Definition: DiscreteKey.cpp:50
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
gtsam::operator&
DiscreteKeys operator&(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition: DiscreteKey.cpp:45
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 Sun Dec 22 2024 04:11:28