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 
46  DiscreteKeys keys(key1);
47  return keys & key2;
48  }
49 
50  void DiscreteKeys::print(const std::string& s,
51  const KeyFormatter& keyFormatter) const {
52  for (auto&& dkey : *this) {
53  std::cout << DefaultKeyFormatter(dkey.first) << " " << dkey.second
54  << std::endl;
55  }
56  }
57 
58  bool DiscreteKeys::equals(const DiscreteKeys& other, double tol) const {
59  if (this->size() != other.size()) {
60  return false;
61  }
62 
63  for (size_t i = 0; i < this->size(); i++) {
64  if (this->at(i).first != other.at(i).first ||
65  this->at(i).second != other.at(i).second) {
66  return false;
67  }
68  }
69  return true;
70  }
71 }
const gtsam::Symbol key('X', 0)
DiscreteKeys()
Constructor for serialization.
Definition: DiscreteKey.h:47
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print the keys and cardinalities.
Definition: DiscreteKey.cpp:50
Definition: BFloat16.h:88
DiscreteKeys operator &(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition: DiscreteKey.cpp:45
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
const Symbol key1('v', 1)
bool equals(const DiscreteKeys &other, double tol=0) const
Check equality to another DiscreteKeys object.
Definition: DiscreteKey.cpp:58
RealScalar s
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
traits
Definition: chartTesting.h:28
specialized key for discrete variables
static EIGEN_DEPRECATED const end_t end
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
Annotation for function names.
Definition: attr.h:48
const G double tol
Definition: Group.h:86
KeyVector indices() const
Return a vector of indices.
Definition: DiscreteKey.cpp:33
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
std::map< Key, size_t > cardinalities() const
Return a map from index to cardinality.
Definition: DiscreteKey.cpp:39
const Symbol key2('v', 2)
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


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