testSymbolicFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
23 
24 
25 using namespace std;
26 using namespace gtsam;
27 
28 /* ************************************************************************* */
29 #ifdef TRACK_ELIMINATE
30 TEST(SymbolicFactor, eliminate) {
31  KeyVector keys {2, 3, 4, 6, 7, 9, 10, 11};
32  IndexFactor actual(keys.begin(), keys.end());
33  BayesNet<IndexConditional> fragment = *actual.eliminate(3);
34 
35  IndexFactor expected(keys.begin()+3, keys.end());
36  IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1);
37  IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1);
38  IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1);
39 
40  CHECK(assert_equal(fragment.size(), size_t(3)));
41  CHECK(assert_equal(expected, actual));
42  BayesNet<IndexConditional>::const_iterator fragmentCond = fragment.begin();
43  CHECK(assert_equal(**fragmentCond++, *expected0));
44  CHECK(assert_equal(**fragmentCond++, *expected1));
45  CHECK(assert_equal(**fragmentCond++, *expected2));
46 }
47 #endif
48 
49 /* ************************************************************************* */
50 TEST(SymbolicFactor, Constructors)
51 {
53 
54  SymbolicFactor actual1 = SymbolicFactor::FromKeys(expected.keys());
55  SymbolicFactor actual2 = SymbolicFactor::FromIterators(expected.begin(), expected.end());
56  SymbolicFactor actual3 = *SymbolicFactor::FromKeysShared(expected.keys());
57  SymbolicFactor actual4 = *SymbolicFactor::FromIteratorsShared(expected.begin(), expected.end());
58 
59  EXPECT(assert_equal(expected, actual1));
60  EXPECT(assert_equal(expected, actual2));
61  EXPECT(assert_equal(expected, actual3));
62  EXPECT(assert_equal(expected, actual4));
63 }
64 
65 /* ************************************************************************* */
67 {
69  std::make_shared<SymbolicFactor>(2, 4, 6),
70  std::make_shared<SymbolicFactor>(1, 2, 5),
71  std::make_shared<SymbolicFactor>(0, 3)};
72 
73  const SymbolicFactor expectedFactor(4,5,6);
74  const SymbolicConditional expectedConditional =
75  SymbolicConditional::FromKeys(KeyVector{0,1,2,3,4,5,6}, 4);
76 
77  const auto [actualConditional, actualFactor] =
78  EliminateSymbolic(factors, Ordering{0, 1, 2, 3});
79 
80  CHECK(assert_equal(expectedConditional, *actualConditional));
81  CHECK(assert_equal(expectedFactor, *actualFactor));
82 }
83 
84 /* ************************************************************************* */
85 int main() {
86  TestResult tr;
87  return TestRegistry::runAllTests(tr);
88 }
89 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
gtsam::BayesNet
Definition: BayesNet.h:35
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
SymbolicFactor.h
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
SymbolicConditional.h
TestableAssertions.h
Provides additional testing facilities for common data structures.
gtsam::internal::EliminateSymbolic
std::pair< std::shared_ptr< SymbolicConditional >, std::shared_ptr< SymbolicFactor > > EliminateSymbolic(const FactorGraph< FACTOR > &factors, const Ordering &keys)
Definition: SymbolicFactor-inst.h:38
gtsam::SymbolicFactorGraph
Definition: SymbolicFactorGraph.h:61
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
SymbolicFactorGraph.h
TestResult
Definition: TestResult.h:26
gtsam::SymbolicConditional
Definition: SymbolicConditional.h:36
gtsam::FactorGraph< CONDITIONAL >::size
size_t size() const
Definition: FactorGraph.h:297
gtsam
traits
Definition: SFMdata.h:40
gtsam::SymbolicFactor
Definition: SymbolicFactor.h:38
CHECK
#define CHECK(condition)
Definition: Test.h:108
std
Definition: BFloat16.h:88
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::FactorGraph< CONDITIONAL >::begin
const_iterator begin() const
Definition: FactorGraph.h:339
TEST
TEST(SymbolicFactor, Constructors)
Definition: testSymbolicFactor.cpp:50
main
int main()
Definition: testSymbolicFactor.cpp:85
gtsam::Ordering
Definition: inference/Ordering.h:33


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:41:48