testSparseEigen.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 #include <boost/assign/list_of.hpp>
25 using boost::assign::list_of;
26 
29 
30 using namespace std;
31 using namespace gtsam;
32 
33 /* ************************************************************************* */
36  SharedDiagonal model = noiseModel::Isotropic::Sigma(2, 0.5);
37  const Key x123 = 0, x45 = 1;
38  gfg.add(x123, (Matrix(2, 3) << 1, 2, 3, 5, 6, 7).finished(),
39  Vector2(4, 8), model);
40  gfg.add(x123, (Matrix(2, 3) << 9, 10, 0, 0, 0, 0).finished(),
41  x45, (Matrix(2, 2) << 11, 12, 14, 15.).finished(),
42  Vector2(13, 16), model);
43 
44  // Sparse Matrix
45  auto sparseResult = sparseJacobianEigen(gfg);
46  EXPECT_LONGS_EQUAL(16, sparseResult.nonZeros());
47  EXPECT(assert_equal(4, sparseResult.rows()));
48  EXPECT(assert_equal(6, sparseResult.cols()));
49  EXPECT(assert_equal(gfg.augmentedJacobian(), Matrix(sparseResult)));
50 
51  // Call sparseJacobian with optional ordering...
52  auto ordering = Ordering(list_of(x45)(x123));
53 
54  // Eigen Sparse with optional ordering
57 
58  // Check matrix dimensions when zero rows / cols
59  gfg.add(x123, Matrix23::Zero(), Vector2::Zero(), model); // zero row
60  gfg.add(2, Matrix21::Zero(), Vector2::Zero(), model); // zero col
61  sparseResult = sparseJacobianEigen(gfg);
62  EXPECT_LONGS_EQUAL(16, sparseResult.nonZeros());
63  EXPECT(assert_equal(8, sparseResult.rows()));
64  EXPECT(assert_equal(7, sparseResult.cols()));
65 }
66 
67 /* ************************************************************************* */
68 int main() {
69  TestResult tr;
70  return TestRegistry::runAllTests(tr);
71 }
72 /* ************************************************************************* */
Provides additional testing facilities for common data structures.
int main()
static int runAllTests(TestResult &result)
A versatible sparse matrix representation.
Definition: SparseMatrix.h:96
Utilities for creating Eigen sparse matrices (gtsam::SparseEigen)
noiseModel::Diagonal::shared_ptr model
static enum @843 ordering
Definition: Half.h:150
Matrix augmentedJacobian(const Ordering &ordering) const
SparseEigen sparseJacobianEigen(const GaussianFactorGraph &gfg, const Ordering &ordering)
Constructs an Eigen-format SparseMatrix of a GaussianFactorGraph.
Definition: SparseEigen.h:38
void add(const GaussianFactor &factor)
#define EXPECT(condition)
Definition: Test.h:151
Linear Factor Graph where all factors are Gaussians.
noiseModel::Diagonal::shared_ptr SharedDiagonal
Definition: NoiseModel.h:736
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
Eigen::Vector2d Vector2
Definition: Vector.h:42
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
TEST(SparseEigen, sparseJacobianEigen)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:49:53