From 5ff18708425f850142b96f3109cdaa967f1d1aee Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Sat, 21 Jul 2012 19:15:13 +0000 Subject: [PATCH] Removed workaround for old boost versions in discrete - we now require a higher version anyway --- gtsam/discrete/Signature.cpp | 7 ---- gtsam/discrete/Signature.h | 5 --- .../tests/testAlgebraicDecisionTree.cpp | 12 ------- gtsam/discrete/tests/testDiscreteBayesNet.cpp | 8 ----- .../tests/testDiscreteConditional.cpp | 35 ++++++++++--------- .../tests/testDiscreteFactorGraph.cpp | 6 ---- gtsam/discrete/tests/testSignature.cpp | 2 -- 7 files changed, 19 insertions(+), 56 deletions(-) diff --git a/gtsam/discrete/Signature.cpp b/gtsam/discrete/Signature.cpp index 439f20864..76ccad9db 100644 --- a/gtsam/discrete/Signature.cpp +++ b/gtsam/discrete/Signature.cpp @@ -21,17 +21,13 @@ #include "Signature.h" -#ifdef BOOST_HAVE_PARSER #include // for parsing #include // for qi::_val -#endif namespace gtsam { using namespace std; - -#ifdef BOOST_HAVE_PARSER namespace qi = boost::spirit::qi; namespace ph = boost::phoenix; @@ -109,7 +105,6 @@ namespace gtsam { return true; } } // \namespace parser -#endif ostream& operator <<(ostream &os, const Signature::Row &row) { os << row[0]; @@ -169,7 +164,6 @@ namespace gtsam { Signature& Signature::operator=(const string& spec) { spec_.reset(spec); -#ifdef BOOST_HAVE_PARSER Table table; // NOTE: using simpler parse function to ensure boost back compatibility // parser::It f = spec.begin(), l = spec.end(); @@ -181,7 +175,6 @@ namespace gtsam { normalize(row); table_.reset(table); } -#endif return *this; } diff --git a/gtsam/discrete/Signature.h b/gtsam/discrete/Signature.h index 873365c24..937bd6e1b 100644 --- a/gtsam/discrete/Signature.h +++ b/gtsam/discrete/Signature.h @@ -22,11 +22,6 @@ #include #include -#include // for checking whether we are using boost 1.40 -#if BOOST_VERSION >= 104200 -#define BOOST_HAVE_PARSER -#endif - namespace gtsam { /** diff --git a/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp b/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp index bfeacb8e4..8ab3b6a14 100644 --- a/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp +++ b/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp @@ -23,10 +23,6 @@ #include #include // for convert only #define DISABLE_TIMING -#include // for checking whether we are using boost 1.40 -#if BOOST_VERSION >= 104200 -#define BOOST_HAVE_PARSER -#endif #include #include @@ -150,7 +146,6 @@ TEST(ADT, joint) { DiscreteKey A(0, 2), S(1, 2), T(2, 2), L(3, 2), B(4, 2), E(5, 2), X(6, 2), D(7, 2); -#ifdef BOOST_HAVE_PARSER resetCounts(); ADT pA = create(A % "99/1"); ADT pS = create(S % "50/50"); @@ -193,7 +188,6 @@ TEST(ADT, joint) EXPECT(assert_equal(pA, fAa)); ADT fAb = pASTL.combine(S, &add_).combine(T, &add_).combine(L, &add_); EXPECT(assert_equal(pA, fAb)); -#endif } /* ************************************************************************* */ @@ -203,7 +197,6 @@ TEST(ADT, inference) DiscreteKey A(0,2), D(1,2),// B(2,2), L(3,2), E(4,2), S(5,2), T(6,2), X(7,2); -#ifdef BOOST_HAVE_PARSER resetCounts(); ADT pA = create(A % "99/1"); ADT pS = create(S % "50/50"); @@ -247,7 +240,6 @@ TEST(ADT, inference) dot(marginal, "Joint-Sum-ADBL"); EXPECT_LONGS_EQUAL(161, adds); printCounts("Asia sum"); -#endif } /* ************************************************************************* */ @@ -255,7 +247,6 @@ TEST(ADT, factor_graph) { DiscreteKey B(0,2), L(1,2), E(2,2), S(3,2), T(4,2), X(5,2); -#ifdef BOOST_HAVE_PARSER resetCounts(); ADT pS = create(S % "50/50"); ADT pT = create(T % "95/5"); @@ -334,7 +325,6 @@ TEST(ADT, factor_graph) fB = fB.combine(L, &add_); dot(fB, "Eliminate-10-fB"); printCounts("Eliminate L"); -#endif } /* ************************************************************************* */ @@ -360,7 +350,6 @@ TEST(ADT, equality_noparser) } /* ************************************************************************* */ -#ifdef BOOST_HAVE_PARSER // test equality TEST(ADT, equality_parser) { @@ -376,7 +365,6 @@ TEST(ADT, equality_parser) ADT pAB2 = apply(pB, pA1, &mul); EXPECT(pAB2 == pAB1); } -#endif /* ******************************************************************************** */ // Factor graph construction diff --git a/gtsam/discrete/tests/testDiscreteBayesNet.cpp b/gtsam/discrete/tests/testDiscreteBayesNet.cpp index bc07d57ca..63f225c35 100644 --- a/gtsam/discrete/tests/testDiscreteBayesNet.cpp +++ b/gtsam/discrete/tests/testDiscreteBayesNet.cpp @@ -25,10 +25,6 @@ #include using namespace boost::assign; -#include // for checking whether we are using boost 1.40 -#if BOOST_VERSION >= 104200 -#define BOOST_HAVE_PARSER -#endif #include @@ -44,7 +40,6 @@ TEST(DiscreteBayesNet, Asia) DiscreteKey A(0,2), S(4,2), T(3,2), L(6,2), B(7,2), E(5,2), X(2,2), D(1,2); // TODO: make a version that doesn't use the parser -#ifdef BOOST_HAVE_PARSER add_front(asia, A % "99/1"); add_front(asia, S % "50/50"); @@ -104,7 +99,6 @@ TEST(DiscreteBayesNet, Asia) S.first, 1)(E.first, 0)(L.first, 0)(B.first, 1); DiscreteFactor::sharedValues actualSample = sample(*chordal2); EXPECT(assert_equal(expectedSample, *actualSample)); -#endif } /* ************************************************************************* */ @@ -114,7 +108,6 @@ TEST_UNSAFE(DiscreteBayesNet, Sugar) DiscreteBayesNet bn; -#ifdef BOOST_HAVE_PARSER // test some mistakes // add(bn, D); // add(bn, D | E); @@ -127,7 +120,6 @@ TEST_UNSAFE(DiscreteBayesNet, Sugar) // // try multivalued add(bn, C % "1/1/2"); add(bn, C | S = "1/1/2 5/2/3"); -#endif } /* ************************************************************************* */ diff --git a/gtsam/discrete/tests/testDiscreteConditional.cpp b/gtsam/discrete/tests/testDiscreteConditional.cpp index c11dddef5..8af23e4f8 100644 --- a/gtsam/discrete/tests/testDiscreteConditional.cpp +++ b/gtsam/discrete/tests/testDiscreteConditional.cpp @@ -24,10 +24,6 @@ using namespace boost::assign; #include #include #include -#include // for checking whether we are using boost 1.40 -#if BOOST_VERSION >= 104200 -#define BOOST_HAVE_PARSER -#endif using namespace std; using namespace gtsam; @@ -37,17 +33,31 @@ TEST( DiscreteConditionalTest, constructors) { DiscreteKey X(0, 2), Y(2, 3), Z(1, 2); // watch ordering ! -#ifdef BOOST_HAVE_PARSER DiscreteConditional::shared_ptr expected1 = // boost::make_shared(X | Y = "1/1 2/3 1/4"); -#else + EXPECT(expected1); + DecisionTreeFactor f1(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8"); + DiscreteConditional actual1(1, f1); + EXPECT(assert_equal(*expected1, actual1, 1e-9)); + + DecisionTreeFactor f2(X & Y & Z, + "0.2 0.5 0.3 0.6 0.4 0.7 0.25 0.55 0.35 0.65 0.45 0.75"); + DiscreteConditional actual2(1, f2); + DecisionTreeFactor::shared_ptr actual2factor = actual2.toFactor(); +// EXPECT(assert_equal(f2, *actual2factor, 1e-9)); +} + +/* ************************************************************************* */ +TEST( DiscreteConditionalTest, constructors_alt_interface) +{ + DiscreteKey X(0, 2), Y(2, 3), Z(1, 2); // watch ordering ! + Signature::Table table; Signature::Row r1, r2, r3; r1 += 1.0, 1.0; r2 += 2.0, 3.0; r3 += 1.0, 4.0; table += r1, r2, r3; DiscreteConditional::shared_ptr expected1 = // boost::make_shared(X | Y = table); -#endif EXPECT(expected1); DecisionTreeFactor f1(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8"); DiscreteConditional actual1(1, f1); @@ -63,7 +73,6 @@ TEST( DiscreteConditionalTest, constructors) /* ************************************************************************* */ TEST( DiscreteConditionalTest, constructors2) { -#ifdef BOOST_HAVE_PARSER // Declare keys and ordering DiscreteKey C(0,2), B(1,2); DecisionTreeFactor expected(C & B, "0.8 0.75 0.2 0.25"); @@ -71,13 +80,11 @@ TEST( DiscreteConditionalTest, constructors2) DiscreteConditional actual(signature); DecisionTreeFactor::shared_ptr actualFactor = actual.toFactor(); EXPECT(assert_equal(expected, *actualFactor)); -#endif - } +} /* ************************************************************************* */ TEST( DiscreteConditionalTest, constructors3) { -#ifdef BOOST_HAVE_PARSER // Declare keys and ordering DiscreteKey C(0,2), B(1,2), A(2,2); DecisionTreeFactor expected(C & B & A, "0.8 0.5 0.5 0.2 0.2 0.5 0.5 0.8"); @@ -85,13 +92,9 @@ TEST( DiscreteConditionalTest, constructors3) DiscreteConditional actual(signature); DecisionTreeFactor::shared_ptr actualFactor = actual.toFactor(); EXPECT(assert_equal(expected, *actualFactor)); -#endif } /* ************************************************************************* */ -int main() { - TestResult tr; - return TestRegistry::runAllTests(tr); -} +int main() { TestResult tr; return TestRegistry::runAllTests(tr); } /* ************************************************************************* */ diff --git a/gtsam/discrete/tests/testDiscreteFactorGraph.cpp b/gtsam/discrete/tests/testDiscreteFactorGraph.cpp index 667ce9331..8fdbc5870 100644 --- a/gtsam/discrete/tests/testDiscreteFactorGraph.cpp +++ b/gtsam/discrete/tests/testDiscreteFactorGraph.cpp @@ -24,10 +24,6 @@ #include using namespace boost::assign; -#include // for checking whether we are using boost 1.40 -#if BOOST_VERSION >= 104200 -#define BOOST_HAVE_PARSER -#endif using namespace std; using namespace gtsam; @@ -136,7 +132,6 @@ TEST( DiscreteFactorGraph, test) boost::tie(conditional, newFactor) =// EliminateDiscrete(graph, 1); -#ifdef BOOST_HAVE_PARSER // Check Bayes net CHECK(conditional); DiscreteBayesNet expected; @@ -173,7 +168,6 @@ TEST( DiscreteFactorGraph, test) insert(expectedValues)(0, 0)(1, 0)(2, 0); DiscreteFactor::sharedValues actualValues = solver.optimize(); EXPECT(assert_equal(expectedValues, *actualValues)); -#endif } /* ************************************************************************* */ diff --git a/gtsam/discrete/tests/testSignature.cpp b/gtsam/discrete/tests/testSignature.cpp index 66b1c61b3..bf4aabb7f 100644 --- a/gtsam/discrete/tests/testSignature.cpp +++ b/gtsam/discrete/tests/testSignature.cpp @@ -28,7 +28,6 @@ using namespace boost::assign; DiscreteKey X(0,2), Y(1,3), Z(2,2); -#ifdef BOOST_HAVE_PARSER /* ************************************************************************* */ TEST(testSignature, simple_conditional) { Signature sig(X | Y = "1/1 2/3 1/4"); @@ -43,7 +42,6 @@ TEST(testSignature, simple_conditional) { vector actCpt = sig.cpt(); EXPECT_LONGS_EQUAL(6, actCpt.size()); } -#endif /* ************************************************************************* */ TEST(testSignature, simple_conditional_nonparser) {