From caddc734c2053006dfd06463f2f70b20bc0b2181 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 10:51:38 -0400 Subject: [PATCH 01/12] fix printing tests --- .../hybrid/tests/testHybridGaussianFactor.cpp | 5 ++- .../tests/testHybridNonlinearFactorGraph.cpp | 32 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridGaussianFactor.cpp b/gtsam/hybrid/tests/testHybridGaussianFactor.cpp index 71aac8224b..05e05c79b7 100644 --- a/gtsam/hybrid/tests/testHybridGaussianFactor.cpp +++ b/gtsam/hybrid/tests/testHybridGaussianFactor.cpp @@ -104,13 +104,12 @@ TEST(HybridGaussianFactor, Keys) { } /* ************************************************************************* */ -TEST_DISABLED(HybridGaussianFactor, Printing) { +TEST(HybridGaussianFactor, Printing) { using namespace test_constructor; HybridGaussianFactor hybridFactor(m1, {f10, f11}); std::string expected = - R"(HybridGaussianFactor -Hybrid [x1 x2; 1]{ + R"(Hybrid [x1 x2; 1]{ Choice(1) 0 Leaf : A[x1] = [ diff --git a/gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp b/gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp index b5486c6cdb..bbf427ecb2 100644 --- a/gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp +++ b/gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp @@ -529,7 +529,7 @@ TEST(HybridNonlinearFactorGraph, Full_Elimination) { /**************************************************************************** * Test printing */ -TEST_DISABLED(HybridNonlinearFactorGraph, Printing) { +TEST(HybridNonlinearFactorGraph, Printing) { Switching self(3); auto linearizedFactorGraph = self.linearizedFactorGraph; @@ -549,7 +549,7 @@ Factor 0 GaussianFactor: A[x0] = [ - 10 + 10 ] b = [ -10 ] No noise model @@ -560,25 +560,25 @@ Hybrid [x0 x1; m0]{ Choice(m0) 0 Leaf : A[x0] = [ - -1 + -1 ] A[x1] = [ - 1 + 1 ] b = [ -1 ] No noise model -scalar: 0 +scalar: 0.918939 1 Leaf : A[x0] = [ - -1 + -1 ] A[x1] = [ - 1 + 1 ] b = [ -0 ] No noise model -scalar: 0 +scalar: 0.918939 } @@ -588,25 +588,25 @@ Hybrid [x1 x2; m1]{ Choice(m1) 0 Leaf : A[x1] = [ - -1 + -1 ] A[x2] = [ - 1 + 1 ] b = [ -1 ] No noise model -scalar: 0 +scalar: 0.918939 1 Leaf : A[x1] = [ - -1 + -1 ] A[x2] = [ - 1 + 1 ] b = [ -0 ] No noise model -scalar: 0 +scalar: 0.918939 } @@ -614,7 +614,7 @@ Factor 3 GaussianFactor: A[x1] = [ - 10 + 10 ] b = [ -10 ] No noise model @@ -623,7 +623,7 @@ Factor 4 GaussianFactor: A[x2] = [ - 10 + 10 ] b = [ -10 ] No noise model From 205eb18f471b21b936f3240a3ad291b8295e38eb Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 10:55:39 -0400 Subject: [PATCH 02/12] add serialization to HybridGaussianProductFactor --- gtsam/hybrid/HybridGaussianProductFactor.h | 10 ++++++++++ gtsam/hybrid/tests/testSerializationHybrid.cpp | 3 +++ 2 files changed, 13 insertions(+) diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index 508113e874..a06f244238 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -115,6 +115,16 @@ class GTSAM_EXPORT HybridGaussianProductFactor HybridGaussianProductFactor removeEmpty() const; ///@} + + private: +#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int /*version*/) { + ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + } +#endif }; // Testable traits diff --git a/gtsam/hybrid/tests/testSerializationHybrid.cpp b/gtsam/hybrid/tests/testSerializationHybrid.cpp index 8258d8615e..fd92e5cfbb 100644 --- a/gtsam/hybrid/tests/testSerializationHybrid.cpp +++ b/gtsam/hybrid/tests/testSerializationHybrid.cpp @@ -59,6 +59,9 @@ BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Leaf, BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Choice, "gtsam_HybridGaussianFactor_Factors_Choice"); +BOOST_CLASS_EXPORT_GUID(GaussianFactorGraphValuePair, + "gtsam_GaussianFactorGraphValuePair"); + BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional, "gtsam_HybridGaussianConditional"); BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals, From 4f7473532878f852c96a5efff88cbb3021bf459f Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 11:11:05 -0400 Subject: [PATCH 03/12] checking if print is the problem --- gtsam/hybrid/HybridGaussianProductFactor.cpp | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/gtsam/hybrid/HybridGaussianProductFactor.cpp b/gtsam/hybrid/HybridGaussianProductFactor.cpp index f7b5994f0f..92888fbc8b 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.cpp +++ b/gtsam/hybrid/HybridGaussianProductFactor.cpp @@ -70,18 +70,19 @@ HybridGaussianProductFactor& HybridGaussianProductFactor::operator+=( /* *******************************************************************************/ void HybridGaussianProductFactor::print(const std::string& s, const KeyFormatter& formatter) const { - KeySet keys; - auto printer = [&](const Y& y) { - if (keys.empty()) keys = y.first.keys(); - return "Graph of size " + std::to_string(y.first.size()) + - ", scalar sum: " + std::to_string(y.second); - }; - Base::print(s, formatter, printer); - if (!keys.empty()) { - std::cout << s << " Keys:"; - for (auto&& key : keys) std::cout << " " << formatter(key); - std::cout << "." << std::endl; - } + // KeySet keys; + // auto printer = [&](const Y& y) { + // if (keys.empty()) keys = y.first.keys(); + // return "Graph of size " + std::to_string(y.first.size()) + + // ", scalar sum: " + std::to_string(y.second); + // }; + // Base::print(s, formatter, printer); + // if (!keys.empty()) { + // std::cout << s << " Keys:"; + // for (auto&& key : keys) std::cout << " " << formatter(key); + // std::cout << "." << std::endl; + // } + std::cout << "HybridGaussianProductFactor" << std::endl; } /* *******************************************************************************/ From 8a650b6a4e4f0be462932766f0cec9c7971b0e4f Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 11:41:23 -0400 Subject: [PATCH 04/12] undo print and remove extra includes --- gtsam/hybrid/HybridGaussianConditional.cpp | 1 - gtsam/hybrid/HybridGaussianConditional.h | 1 - gtsam/hybrid/HybridGaussianProductFactor.cpp | 25 ++++++++++---------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gtsam/hybrid/HybridGaussianConditional.cpp b/gtsam/hybrid/HybridGaussianConditional.cpp index 2a0b5a875b..58724163ec 100644 --- a/gtsam/hybrid/HybridGaussianConditional.cpp +++ b/gtsam/hybrid/HybridGaussianConditional.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/gtsam/hybrid/HybridGaussianConditional.h b/gtsam/hybrid/HybridGaussianConditional.h index 75138b0dc2..4cc3d31960 100644 --- a/gtsam/hybrid/HybridGaussianConditional.h +++ b/gtsam/hybrid/HybridGaussianConditional.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/gtsam/hybrid/HybridGaussianProductFactor.cpp b/gtsam/hybrid/HybridGaussianProductFactor.cpp index 92888fbc8b..f7b5994f0f 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.cpp +++ b/gtsam/hybrid/HybridGaussianProductFactor.cpp @@ -70,19 +70,18 @@ HybridGaussianProductFactor& HybridGaussianProductFactor::operator+=( /* *******************************************************************************/ void HybridGaussianProductFactor::print(const std::string& s, const KeyFormatter& formatter) const { - // KeySet keys; - // auto printer = [&](const Y& y) { - // if (keys.empty()) keys = y.first.keys(); - // return "Graph of size " + std::to_string(y.first.size()) + - // ", scalar sum: " + std::to_string(y.second); - // }; - // Base::print(s, formatter, printer); - // if (!keys.empty()) { - // std::cout << s << " Keys:"; - // for (auto&& key : keys) std::cout << " " << formatter(key); - // std::cout << "." << std::endl; - // } - std::cout << "HybridGaussianProductFactor" << std::endl; + KeySet keys; + auto printer = [&](const Y& y) { + if (keys.empty()) keys = y.first.keys(); + return "Graph of size " + std::to_string(y.first.size()) + + ", scalar sum: " + std::to_string(y.second); + }; + Base::print(s, formatter, printer); + if (!keys.empty()) { + std::cout << s << " Keys:"; + for (auto&& key : keys) std::cout << " " << formatter(key); + std::cout << "." << std::endl; + } } /* *******************************************************************************/ From e87d1fb1de0093dcdcdba0657cfa851bef9e412a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 11:41:31 -0400 Subject: [PATCH 05/12] comment out serialization --- .../hybrid/tests/testSerializationHybrid.cpp | 212 +++++++++--------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/gtsam/hybrid/tests/testSerializationHybrid.cpp b/gtsam/hybrid/tests/testSerializationHybrid.cpp index fd92e5cfbb..bb1a492feb 100644 --- a/gtsam/hybrid/tests/testSerializationHybrid.cpp +++ b/gtsam/hybrid/tests/testSerializationHybrid.cpp @@ -39,112 +39,112 @@ using symbol_shorthand::Z; using namespace serializationTestHelpers; -BOOST_CLASS_EXPORT_GUID(Factor, "gtsam_Factor"); -BOOST_CLASS_EXPORT_GUID(HybridFactor, "gtsam_HybridFactor"); -BOOST_CLASS_EXPORT_GUID(JacobianFactor, "gtsam_JacobianFactor"); -BOOST_CLASS_EXPORT_GUID(GaussianConditional, "gtsam_GaussianConditional"); -BOOST_CLASS_EXPORT_GUID(DiscreteConditional, "gtsam_DiscreteConditional"); - -BOOST_CLASS_EXPORT_GUID(DecisionTreeFactor, "gtsam_DecisionTreeFactor"); -using ADT = AlgebraicDecisionTree; -BOOST_CLASS_EXPORT_GUID(ADT, "gtsam_AlgebraicDecisionTree"); -BOOST_CLASS_EXPORT_GUID(ADT::Leaf, "gtsam_AlgebraicDecisionTree_Leaf"); -BOOST_CLASS_EXPORT_GUID(ADT::Choice, "gtsam_AlgebraicDecisionTree_Choice") - -BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor, "gtsam_HybridGaussianFactor"); -BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs, - "gtsam_HybridGaussianFactor_Factors"); -BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Leaf, - "gtsam_HybridGaussianFactor_Factors_Leaf"); -BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Choice, - "gtsam_HybridGaussianFactor_Factors_Choice"); - -BOOST_CLASS_EXPORT_GUID(GaussianFactorGraphValuePair, - "gtsam_GaussianFactorGraphValuePair"); - -BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional, - "gtsam_HybridGaussianConditional"); -BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals, - "gtsam_HybridGaussianConditional_Conditionals"); -BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Leaf, - "gtsam_HybridGaussianConditional_Conditionals_Leaf"); -BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Choice, - "gtsam_HybridGaussianConditional_Conditionals_Choice"); -// Needed since GaussianConditional::FromMeanAndStddev uses it -BOOST_CLASS_EXPORT_GUID(noiseModel::Isotropic, "gtsam_noiseModel_Isotropic"); - -BOOST_CLASS_EXPORT_GUID(HybridBayesNet, "gtsam_HybridBayesNet"); - -/* ****************************************************************************/ -// Test HybridGaussianFactor serialization. -TEST(HybridSerialization, HybridGaussianFactor) { - DiscreteKey discreteKey{M(0), 2}; - - auto A = Matrix::Zero(2, 1); - auto b0 = Matrix::Zero(2, 1); - auto b1 = Matrix::Ones(2, 1); - auto f0 = std::make_shared(X(0), A, b0); - auto f1 = std::make_shared(X(0), A, b1); - std::vector factors{f0, f1}; - - const HybridGaussianFactor factor(discreteKey, factors); - - EXPECT(equalsObj(factor)); - EXPECT(equalsXML(factor)); - EXPECT(equalsBinary(factor)); -} - -/* ****************************************************************************/ -// Test HybridConditional serialization. -TEST(HybridSerialization, HybridConditional) { - const DiscreteKey mode(M(0), 2); - Matrix1 I = Matrix1::Identity(); - const auto conditional = std::make_shared( - GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); - const HybridConditional hc(conditional); - - EXPECT(equalsObj(hc)); - EXPECT(equalsXML(hc)); - EXPECT(equalsBinary(hc)); -} - -/* ****************************************************************************/ -// Test HybridGaussianConditional serialization. -TEST(HybridSerialization, HybridGaussianConditional) { - const DiscreteKey mode(M(0), 2); - Matrix1 I = Matrix1::Identity(); - const auto conditional0 = std::make_shared( - GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); - const auto conditional1 = std::make_shared( - GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 3)); - const HybridGaussianConditional gm(mode, {conditional0, conditional1}); - - EXPECT(equalsObj(gm)); - EXPECT(equalsXML(gm)); - EXPECT(equalsBinary(gm)); -} - -/* ****************************************************************************/ -// Test HybridBayesNet serialization. -TEST(HybridSerialization, HybridBayesNet) { - Switching s(2); - HybridBayesNet hbn = *(s.linearizedFactorGraph.eliminateSequential()); - - EXPECT(equalsObj(hbn)); - EXPECT(equalsXML(hbn)); - EXPECT(equalsBinary(hbn)); -} - -/* ****************************************************************************/ -// Test HybridBayesTree serialization. -TEST(HybridSerialization, HybridBayesTree) { - Switching s(2); - HybridBayesTree hbt = *(s.linearizedFactorGraph.eliminateMultifrontal()); - - EXPECT(equalsObj(hbt)); - EXPECT(equalsXML(hbt)); - EXPECT(equalsBinary(hbt)); -} +// BOOST_CLASS_EXPORT_GUID(Factor, "gtsam_Factor"); +// BOOST_CLASS_EXPORT_GUID(HybridFactor, "gtsam_HybridFactor"); +// BOOST_CLASS_EXPORT_GUID(JacobianFactor, "gtsam_JacobianFactor"); +// BOOST_CLASS_EXPORT_GUID(GaussianConditional, "gtsam_GaussianConditional"); +// BOOST_CLASS_EXPORT_GUID(DiscreteConditional, "gtsam_DiscreteConditional"); + +// BOOST_CLASS_EXPORT_GUID(DecisionTreeFactor, "gtsam_DecisionTreeFactor"); +// using ADT = AlgebraicDecisionTree; +// BOOST_CLASS_EXPORT_GUID(ADT, "gtsam_AlgebraicDecisionTree"); +// BOOST_CLASS_EXPORT_GUID(ADT::Leaf, "gtsam_AlgebraicDecisionTree_Leaf"); +// BOOST_CLASS_EXPORT_GUID(ADT::Choice, "gtsam_AlgebraicDecisionTree_Choice") + +// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor, "gtsam_HybridGaussianFactor"); +// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs, +// "gtsam_HybridGaussianFactor_Factors"); +// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Leaf, +// "gtsam_HybridGaussianFactor_Factors_Leaf"); +// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Choice, +// "gtsam_HybridGaussianFactor_Factors_Choice"); + +// BOOST_CLASS_EXPORT_GUID(GaussianFactorGraphValuePair, +// "gtsam_GaussianFactorGraphValuePair"); + +// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional, +// "gtsam_HybridGaussianConditional"); +// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals, +// "gtsam_HybridGaussianConditional_Conditionals"); +// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Leaf, +// "gtsam_HybridGaussianConditional_Conditionals_Leaf"); +// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Choice, +// "gtsam_HybridGaussianConditional_Conditionals_Choice"); +// // Needed since GaussianConditional::FromMeanAndStddev uses it +// BOOST_CLASS_EXPORT_GUID(noiseModel::Isotropic, "gtsam_noiseModel_Isotropic"); + +// BOOST_CLASS_EXPORT_GUID(HybridBayesNet, "gtsam_HybridBayesNet"); + +// /* ****************************************************************************/ +// // Test HybridGaussianFactor serialization. +// TEST(HybridSerialization, HybridGaussianFactor) { +// DiscreteKey discreteKey{M(0), 2}; + +// auto A = Matrix::Zero(2, 1); +// auto b0 = Matrix::Zero(2, 1); +// auto b1 = Matrix::Ones(2, 1); +// auto f0 = std::make_shared(X(0), A, b0); +// auto f1 = std::make_shared(X(0), A, b1); +// std::vector factors{f0, f1}; + +// const HybridGaussianFactor factor(discreteKey, factors); + +// EXPECT(equalsObj(factor)); +// EXPECT(equalsXML(factor)); +// EXPECT(equalsBinary(factor)); +// } + +// /* ****************************************************************************/ +// // Test HybridConditional serialization. +// TEST(HybridSerialization, HybridConditional) { +// const DiscreteKey mode(M(0), 2); +// Matrix1 I = Matrix1::Identity(); +// const auto conditional = std::make_shared( +// GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); +// const HybridConditional hc(conditional); + +// EXPECT(equalsObj(hc)); +// EXPECT(equalsXML(hc)); +// EXPECT(equalsBinary(hc)); +// } + +// /* ****************************************************************************/ +// // Test HybridGaussianConditional serialization. +// TEST(HybridSerialization, HybridGaussianConditional) { +// const DiscreteKey mode(M(0), 2); +// Matrix1 I = Matrix1::Identity(); +// const auto conditional0 = std::make_shared( +// GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); +// const auto conditional1 = std::make_shared( +// GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 3)); +// const HybridGaussianConditional gm(mode, {conditional0, conditional1}); + +// EXPECT(equalsObj(gm)); +// EXPECT(equalsXML(gm)); +// EXPECT(equalsBinary(gm)); +// } + +// /* ****************************************************************************/ +// // Test HybridBayesNet serialization. +// TEST(HybridSerialization, HybridBayesNet) { +// Switching s(2); +// HybridBayesNet hbn = *(s.linearizedFactorGraph.eliminateSequential()); + +// EXPECT(equalsObj(hbn)); +// EXPECT(equalsXML(hbn)); +// EXPECT(equalsBinary(hbn)); +// } + +// /* ****************************************************************************/ +// // Test HybridBayesTree serialization. +// TEST(HybridSerialization, HybridBayesTree) { +// Switching s(2); +// HybridBayesTree hbt = *(s.linearizedFactorGraph.eliminateMultifrontal()); + +// EXPECT(equalsObj(hbt)); +// EXPECT(equalsXML(hbt)); +// EXPECT(equalsBinary(hbt)); +// } /* ************************************************************************* */ int main() { From 99a39e6568826739aa7d9185694ffe15f7d74433 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 12:04:04 -0400 Subject: [PATCH 06/12] undo test change --- .../hybrid/tests/testSerializationHybrid.cpp | 214 +++++++++--------- 1 file changed, 108 insertions(+), 106 deletions(-) diff --git a/gtsam/hybrid/tests/testSerializationHybrid.cpp b/gtsam/hybrid/tests/testSerializationHybrid.cpp index bb1a492feb..5b06312ba4 100644 --- a/gtsam/hybrid/tests/testSerializationHybrid.cpp +++ b/gtsam/hybrid/tests/testSerializationHybrid.cpp @@ -39,112 +39,114 @@ using symbol_shorthand::Z; using namespace serializationTestHelpers; -// BOOST_CLASS_EXPORT_GUID(Factor, "gtsam_Factor"); -// BOOST_CLASS_EXPORT_GUID(HybridFactor, "gtsam_HybridFactor"); -// BOOST_CLASS_EXPORT_GUID(JacobianFactor, "gtsam_JacobianFactor"); -// BOOST_CLASS_EXPORT_GUID(GaussianConditional, "gtsam_GaussianConditional"); -// BOOST_CLASS_EXPORT_GUID(DiscreteConditional, "gtsam_DiscreteConditional"); - -// BOOST_CLASS_EXPORT_GUID(DecisionTreeFactor, "gtsam_DecisionTreeFactor"); -// using ADT = AlgebraicDecisionTree; -// BOOST_CLASS_EXPORT_GUID(ADT, "gtsam_AlgebraicDecisionTree"); -// BOOST_CLASS_EXPORT_GUID(ADT::Leaf, "gtsam_AlgebraicDecisionTree_Leaf"); -// BOOST_CLASS_EXPORT_GUID(ADT::Choice, "gtsam_AlgebraicDecisionTree_Choice") - -// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor, "gtsam_HybridGaussianFactor"); -// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs, -// "gtsam_HybridGaussianFactor_Factors"); -// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Leaf, -// "gtsam_HybridGaussianFactor_Factors_Leaf"); -// BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Choice, -// "gtsam_HybridGaussianFactor_Factors_Choice"); - -// BOOST_CLASS_EXPORT_GUID(GaussianFactorGraphValuePair, -// "gtsam_GaussianFactorGraphValuePair"); - -// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional, -// "gtsam_HybridGaussianConditional"); -// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals, -// "gtsam_HybridGaussianConditional_Conditionals"); -// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Leaf, -// "gtsam_HybridGaussianConditional_Conditionals_Leaf"); -// BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Choice, -// "gtsam_HybridGaussianConditional_Conditionals_Choice"); -// // Needed since GaussianConditional::FromMeanAndStddev uses it -// BOOST_CLASS_EXPORT_GUID(noiseModel::Isotropic, "gtsam_noiseModel_Isotropic"); - -// BOOST_CLASS_EXPORT_GUID(HybridBayesNet, "gtsam_HybridBayesNet"); - -// /* ****************************************************************************/ -// // Test HybridGaussianFactor serialization. -// TEST(HybridSerialization, HybridGaussianFactor) { -// DiscreteKey discreteKey{M(0), 2}; - -// auto A = Matrix::Zero(2, 1); -// auto b0 = Matrix::Zero(2, 1); -// auto b1 = Matrix::Ones(2, 1); -// auto f0 = std::make_shared(X(0), A, b0); -// auto f1 = std::make_shared(X(0), A, b1); -// std::vector factors{f0, f1}; - -// const HybridGaussianFactor factor(discreteKey, factors); - -// EXPECT(equalsObj(factor)); -// EXPECT(equalsXML(factor)); -// EXPECT(equalsBinary(factor)); -// } - -// /* ****************************************************************************/ -// // Test HybridConditional serialization. -// TEST(HybridSerialization, HybridConditional) { -// const DiscreteKey mode(M(0), 2); -// Matrix1 I = Matrix1::Identity(); -// const auto conditional = std::make_shared( -// GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); -// const HybridConditional hc(conditional); - -// EXPECT(equalsObj(hc)); -// EXPECT(equalsXML(hc)); -// EXPECT(equalsBinary(hc)); -// } - -// /* ****************************************************************************/ -// // Test HybridGaussianConditional serialization. -// TEST(HybridSerialization, HybridGaussianConditional) { -// const DiscreteKey mode(M(0), 2); -// Matrix1 I = Matrix1::Identity(); -// const auto conditional0 = std::make_shared( -// GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); -// const auto conditional1 = std::make_shared( -// GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 3)); -// const HybridGaussianConditional gm(mode, {conditional0, conditional1}); - -// EXPECT(equalsObj(gm)); -// EXPECT(equalsXML(gm)); -// EXPECT(equalsBinary(gm)); -// } - -// /* ****************************************************************************/ -// // Test HybridBayesNet serialization. -// TEST(HybridSerialization, HybridBayesNet) { -// Switching s(2); -// HybridBayesNet hbn = *(s.linearizedFactorGraph.eliminateSequential()); - -// EXPECT(equalsObj(hbn)); -// EXPECT(equalsXML(hbn)); -// EXPECT(equalsBinary(hbn)); -// } - -// /* ****************************************************************************/ -// // Test HybridBayesTree serialization. -// TEST(HybridSerialization, HybridBayesTree) { -// Switching s(2); -// HybridBayesTree hbt = *(s.linearizedFactorGraph.eliminateMultifrontal()); - -// EXPECT(equalsObj(hbt)); -// EXPECT(equalsXML(hbt)); -// EXPECT(equalsBinary(hbt)); -// } +BOOST_CLASS_EXPORT_GUID(Factor, "gtsam_Factor"); +BOOST_CLASS_EXPORT_GUID(HybridFactor, "gtsam_HybridFactor"); +BOOST_CLASS_EXPORT_GUID(JacobianFactor, "gtsam_JacobianFactor"); +BOOST_CLASS_EXPORT_GUID(GaussianConditional, "gtsam_GaussianConditional"); +BOOST_CLASS_EXPORT_GUID(DiscreteConditional, "gtsam_DiscreteConditional"); + +BOOST_CLASS_EXPORT_GUID(DecisionTreeFactor, "gtsam_DecisionTreeFactor"); +using ADT = AlgebraicDecisionTree; +BOOST_CLASS_EXPORT_GUID(ADT, "gtsam_AlgebraicDecisionTree"); +BOOST_CLASS_EXPORT_GUID(ADT::Leaf, "gtsam_AlgebraicDecisionTree_Leaf"); +BOOST_CLASS_EXPORT_GUID(ADT::Choice, "gtsam_AlgebraicDecisionTree_Choice") + +BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor, "gtsam_HybridGaussianFactor"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs, + "gtsam_HybridGaussianFactor_Factors"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Leaf, + "gtsam_HybridGaussianFactor_Factors_Leaf"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianFactor::FactorValuePairs::Choice, + "gtsam_HybridGaussianFactor_Factors_Choice"); + +BOOST_CLASS_EXPORT_GUID(GaussianFactorGraphValuePair, + "gtsam_GaussianFactorGraphValuePair"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianProductFactor, + "gtsam_HybridGaussianProductFactor"); + +BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional, + "gtsam_HybridGaussianConditional"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals, + "gtsam_HybridGaussianConditional_Conditionals"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Leaf, + "gtsam_HybridGaussianConditional_Conditionals_Leaf"); +BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals::Choice, + "gtsam_HybridGaussianConditional_Conditionals_Choice"); +// Needed since GaussianConditional::FromMeanAndStddev uses it +BOOST_CLASS_EXPORT_GUID(noiseModel::Isotropic, "gtsam_noiseModel_Isotropic"); + +BOOST_CLASS_EXPORT_GUID(HybridBayesNet, "gtsam_HybridBayesNet"); + +/* ****************************************************************************/ +// Test HybridGaussianFactor serialization. +TEST(HybridSerialization, HybridGaussianFactor) { + DiscreteKey discreteKey{M(0), 2}; + + auto A = Matrix::Zero(2, 1); + auto b0 = Matrix::Zero(2, 1); + auto b1 = Matrix::Ones(2, 1); + auto f0 = std::make_shared(X(0), A, b0); + auto f1 = std::make_shared(X(0), A, b1); + std::vector factors{f0, f1}; + + const HybridGaussianFactor factor(discreteKey, factors); + + EXPECT(equalsObj(factor)); + EXPECT(equalsXML(factor)); + EXPECT(equalsBinary(factor)); +} + +/* ****************************************************************************/ +// Test HybridConditional serialization. +TEST(HybridSerialization, HybridConditional) { + const DiscreteKey mode(M(0), 2); + Matrix1 I = Matrix1::Identity(); + const auto conditional = std::make_shared( + GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); + const HybridConditional hc(conditional); + + EXPECT(equalsObj(hc)); + EXPECT(equalsXML(hc)); + EXPECT(equalsBinary(hc)); +} + +/* ****************************************************************************/ +// Test HybridGaussianConditional serialization. +TEST(HybridSerialization, HybridGaussianConditional) { + const DiscreteKey mode(M(0), 2); + Matrix1 I = Matrix1::Identity(); + const auto conditional0 = std::make_shared( + GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 0.5)); + const auto conditional1 = std::make_shared( + GaussianConditional::FromMeanAndStddev(Z(0), I, X(0), Vector1(0), 3)); + const HybridGaussianConditional gm(mode, {conditional0, conditional1}); + + EXPECT(equalsObj(gm)); + EXPECT(equalsXML(gm)); + EXPECT(equalsBinary(gm)); +} + +/* ****************************************************************************/ +// Test HybridBayesNet serialization. +TEST(HybridSerialization, HybridBayesNet) { + Switching s(2); + HybridBayesNet hbn = *(s.linearizedFactorGraph.eliminateSequential()); + + EXPECT(equalsObj(hbn)); + EXPECT(equalsXML(hbn)); + EXPECT(equalsBinary(hbn)); +} + +/* ****************************************************************************/ +// Test HybridBayesTree serialization. +TEST(HybridSerialization, HybridBayesTree) { + Switching s(2); + HybridBayesTree hbt = *(s.linearizedFactorGraph.eliminateMultifrontal()); + + EXPECT(equalsObj(hbt)); + EXPECT(equalsXML(hbt)); + EXPECT(equalsBinary(hbt)); +} /* ************************************************************************* */ int main() { From 752e10fc21657a8dec54edfb1937a52f2411454d Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 12:39:03 -0400 Subject: [PATCH 07/12] delete constructor from string to fix issue --- gtsam/hybrid/HybridGaussianProductFactor.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index a06f244238..c94a04a2a4 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -55,6 +55,11 @@ class GTSAM_EXPORT HybridGaussianProductFactor */ HybridGaussianProductFactor(Base&& tree) : Base(std::move(tree)) {} + /// Deleted constructor since we don't have istream operator for + /// GaussianFactorGraphValuePair + HybridGaussianProductFactor(const std::vector& labelCs, + const std::string& table) = delete; + ///@} /// @name Operators From 1ac8a6e2e0ab8b490d57fd8edba2b460f0f635ec Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 12:57:03 -0400 Subject: [PATCH 08/12] fix vector type --- gtsam/hybrid/HybridGaussianProductFactor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index c94a04a2a4..17d9238dd7 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -57,7 +57,7 @@ class GTSAM_EXPORT HybridGaussianProductFactor /// Deleted constructor since we don't have istream operator for /// GaussianFactorGraphValuePair - HybridGaussianProductFactor(const std::vector& labelCs, + HybridGaussianProductFactor(const std::vector& labelCs, const std::string& table) = delete; ///@} From f4bf280047b352bf49ae939f8195f6aca65eebc4 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 13:08:42 -0400 Subject: [PATCH 09/12] implement constructor --- gtsam/hybrid/HybridGaussianProductFactor.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index 17d9238dd7..ab15fee303 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -58,7 +58,10 @@ class GTSAM_EXPORT HybridGaussianProductFactor /// Deleted constructor since we don't have istream operator for /// GaussianFactorGraphValuePair HybridGaussianProductFactor(const std::vector& labelCs, - const std::string& table) = delete; + const std::string& table) { + throw std::runtime_error( + "HybridGaussianProductFactor: No way to construct."); + } ///@} From 55dc3f5372857f349db00e7581dadaf764fb35fc Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 13:19:41 -0400 Subject: [PATCH 10/12] experiment with removing the constructor --- gtsam/discrete/DecisionTree-inl.h | 26 +++++++++++----------- gtsam/discrete/DecisionTree.h | 4 ++-- gtsam/discrete/tests/testDecisionTree.cpp | 14 ++++++------ gtsam/hybrid/HybridGaussianProductFactor.h | 8 ------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/gtsam/discrete/DecisionTree-inl.h b/gtsam/discrete/DecisionTree-inl.h index 27e98fcdec..29c36d27a5 100644 --- a/gtsam/discrete/DecisionTree-inl.h +++ b/gtsam/discrete/DecisionTree-inl.h @@ -523,19 +523,19 @@ namespace gtsam { root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); } - /****************************************************************************/ - template - DecisionTree::DecisionTree(const std::vector& labelCs, - const std::string& table) { - // Convert std::string to values of type Y - std::vector ys; - std::istringstream iss(table); - copy(std::istream_iterator(iss), std::istream_iterator(), - back_inserter(ys)); - - // now call recursive Create - root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); - } + // /****************************************************************************/ + // template + // DecisionTree::DecisionTree(const std::vector& labelCs, + // const std::string& table) { + // // Convert std::string to values of type Y + // std::vector ys; + // std::istringstream iss(table); + // copy(std::istream_iterator(iss), std::istream_iterator(), + // back_inserter(ys)); + + // // now call recursive Create + // root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); + // } /****************************************************************************/ template diff --git a/gtsam/discrete/DecisionTree.h b/gtsam/discrete/DecisionTree.h index 6d6179a7e6..a02fa9d385 100644 --- a/gtsam/discrete/DecisionTree.h +++ b/gtsam/discrete/DecisionTree.h @@ -205,8 +205,8 @@ namespace gtsam { /** Create from keys and a corresponding vector of values */ DecisionTree(const std::vector& labelCs, const std::vector& ys); - /** Create from keys and string table */ - DecisionTree(const std::vector& labelCs, const std::string& table); + // /** Create from keys and string table */ + // DecisionTree(const std::vector& labelCs, const std::string& table); /** Create DecisionTree from others */ template diff --git a/gtsam/discrete/tests/testDecisionTree.cpp b/gtsam/discrete/tests/testDecisionTree.cpp index c625e1ba63..2cc8d8441c 100644 --- a/gtsam/discrete/tests/testDecisionTree.cpp +++ b/gtsam/discrete/tests/testDecisionTree.cpp @@ -333,17 +333,17 @@ TEST(DecisionTree, Compose) { // Create from string vector keys{DT::LabelC(A, 2), DT::LabelC(B, 2)}; - DT f2(keys, "0 2 1 3"); + DT f2(keys, {0, 2, 1, 3}); EXPECT(assert_equal(f2, f1, 1e-9)); // Put this AB tree together with another one - DT f3(keys, "4 6 5 7"); + DT f3(keys, {4, 6, 5, 7}); DT f4(C, f1, f3); DOT(f4); // a bigger tree keys.push_back(DT::LabelC(C, 2)); - DT f5(keys, "0 4 2 6 1 5 3 7"); + DT f5(keys, {0, 4, 2, 6, 1, 5, 3, 7}); EXPECT(assert_equal(f5, f4, 1e-9)); DOT(f5); } @@ -508,7 +508,7 @@ TEST(DecisionTree, threshold) { // Create three level tree const vector keys{DT::LabelC("C", 2), DT::LabelC("B", 2), DT::LabelC("A", 2)}; - DT tree(keys, "0 1 2 3 4 5 6 7"); + DT tree(keys, {0, 1, 2, 3, 4, 5, 6, 7}); // Check number of leaves equal to zero auto count = [](const int& value, int count) { @@ -536,10 +536,10 @@ TEST(DecisionTree, ApplyWithAssignment) { // Create three level tree const vector keys{DT::LabelC("C", 2), DT::LabelC("B", 2), DT::LabelC("A", 2)}; - DT tree(keys, "1 2 3 4 5 6 7 8"); + DT tree(keys, {1, 2, 3, 4, 5, 6, 7, 8}); DecisionTree probTree( - keys, "0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08"); + keys, {0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08}); double threshold = 0.045; // We test pruning one tree by indexing into another. @@ -553,7 +553,7 @@ TEST(DecisionTree, ApplyWithAssignment) { }; DT prunedTree = tree.apply(pruner); - DT expectedTree(keys, "0 0 0 0 5 6 7 8"); + DT expectedTree(keys, {0, 0, 0, 0, 5, 6, 7, 8}); EXPECT(assert_equal(expectedTree, prunedTree)); size_t count = 0; diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index ab15fee303..a06f244238 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -55,14 +55,6 @@ class GTSAM_EXPORT HybridGaussianProductFactor */ HybridGaussianProductFactor(Base&& tree) : Base(std::move(tree)) {} - /// Deleted constructor since we don't have istream operator for - /// GaussianFactorGraphValuePair - HybridGaussianProductFactor(const std::vector& labelCs, - const std::string& table) { - throw std::runtime_error( - "HybridGaussianProductFactor: No way to construct."); - } - ///@} /// @name Operators From 4d707e7cdd83b8c959c64c2e300ab28646ca1473 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 13:37:55 -0400 Subject: [PATCH 11/12] Revert "experiment with removing the constructor" This reverts commit 55dc3f5372857f349db00e7581dadaf764fb35fc. --- gtsam/discrete/DecisionTree-inl.h | 26 +++++++++++----------- gtsam/discrete/DecisionTree.h | 4 ++-- gtsam/discrete/tests/testDecisionTree.cpp | 14 ++++++------ gtsam/hybrid/HybridGaussianProductFactor.h | 8 +++++++ 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/gtsam/discrete/DecisionTree-inl.h b/gtsam/discrete/DecisionTree-inl.h index 29c36d27a5..27e98fcdec 100644 --- a/gtsam/discrete/DecisionTree-inl.h +++ b/gtsam/discrete/DecisionTree-inl.h @@ -523,19 +523,19 @@ namespace gtsam { root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); } - // /****************************************************************************/ - // template - // DecisionTree::DecisionTree(const std::vector& labelCs, - // const std::string& table) { - // // Convert std::string to values of type Y - // std::vector ys; - // std::istringstream iss(table); - // copy(std::istream_iterator(iss), std::istream_iterator(), - // back_inserter(ys)); - - // // now call recursive Create - // root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); - // } + /****************************************************************************/ + template + DecisionTree::DecisionTree(const std::vector& labelCs, + const std::string& table) { + // Convert std::string to values of type Y + std::vector ys; + std::istringstream iss(table); + copy(std::istream_iterator(iss), std::istream_iterator(), + back_inserter(ys)); + + // now call recursive Create + root_ = create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); + } /****************************************************************************/ template diff --git a/gtsam/discrete/DecisionTree.h b/gtsam/discrete/DecisionTree.h index a02fa9d385..6d6179a7e6 100644 --- a/gtsam/discrete/DecisionTree.h +++ b/gtsam/discrete/DecisionTree.h @@ -205,8 +205,8 @@ namespace gtsam { /** Create from keys and a corresponding vector of values */ DecisionTree(const std::vector& labelCs, const std::vector& ys); - // /** Create from keys and string table */ - // DecisionTree(const std::vector& labelCs, const std::string& table); + /** Create from keys and string table */ + DecisionTree(const std::vector& labelCs, const std::string& table); /** Create DecisionTree from others */ template diff --git a/gtsam/discrete/tests/testDecisionTree.cpp b/gtsam/discrete/tests/testDecisionTree.cpp index 2cc8d8441c..c625e1ba63 100644 --- a/gtsam/discrete/tests/testDecisionTree.cpp +++ b/gtsam/discrete/tests/testDecisionTree.cpp @@ -333,17 +333,17 @@ TEST(DecisionTree, Compose) { // Create from string vector keys{DT::LabelC(A, 2), DT::LabelC(B, 2)}; - DT f2(keys, {0, 2, 1, 3}); + DT f2(keys, "0 2 1 3"); EXPECT(assert_equal(f2, f1, 1e-9)); // Put this AB tree together with another one - DT f3(keys, {4, 6, 5, 7}); + DT f3(keys, "4 6 5 7"); DT f4(C, f1, f3); DOT(f4); // a bigger tree keys.push_back(DT::LabelC(C, 2)); - DT f5(keys, {0, 4, 2, 6, 1, 5, 3, 7}); + DT f5(keys, "0 4 2 6 1 5 3 7"); EXPECT(assert_equal(f5, f4, 1e-9)); DOT(f5); } @@ -508,7 +508,7 @@ TEST(DecisionTree, threshold) { // Create three level tree const vector keys{DT::LabelC("C", 2), DT::LabelC("B", 2), DT::LabelC("A", 2)}; - DT tree(keys, {0, 1, 2, 3, 4, 5, 6, 7}); + DT tree(keys, "0 1 2 3 4 5 6 7"); // Check number of leaves equal to zero auto count = [](const int& value, int count) { @@ -536,10 +536,10 @@ TEST(DecisionTree, ApplyWithAssignment) { // Create three level tree const vector keys{DT::LabelC("C", 2), DT::LabelC("B", 2), DT::LabelC("A", 2)}; - DT tree(keys, {1, 2, 3, 4, 5, 6, 7, 8}); + DT tree(keys, "1 2 3 4 5 6 7 8"); DecisionTree probTree( - keys, {0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08}); + keys, "0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08"); double threshold = 0.045; // We test pruning one tree by indexing into another. @@ -553,7 +553,7 @@ TEST(DecisionTree, ApplyWithAssignment) { }; DT prunedTree = tree.apply(pruner); - DT expectedTree(keys, {0, 0, 0, 0, 5, 6, 7, 8}); + DT expectedTree(keys, "0 0 0 0 5 6 7 8"); EXPECT(assert_equal(expectedTree, prunedTree)); size_t count = 0; diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index a06f244238..ab15fee303 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -55,6 +55,14 @@ class GTSAM_EXPORT HybridGaussianProductFactor */ HybridGaussianProductFactor(Base&& tree) : Base(std::move(tree)) {} + /// Deleted constructor since we don't have istream operator for + /// GaussianFactorGraphValuePair + HybridGaussianProductFactor(const std::vector& labelCs, + const std::string& table) { + throw std::runtime_error( + "HybridGaussianProductFactor: No way to construct."); + } + ///@} /// @name Operators From 93ec276ef3090c46a13307c6c777b51f84f308aa Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 9 Oct 2024 13:47:59 -0400 Subject: [PATCH 12/12] implement dummy >> operator --- gtsam/hybrid/HybridGaussianProductFactor.cpp | 6 ++++++ gtsam/hybrid/HybridGaussianProductFactor.h | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gtsam/hybrid/HybridGaussianProductFactor.cpp b/gtsam/hybrid/HybridGaussianProductFactor.cpp index f7b5994f0f..280059f542 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.cpp +++ b/gtsam/hybrid/HybridGaussianProductFactor.cpp @@ -103,4 +103,10 @@ HybridGaussianProductFactor HybridGaussianProductFactor::removeEmpty() const { return {Base(*this, emptyGaussian)}; } +/* *******************************************************************************/ +std::istream& operator>>(std::istream& is, GaussianFactorGraphValuePair& pair) { + // Dummy, don't do anything + return is; +} + } // namespace gtsam diff --git a/gtsam/hybrid/HybridGaussianProductFactor.h b/gtsam/hybrid/HybridGaussianProductFactor.h index ab15fee303..60a58a3a51 100644 --- a/gtsam/hybrid/HybridGaussianProductFactor.h +++ b/gtsam/hybrid/HybridGaussianProductFactor.h @@ -22,6 +22,8 @@ #include #include +#include + namespace gtsam { class HybridGaussianFactor; @@ -55,14 +57,6 @@ class GTSAM_EXPORT HybridGaussianProductFactor */ HybridGaussianProductFactor(Base&& tree) : Base(std::move(tree)) {} - /// Deleted constructor since we don't have istream operator for - /// GaussianFactorGraphValuePair - HybridGaussianProductFactor(const std::vector& labelCs, - const std::string& table) { - throw std::runtime_error( - "HybridGaussianProductFactor: No way to construct."); - } - ///@} /// @name Operators @@ -140,4 +134,14 @@ template <> struct traits : public Testable {}; +/** + * Create a dummy overload of >> for GaussianFactorGraphValuePair + * so that HybridGaussianProductFactor compiles + * with the constructor + * `DecisionTree(const std::vector& labelCs, const std::string& table)`. + * + * Needed to compile on Windows. + */ +std::istream& operator>>(std::istream& is, GaussianFactorGraphValuePair& pair); + } // namespace gtsam