diff --git a/gtsam/discrete/discrete.i b/gtsam/discrete/discrete.i index 68c2e5079..9c9869b04 100644 --- a/gtsam/discrete/discrete.i +++ b/gtsam/discrete/discrete.i @@ -5,20 +5,37 @@ namespace gtsam { -// typedef pair DiscreteKey; +#include +class DiscreteKey {}; + +class DiscreteKeys { + DiscreteKeys(); + size_t size() const; + bool empty() const; + gtsam::DiscreteKey at(size_t n) const; + void push_back(const gtsam::DiscreteKey& point_pair); +}; #include class DiscreteFactor { }; +#include +class Signature { + Signature(gtsam::DiscreteKey key); +}; + #include -class DecisionTreeFactor { +class DecisionTreeFactor: gtsam::DiscreteFactor { DecisionTreeFactor(); }; #include class DiscreteFactorGraph { DiscreteFactorGraph(); + void add(const gtsam::DiscreteKey& j, string table); + void add(const gtsam::DiscreteKeys& j, string table); + void print(string s = "") const; }; } // namespace gtsam diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 3781a16ba..d1bfc5740 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -49,6 +49,7 @@ set(ignore gtsam::Pose3Vector gtsam::KeyVector gtsam::BinaryMeasurementsUnit3 + gtsam::DiscreteKey gtsam::KeyPairDoubleMap) set(interface_headers diff --git a/python/gtsam/preamble/discrete.h b/python/gtsam/preamble/discrete.h index 56a07cfdd..608508c32 100644 --- a/python/gtsam/preamble/discrete.h +++ b/python/gtsam/preamble/discrete.h @@ -12,3 +12,5 @@ */ #include + +PYBIND11_MAKE_OPAQUE(gtsam::DiscreteKeys); diff --git a/python/gtsam/specializations/discrete.h b/python/gtsam/specializations/discrete.h index da8842eaf..447f9a4d6 100644 --- a/python/gtsam/specializations/discrete.h +++ b/python/gtsam/specializations/discrete.h @@ -10,3 +10,6 @@ * with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python, * and saves one copy operation. */ + +// Seems this is not a good idea with inherited stl +//py::bind_vector>(m_, "DiscreteKeys"); \ No newline at end of file diff --git a/python/gtsam/tests/test_DiscreteFactorGraph.py b/python/gtsam/tests/test_DiscreteFactorGraph.py index 6fad601b6..afc6630bd 100644 --- a/python/gtsam/tests/test_DiscreteFactorGraph.py +++ b/python/gtsam/tests/test_DiscreteFactorGraph.py @@ -31,20 +31,32 @@ from gtsam.utils.test_case import GtsamTestCase # using namespace std # using namespace gtsam +from gtsam import DiscreteKeys, DiscreteFactorGraph + class TestDiscreteFactorGraph(GtsamTestCase): """Tests for Discrete Factor Graphs.""" def test_evaluation(self): # Three keys P1 and P2 - P1=DiscreteKey(0,2) - P2=DiscreteKey(1,2) - P3=DiscreteKey(2,3) + P1 = (0, 2) + P2 = (1, 2) + P3 = (2, 3) # Create the DiscreteFactorGraph graph = DiscreteFactorGraph() -# graph.add(P1, "0.9 0.3") -# graph.add(P2, "0.9 0.6") -# graph.add(P1 & P2, "4 1 10 4") + graph.add(P1, "0.9 0.3") + graph.add(P2, "0.9 0.6") + + # NOTE(fan): originally is an operator overload in C++ & + def discrete_and(a, b): + dks = DiscreteKeys() + dks.push_back(a) + dks.push_back(b) + return dks + + graph.add(discrete_and(P1, P2), "4 1 10 4") + + print(graph) # # Instantiate Values # DiscreteFactor::Values values