From 17e3955c0561b642c0b501db6f8d4ce1888c74e7 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Tue, 4 Jan 2022 13:15:08 -0500 Subject: [PATCH] Fix small bug with names not being passed if no parents --- gtsam/discrete/DiscreteConditional.cpp | 2 +- .../tests/testDiscreteConditional.cpp | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gtsam/discrete/DiscreteConditional.cpp b/gtsam/discrete/DiscreteConditional.cpp index b4f95780d..8ee93eb77 100644 --- a/gtsam/discrete/DiscreteConditional.cpp +++ b/gtsam/discrete/DiscreteConditional.cpp @@ -307,7 +307,7 @@ std::string DiscreteConditional::markdown(const KeyFormatter& keyFormatter, if (nrParents() == 0) { // We have no parents, call factor method. ss << ")*:\n" << std::endl; - ss << DecisionTreeFactor::markdown(keyFormatter); + ss << DecisionTreeFactor::markdown(keyFormatter, names); return ss.str(); } diff --git a/gtsam/discrete/tests/testDiscreteConditional.cpp b/gtsam/discrete/tests/testDiscreteConditional.cpp index b498b0541..6d2af3cff 100644 --- a/gtsam/discrete/tests/testDiscreteConditional.cpp +++ b/gtsam/discrete/tests/testDiscreteConditional.cpp @@ -135,6 +135,24 @@ TEST(DiscreteConditional, markdown_prior) { EXPECT(actual == expected); } +/* ************************************************************************* */ +// Check markdown representation looks as expected, no parents + names. +TEST(DiscreteConditional, markdown_prior_names) { + Symbol x1('x', 1); + DiscreteKey A(x1, 3); + DiscreteConditional conditional(A % "1/2/2"); + string expected = + " *P(x1)*:\n\n" + "|x1|value|\n" + "|:-:|:-:|\n" + "|A0|0.2|\n" + "|A1|0.4|\n" + "|A2|0.4|\n"; + DecisionTreeFactor::Names names{{x1, {"A0", "A1", "A2"}}}; + string actual = conditional.markdown(DefaultKeyFormatter, names); + EXPECT(actual == expected); +} + /* ************************************************************************* */ // Check markdown representation looks as expected, multivalued. TEST(DiscreteConditional, markdown_multivalued) { @@ -155,7 +173,7 @@ TEST(DiscreteConditional, markdown_multivalued) { } /* ************************************************************************* */ -// Check markdown representation looks as expected, two parents. +// Check markdown representation looks as expected, two parents + names. TEST(DiscreteConditional, markdown) { DiscreteKey A(2, 2), B(1, 2), C(0, 3); DiscreteConditional conditional(A, {B, C}, "0/1 1/3 1/1 3/1 0/1 1/0");