Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of minor fixes #1132

Merged
merged 5 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gtsam/discrete/DiscreteLookupDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GTSAM_EXPORT DiscreteLookupTable : public DiscreteConditional {
* @brief Construct a new Discrete Lookup Table object
*
* @param nFrontals number of frontal variables
* @param keys a orted list of gtsam::Keys
* @param keys a sorted list of gtsam::Keys
* @param potentials the algebraic decision tree with lookup values
*/
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys& keys,
Expand Down
2 changes: 1 addition & 1 deletion gtsam/geometry/Pose3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Matrix6 Pose3::AdjointMap() const {
const Matrix3 R = R_.matrix();
Matrix3 A = skewSymmetric(t_.x(), t_.y(), t_.z()) * R;
Matrix6 adj;
adj << R, Z_3x3, A, R;
adj << R, Z_3x3, A, R; // Gives [R 0; A R]
return adj;
}

Expand Down
2 changes: 1 addition & 1 deletion gtsam/inference/BayesTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace gtsam {
return nodes_.empty();
}

/** return nodes */
/** Return nodes. Each node is a clique of variables obtained after elimination. */
const Nodes& nodes() const { return nodes_; }

/** Access node by variable */
Expand Down
1 change: 0 additions & 1 deletion gtsam/navigation/PreintegrationParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void PreintegrationParams::print(const string& s) const {
<< endl;
if (omegaCoriolis && use2ndOrderCoriolis)
cout << "Using 2nd-order Coriolis" << endl;
if (body_P_sensor) body_P_sensor->print(" ");
cout << "n_gravity = (" << n_gravity.transpose() << ")" << endl;
}

Expand Down
11 changes: 11 additions & 0 deletions gtsam/nonlinear/ISAM2.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ class GTSAM_EXPORT ISAM2 : public BayesTree<ISAM2Clique> {
const ISAM2UpdateParams& updateParams, const FastList<Key>& affectedKeys,
const KeySet& relinKeys);

/**
* @brief Perform an incremental update of the factor graph to return a new
* Bayes Tree with affected keys.
*
* @param updateParams Parameters for the ISAM2 update.
* @param relinKeys Keys of variables to relinearize.
* @param affectedKeys The set of keys which are affected in the update.
* @param affectedKeysSet [output] Affected and contaminated keys.
* @param orphans [output] List of orphanes cliques after elimination.
* @param result [output] The result of the incremental update step.
*/
void recalculateIncremental(const ISAM2UpdateParams& updateParams,
const KeySet& relinKeys,
const FastList<Key>& affectedKeys,
Expand Down
4 changes: 3 additions & 1 deletion gtsam/slam/BetweenFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ namespace gtsam {
/// @{

/// print with optional string
void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
void print(
const std::string& s = "",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
std::cout << s << "BetweenFactor("
<< keyFormatter(this->key1()) << ","
<< keyFormatter(this->key2()) << ")\n";
Expand Down
27 changes: 22 additions & 5 deletions python/gtsam/tests/test_GaussianFactorGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
def create_graph():
"""Create a basic linear factor graph for testing"""
graph = gtsam.GaussianFactorGraph()

x0 = X(0)
x1 = X(1)
x2 = X(2)

BETWEEN_NOISE = gtsam.noiseModel.Diagonal.Sigmas(np.ones(1))
PRIOR_NOISE = gtsam.noiseModel.Diagonal.Sigmas(np.ones(1))

graph.add(x1, np.eye(1), x0, -np.eye(1), np.ones(1), BETWEEN_NOISE)
graph.add(x2, np.eye(1), x1, -np.eye(1), 2*np.ones(1), BETWEEN_NOISE)
graph.add(x2, np.eye(1), x1, -np.eye(1), 2 * np.ones(1), BETWEEN_NOISE)
graph.add(x0, np.eye(1), np.zeros(1), PRIOR_NOISE)

return graph, (x0, x1, x2)


class TestGaussianFactorGraph(GtsamTestCase):
"""Tests for Gaussian Factor Graphs."""

def test_fg(self):
"""Test solving a linear factor graph"""
graph, X = create_graph()
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_convertNonlinear(self):
self.assertAlmostEqual(EXPECTEDM[0], m[0], delta=1e-8)
self.assertAlmostEqual(EXPECTEDM[1], m[1], delta=1e-8)
self.assertAlmostEqual(EXPECTEDM[2], m[2], delta=1e-8)

def test_linearMarginalization(self):
"""Marginalize a linear factor graph"""
graph, X = create_graph()
Expand All @@ -88,5 +88,22 @@ def test_linearMarginalization(self):
self.assertAlmostEqual(EXPECTEDM[1], m[1], delta=1e-8)
self.assertAlmostEqual(EXPECTEDM[2], m[2], delta=1e-8)

def test_ordering(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add more comments about what is happening and what the bug is you uncovered with this? Also maybe add output so I can help think about the cause, or if you know what the problem is, let us know :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue seems to be in the way the Debug configuration is handled in the wrapper. Release versions of this same test passes no problem but we get a segfault in the Debug version. Pretty confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output isn't helpful, but here it is:

python/gtsam/tests/test_GaussianFactorGraph.py Fatal Python error: Segmentation fault

Current thread 0x00007fa529fd2280 (most recent call first):
  File "/home/varun/borglab/gtsam/build/python/gtsam/tests/test_GaussianFactorGraph.py", line 103 in test_ordering
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/unittest/case.py", line 633 in _callTestMethod
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/unittest/case.py", line 676 in run
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/unittest/case.py", line 736 in __call__
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/unittest.py", line 321 in runtest
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 162 in pytest_runtest_call
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 255 in <lambda>
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 311 in from_call
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 254 in call_runtest_hook
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 215 in call_and_report
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 126 in runtestprotocol
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/runner.py", line 109 in pytest_runtest_protocol
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/main.py", line 348 in pytest_runtestloop
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/main.py", line 323 in _main
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/main.py", line 269 in wrap_session
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/main.py", line 316 in pytest_cmdline_main
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 84 in <lambda>
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/config/__init__.py", line 162 in main
  File "/home/varun/.pyenv/versions/3.8.11/lib/python3.8/site-packages/_pytest/config/__init__.py", line 185 in console_main
  File "/home/varun/.pyenv/versions/3.8.11/bin/pytest", line 8 in <module>
[1]    3008430 segmentation fault (core dumped)  pytest  -s

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting out this particular test section since it is time-consuming and out of scope for this PR.

"""Test ordering"""
gfg, keys = create_graph()
ordering = gtsam.Ordering()
for key in keys[::-1]:
ordering.push_back(key)

bn = gfg.eliminateSequential(ordering)
self.assertEqual(bn.size(), 3)

keyVector = gtsam.KeyVector()
keyVector.append(keys[2])
ordering = gtsam.Ordering.ColamdConstrainedLastGaussianFactorGraph(gfg, keyVector)
bn = gfg.eliminateSequential(ordering)
self.assertEqual(bn.size(), 3)


if __name__ == '__main__':
unittest.main()