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


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:17:29