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

More Hybrid Fixes #1866

Merged
merged 12 commits into from
Oct 9, 2024
1 change: 0 additions & 1 deletion gtsam/hybrid/HybridGaussianConditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <gtsam/discrete/DiscreteValues.h>
#include <gtsam/hybrid/HybridGaussianConditional.h>
#include <gtsam/hybrid/HybridGaussianFactor.h>
#include <gtsam/hybrid/HybridGaussianProductFactor.h>
#include <gtsam/hybrid/HybridValues.h>
#include <gtsam/inference/Conditional-inst.h>
#include <gtsam/linear/GaussianBayesNet.h>
Expand Down
1 change: 0 additions & 1 deletion gtsam/hybrid/HybridGaussianConditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <gtsam/discrete/DiscreteKey.h>
#include <gtsam/hybrid/HybridFactor.h>
#include <gtsam/hybrid/HybridGaussianFactor.h>
#include <gtsam/hybrid/HybridGaussianProductFactor.h>
#include <gtsam/inference/Conditional.h>
#include <gtsam/linear/GaussianConditional.h>

Expand Down
6 changes: 6 additions & 0 deletions gtsam/hybrid/HybridGaussianProductFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions gtsam/hybrid/HybridGaussianProductFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <gtsam/inference/Key.h>
#include <gtsam/linear/GaussianFactorGraph.h>

#include <iostream>

namespace gtsam {

class HybridGaussianFactor;
Expand Down Expand Up @@ -115,11 +117,31 @@ class GTSAM_EXPORT HybridGaussianProductFactor
HybridGaussianProductFactor removeEmpty() const;

///@}

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int /*version*/) {
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
#endif
};

// Testable traits
template <>
struct traits<HybridGaussianProductFactor>
: public Testable<HybridGaussianProductFactor> {};

/**
* Create a dummy overload of >> for GaussianFactorGraphValuePair
* so that HybridGaussianProductFactor compiles
* with the constructor
* `DecisionTree(const std::vector<LabelC>& labelCs, const std::string& table)`.
*
* Needed to compile on Windows.
*/
std::istream& operator>>(std::istream& is, GaussianFactorGraphValuePair& pair);

} // namespace gtsam
5 changes: 2 additions & 3 deletions gtsam/hybrid/tests/testHybridGaussianFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down
32 changes: 16 additions & 16 deletions gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ TEST(HybridNonlinearFactorGraph, Full_Elimination) {
/****************************************************************************
* Test printing
*/
TEST_DISABLED(HybridNonlinearFactorGraph, Printing) {
TEST(HybridNonlinearFactorGraph, Printing) {
Switching self(3);

auto linearizedFactorGraph = self.linearizedFactorGraph;
Expand All @@ -549,7 +549,7 @@ Factor 0
GaussianFactor:

A[x0] = [
10
10
]
b = [ -10 ]
No noise model
Expand All @@ -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

}

Expand All @@ -588,33 +588,33 @@ 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

}

Factor 3
GaussianFactor:

A[x1] = [
10
10
]
b = [ -10 ]
No noise model
Expand All @@ -623,7 +623,7 @@ Factor 4
GaussianFactor:

A[x2] = [
10
10
]
b = [ -10 ]
No noise model
Expand Down
5 changes: 5 additions & 0 deletions gtsam/hybrid/tests/testSerializationHybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ 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(HybridGaussianProductFactor,
"gtsam_HybridGaussianProductFactor");

BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional,
"gtsam_HybridGaussianConditional");
BOOST_CLASS_EXPORT_GUID(HybridGaussianConditional::Conditionals,
Expand Down
Loading