Wrap VariableIndex.at(), .empty()

release/4.3a0
p-zach 2025-04-15 18:19:25 -04:00
parent 198efe23c7
commit 098704ac22
3 changed files with 25 additions and 12 deletions

View File

@ -23,6 +23,24 @@ namespace gtsam {
using namespace std;
const FactorIndices& operator[](Key variable) const {
KeyMap::const_iterator item = index_.find(variable);
}
const FactorIndices& at(Key variable) const {
KeyMap::const_iterator item = (*this)[variable];
if(item == index_.end())
throw std::invalid_argument("Requested non-existent variable '" +
DefaultKeyFormatter(variable) +
"' from VariableIndex");
else
return item->second;
}
bool empty(Key variable) const {
return (*this)[variable].empty();
}
/* ************************************************************************* */
bool VariableIndex::equals(const VariableIndex& other, double tol) const {
return this->nEntries_ == other.nEntries_ && this->nFactors_ == other.nFactors_

View File

@ -84,20 +84,12 @@ class GTSAM_EXPORT VariableIndex {
size_t nEntries() const { return nEntries_; }
/// Access a list of factors by variable
const FactorIndices& operator[](Key variable) const {
KeyMap::const_iterator item = index_.find(variable);
if(item == index_.end())
throw std::invalid_argument("Requested non-existent variable '" +
DefaultKeyFormatter(variable) +
"' from VariableIndex");
else
return item->second;
}
const FactorIndices& operator[](Key variable) const;
const FactorIndices& at(Key variable) const;
/// Return true if no factors associated with a variable
bool empty(Key variable) const {
return (*this)[variable].empty();
}
bool empty(Key variable) const;
/// @}
/// @name Testable

View File

@ -199,6 +199,9 @@ class VariableIndex {
VariableIndex(const T& factorGraph);
VariableIndex(const gtsam::VariableIndex& other);
const FactorIndices& at(Key variable) const;
bool empty(Key variable) const;
// Testable
bool equals(const gtsam::VariableIndex& other, double tol) const;
void print(string s = "VariableIndex: ",