SymmetricBlockMatrix.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 
21 #include <gtsam/base/cholesky.h>
22 #include <gtsam/base/timing.h>
24 
25 namespace gtsam {
26 
27 /* ************************************************************************* */
29  variableColOffsets_.push_back(0);
31 }
32 
33 /* ************************************************************************* */
35  const SymmetricBlockMatrix& other) {
37  result.variableColOffsets_.resize(other.nBlocks() + 1);
38  for (size_t i = 0; i < result.variableColOffsets_.size(); ++i)
40  + i] - other.variableColOffsets_[other.blockStart_];
41  result.matrix_.resize(other.cols(), other.cols());
42  result.assertInvariants();
43  return result;
44 }
45 
46 /* ************************************************************************* */
48  const VerticalBlockMatrix& other) {
50  result.variableColOffsets_.resize(other.nBlocks() + 1);
51  for (size_t i = 0; i < result.variableColOffsets_.size(); ++i)
53  + i] - other.variableColOffsets_[other.blockStart_];
54  result.matrix_.resize(other.cols(), other.cols());
55  result.assertInvariants();
56  return result;
57 }
58 
59 /* ************************************************************************* */
61  if (I == J) {
62  return diagonalBlock(I);
63  } else if (I < J) {
64  return aboveDiagonalBlock(I, J);
65  } else {
66  return aboveDiagonalBlock(J, I).transpose();
67  }
68 }
69 
70 /* ************************************************************************* */
72  full().triangularView<Eigen::Upper>() *= -1.0;
73 }
74 
75 /* ************************************************************************* */
77  const auto identity = Matrix::Identity(rows(), rows());
78  full().triangularView<Eigen::Upper>() =
79  selfadjointView().llt().solve(identity).triangularView<Eigen::Upper>();
80 }
81 
82 /* ************************************************************************* */
84  gttic(VerticalBlockMatrix_choleskyPartial);
86  if (!gtsam::choleskyPartial(matrix_, offset(nFrontals) - topleft, topleft)) {
87  throw CholeskyFailed();
88  }
89 }
90 
91 /* ************************************************************************* */
93  gttic(VerticalBlockMatrix_split);
94 
95  // Construct a VerticalBlockMatrix that contains [R Sd]
96  const size_t n1 = offset(nFrontals);
98 
99  // Copy into it.
100  RSd.full() = matrix_.topRows(n1);
101  RSd.full().triangularView<Eigen::StrictlyLower>().setZero();
102 
103  // Take lower-right block of Ab_ to get the remaining factor
104  blockStart() = nFrontals;
105 
106  return RSd;
107 }
108 
109 /* ************************************************************************* */
110 
111 } //\ namespace gtsam
112 
DenseIndex cols() const
Column size.
#define I
Definition: main.h:112
constBlock full() const
Get the full matrix as a block.
Access to matrices via blocks of pre-defined sizes. Used in GaussianFactor and GaussianConditional.
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
DenseIndex nBlocks() const
Block count.
A matrix with column blocks of pre-defined sizes. Used in JacobianFactor and GaussianConditional.
Matrix matrix_
The full matrix.
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
static SymmetricBlockMatrix LikeActiveViewOf(const SymmetricBlockMatrix &other)
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:108
void invertInPlace()
Invert the entire active matrix in place.
#define gttic(label)
Definition: timing.h:295
DenseIndex nBlocks() const
Block count.
DenseIndex rows() const
Row size.
Values result
DenseIndex cols() const
Column size.
void negate()
Negate the entire active matrix.
JacobiRotation< float > J
Eigen::SelfAdjointView< Block, Eigen::Upper > selfadjointView()
Get self adjoint view.
traits
Definition: chartTesting.h:28
VerticalBlockMatrix split(DenseIndex nFrontals)
static VerticalBlockMatrix LikeActiveViewOf(const VerticalBlockMatrix &rhs)
bool choleskyPartial(Matrix &ABC, size_t nFrontal, size_t topleft)
DenseIndex offset(DenseIndex block) const
Get an offset for a block index (in the active view).
void choleskyPartial(DenseIndex nFrontals)
void setZero()
Set the entire active matrix zero.
FastVector< DenseIndex > variableColOffsets_
the starting columns of each block (0-based)
SymmetricBlockMatrix()
Construct from an empty matrix (asserts that the matrix is empty)
DenseIndex blockStart_
Changes apparent matrix view, see main class comment.
Indicate Cholesky factorization failure.
Eigen::SelfAdjointView< Block, Eigen::Upper > diagonalBlock(DenseIndex J)
Return the J&#39;th diagonal block as a self adjoint view.
constBlock aboveDiagonalBlock(DenseIndex I, DenseIndex J) const
Get block above the diagonal (I, J).
Matrix block(DenseIndex I, DenseIndex J) const
Timing utilities.
Efficient incomplete Cholesky on rank-deficient matrices, todo: constrained Cholesky.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:36:35