DiscreteKey.h
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 #pragma once
20 
21 #include <gtsam/global_includes.h>
22 #include <gtsam/inference/Key.h>
23 
24 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
25 #include <boost/serialization/vector.hpp>
26 #endif
27 #include <map>
28 #include <string>
29 #include <vector>
30 
31 namespace gtsam {
32 
38  using DiscreteKey = std::pair<Key,size_t>;
39 
41  struct GTSAM_EXPORT DiscreteKeys: public std::vector<DiscreteKey> {
42 
43  // Forward all constructors.
44  using std::vector<DiscreteKey>::vector;
45 
47  DiscreteKeys() : std::vector<DiscreteKey>::vector() {}
48 
50  explicit DiscreteKeys(const DiscreteKey& key) { push_back(key); }
51 
53  explicit DiscreteKeys(std::map<Key, size_t> cardinalities) {
54  for (auto&& kv : cardinalities) emplace_back(kv);
55  }
56 
58  DiscreteKeys(const std::vector<DiscreteKey>& keys) :
59  std::vector<DiscreteKey>(keys) {
60  }
61 
63  DiscreteKeys(const std::vector<int>& cs);
64 
66  KeyVector indices() const;
67 
69  std::map<Key,size_t> cardinalities() const;
70 
73  push_back(key);
74  return *this;
75  }
76 
79  this->insert(this->end(), keys.begin(), keys.end());
80  return *this;
81  }
82 
84  void print(const std::string& s = "",
85  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
86 
88  bool equals(const DiscreteKeys& other, double tol = 0) const;
89 
90 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
91 
92  friend class boost::serialization::access;
93  template <class ARCHIVE>
94  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
95  ar& boost::serialization::make_nvp(
96  "DiscreteKeys",
97  boost::serialization::base_object<std::vector<DiscreteKey>>(*this));
98  }
99 #endif
100 
101  }; // DiscreteKeys
102 
104  GTSAM_EXPORT DiscreteKeys operator&(const DiscreteKey& key1, const DiscreteKey& key2);
105 
106  // traits
107  template <>
108  struct traits<DiscreteKeys> : public Testable<DiscreteKeys> {};
109 
110  } // namespace gtsam
key1
const Symbol key1('v', 1)
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys(const std::vector< DiscreteKey > &keys)
Construct from a vector of keys.
Definition: DiscreteKey.h:58
gtsam::DiscreteKeys::operator&
DiscreteKeys & operator&(const DiscreteKey &key)
Add a key (non-const!)
Definition: DiscreteKey.h:72
global_includes.h
Included from all GTSAM files.
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::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
test_eigen_tensor.indices
indices
Definition: test_eigen_tensor.py:33
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys()
Constructor for serialization.
Definition: DiscreteKey.h:47
Key.h
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
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::equals
Definition: Testable.h:112
key
const gtsam::Symbol key('X', 0)
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys(const DiscreteKey &key)
Construct from a key.
Definition: DiscreteKey.h:50
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys(std::map< Key, size_t > cardinalities)
Construct from cardinalities.
Definition: DiscreteKey.h:53
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
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
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
insert
A insert(1, 2)=0
gtsam::operator&
DiscreteKeys operator&(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition: DiscreteKey.cpp:45
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::DiscreteKeys::operator&
DiscreteKeys & operator&(const DiscreteKeys &keys)
Add multiple keys (non-const!)
Definition: DiscreteKey.h:78


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:03