VariableIndex.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 
18 #include <iostream>
19 
21 
22 namespace gtsam {
23 
24 using namespace std;
25 
27  return index_.find(variable)->second;
28 }
29 
30 const FactorIndices& VariableIndex::at(Key variable) const {
31  KeyMap::const_iterator item = index_.find(variable);
32  if(item == index_.end())
33  throw std::invalid_argument("Requested non-existent variable '" +
34  DefaultKeyFormatter(variable) +
35  "' from VariableIndex");
36  else
37  return item->second;
38 }
39 
40 bool VariableIndex::empty(Key variable) const {
41  return (*this)[variable].empty();
42 }
43 
44 /* ************************************************************************* */
45 bool VariableIndex::equals(const VariableIndex& other, double tol) const {
46  return this->nEntries_ == other.nEntries_ && this->nFactors_ == other.nFactors_
47  && this->index_ == other.index_;
48 }
49 
50 /* ************************************************************************* */
51 void VariableIndex::print(const string& str, const KeyFormatter& keyFormatter) const {
52  cout << str;
53  cout << "nEntries = " << nEntries() << ", nFactors = " << nFactors() << "\n";
54  for(KeyMap::value_type key_factors: index_) {
55  cout << "var " << keyFormatter(key_factors.first) << ":";
56  for(const auto index: key_factors.second)
57  cout << " " << index;
58  cout << "\n";
59  }
60  cout.flush();
61 }
62 
63 /* ************************************************************************* */
64 void VariableIndex::outputMetisFormat(ostream& os) const {
65  os << size() << " " << nFactors() << "\n";
66  // run over variables, which will be hyper-edges.
67  for(KeyMap::value_type key_factors: index_) {
68  // every variable is a hyper-edge covering its factors
69  for(const auto index: key_factors.second)
70  os << (index+1) << " "; // base 1
71  os << "\n";
72  }
73  os << flush;
74 }
75 
76 /* ************************************************************************* */
77 void VariableIndex::augmentExistingFactor(const FactorIndex factorIndex, const KeySet & newKeys)
78 {
79  gttic(VariableIndex_augmentExistingFactor);
80 
81  for(const Key key: newKeys) {
82  index_[key].push_back(factorIndex);
83  ++nEntries_;
84  }
85 
86  gttoc(VariableIndex_augmentExistingFactor);
87 }
88 
89 }
gttoc
#define gttoc(label)
Definition: timing.h:327
gtsam::FastSet< Key >
gtsam::VariableIndex::operator[]
const FactorIndices & operator[](Key variable) const
Access a list of factors by variable without checking for existence.
Definition: VariableIndex.cpp:26
os
ofstream os("timeSchurFactors.csv")
gtsam::VariableIndex::outputMetisFormat
void outputMetisFormat(std::ostream &os) const
Definition: VariableIndex.cpp:64
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
gtsam::VariableIndex::augmentExistingFactor
void augmentExistingFactor(const FactorIndex factorIndex, const KeySet &newKeys)
Definition: VariableIndex.cpp:77
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::FactorIndex
std::uint64_t FactorIndex
Integer nonlinear factor index type.
Definition: types.h:100
gtsam::VariableIndex
Definition: VariableIndex.h:41
str
Definition: pytypes.h:1560
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: ABC.h:17
std
Definition: BFloat16.h:88
VariableIndex.h
gtsam::VariableIndex::at
const FactorIndices & at(Key variable) const
Access a list of factors by variable.
Definition: VariableIndex.cpp:30
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::VariableIndex::equals
bool equals(const VariableIndex &other, double tol=0.0) const
Test for equality (for unit tests and debug assertions).
Definition: VariableIndex.cpp:45
gtsam::VariableIndex::empty
bool empty(Key variable) const
Return true if no factors associated with a variable.
Definition: VariableIndex.cpp:40
gtsam::VariableIndex::print
void print(const std::string &str="VariableIndex: ", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print the variable index (for unit tests and debugging).
Definition: VariableIndex.cpp:51
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam.examples.ShonanAveragingCLI.str
str
Definition: ShonanAveragingCLI.py:115
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gttic
#define gttic(label)
Definition: timing.h:326
gtsam::FactorIndices
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:37


gtsam
Author(s):
autogenerated on Wed May 28 2025 03:08:41