inferenceExceptions.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 
20 
21 #include <sstream>
22 
23 namespace gtsam {
24 
26  const KeySet& keys, const KeyFormatter& key_formatter)
27  : keys_(keys.begin(), keys.end()), keyFormatter(key_formatter) {}
28 
29 const char* InconsistentEliminationRequested::what() const noexcept {
30  // Format keys for printing
31  std::stringstream sstr;
32  size_t nrKeysToDisplay = std::min(size_t(4), keys_.size());
33  for (size_t i = 0; i < nrKeysToDisplay; i++) {
34  sstr << keyFormatter(keys_.at(i));
35  if (i < nrKeysToDisplay - 1) {
36  sstr << ", ";
37  }
38  }
39  if (keys_.size() > nrKeysToDisplay) {
40  sstr << ", ... (total " << keys_.size() << " keys)";
41  }
42  sstr << ".";
43  std::string keys = sstr.str();
44 
45  std::string msg =
46  "An inference algorithm was called with inconsistent "
47  "arguments. "
48  "The\n"
49  "factor graph, ordering, or variable index were "
50  "inconsistent with "
51  "each\n"
52  "other, or a full elimination routine was called with "
53  "an ordering "
54  "that\n"
55  "does not include all of the variables.\n";
56  msg += ("Leftover keys after elimination: " + keys);
57  // `new` to allocate memory on heap instead of stack
58  return (new std::string(msg))->c_str();
59 }
60 } // namespace gtsam
gtsam::InconsistentEliminationRequested::InconsistentEliminationRequested
InconsistentEliminationRequested() noexcept
Definition: inferenceExceptions.h:36
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::InconsistentEliminationRequested::keys_
KeyVector keys_
Definition: inferenceExceptions.h:32
gtsam::FastSet< Key >
gtsam::InconsistentEliminationRequested::keyFormatter
const KeyFormatter & keyFormatter
Definition: inferenceExceptions.h:33
gtsam::InconsistentEliminationRequested::what
const char * what() const noexcept override
Definition: inferenceExceptions.cpp:29
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
inferenceExceptions.h
Exceptions that may be thrown by inference algorithms.
gtsam
traits
Definition: chartTesting.h:28
gtsam::key_formatter
Definition: Key.h:78
c_str
const char * c_str(Args &&...args)
Definition: internals.h:599
min
#define min(a, b)
Definition: datatypes.h:19
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind11.msg
msg
Definition: wrap/pybind11/pybind11/__init__.py:4


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:02:37