30 template<
typename SymmetricBlockMatrixType>
31 struct traits<gtsam::SymmetricBlockMatrixBlockExpr<SymmetricBlockMatrixType> > :
32 public traits<typename gtsam::const_selector<
33 SymmetricBlockMatrixType, gtsam::SymmetricBlockMatrix, gtsam::Matrix, const gtsam::Matrix>::type>
45 template<
typename SymmetricBlockMatrixType>
46 class SymmetricBlockMatrixBlockExpr :
public Eigen::EigenBase<SymmetricBlockMatrixBlockExpr<SymmetricBlockMatrixType> >
49 SymmetricBlockMatrixType&
xpr_;
54 enum BlockType { Plain, SelfAdjoint, Transposed }
blockType_;
60 typename Eigen::internal::traits<This>::Scalar&,
typename Eigen::internal::traits<This>::Scalar>::type ScalarRef;
61 typedef typename Eigen::internal::traits<This>::Scalar Scalar;
62 typedef typename Eigen::internal::traits<This>::Index Index;
63 static const Index ColsAtCompileTime = Eigen::Dynamic;
64 static const Index RowsAtCompileTime = Eigen::Dynamic;
69 typedef Eigen::Map<DenseMatrixType, 0, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> > OffDiagonal;
70 typedef Eigen::SelfAdjointView<Eigen::Block<DenseMatrixType>, Eigen::Upper> SelfAdjointView;
71 typedef Eigen::TriangularView<Eigen::Block<DenseMatrixType>, Eigen::Upper> TriangularView;
74 mutable Eigen::Block<DenseMatrixType> myBlock_;
80 xpr_(blockMatrix), myBlock_(blockMatrix.matrix_.block(0, 0, 0, 0))
82 initIndices(iBlock, jBlock);
88 Index firstRowBlock, Index firstColBlock, Index rowBlocks, Index colBlocks) :
89 xpr_(blockMatrix), myBlock_(blockMatrix.matrix_.block(0, 0, 0, 0))
91 initIndices(firstRowBlock, firstColBlock, rowBlocks, colBlocks);
97 xpr_(blockMatrix), myBlock_(blockMatrix.matrix_.block(0, 0, 0, 0))
99 initIndices(firstBlock, firstBlock, blocks, blocks);
105 inline BlockType blockType()
const {
return blockType_; }
107 inline ScalarRef operator()(Index
row, Index col)
const
109 return coeffInternal<ScalarRef>(
row, col);
112 inline OffDiagonal knownOffDiagonal()
const
114 typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> DynamicStride;
122 return Eigen::Map<DenseMatrixType, 0, DynamicStride>(block.data(), block.cols(), block.rows(),
123 DynamicStride(block.innerStride(), block.outerStride()));
128 return Eigen::Map<DenseMatrixType, 0, DynamicStride>(block.data(), block.rows(), block.cols(),
129 DynamicStride(block.outerStride(), block.innerStride()));
133 inline SelfAdjointView selfadjointView()
const
139 inline TriangularView triangularView()
const
145 template<
typename Dest>
inline void evalTo(Dest& dst)
const
149 dst = selfadjointView();
153 dst = myBlock_.transpose();
172 template<
typename RhsDerived>
173 This& operator=(
const Eigen::MatrixBase<RhsDerived>& rhs)
177 triangularView() = rhs.derived().template triangularView<Eigen::Upper>();
179 myBlock_ = rhs.derived();
181 myBlock_.transpose() = rhs.derived();
185 template<
typename MatrixType>
186 This& operator=(
const Eigen::SelfAdjointView<MatrixType, Eigen::Upper>& rhs)
189 triangularView() = rhs.nestedExpression().template triangularView<Eigen::Upper>();
191 throw std::invalid_argument(
"Cannot assign a self-adjoint matrix to an off-diagonal block");
195 template<
typename OtherSymmetricBlockMatrixType>
196 This& operator=(
const SymmetricBlockMatrixBlockExpr<OtherSymmetricBlockMatrixType>& other)
202 This& operator=(
const This& other)
209 template<
typename OtherSymmetricBlockMatrixType>
210 This& operator+=(
const SymmetricBlockMatrixBlockExpr<OtherSymmetricBlockMatrixType>& other)
214 assert((BlockType)other.blockType() == SelfAdjoint);
215 triangularView() += other.triangularView().nestedExpression();
219 assert((BlockType)other.blockType() == Plain || (BlockType)other.blockType() == Transposed);
220 if((BlockType)other.blockType() == Transposed)
221 myBlock_ += other.myBlock_.transpose();
223 myBlock_ += other.myBlock_;
227 assert((BlockType)other.blockType() == Plain || (BlockType)other.blockType() == Transposed);
228 if((BlockType)other.blockType() == Transposed)
229 myBlock_.transpose() += other.myBlock_.transpose();
231 myBlock_.transpose() += other.myBlock_;
237 void initIndices(Index iBlock, Index jBlock, Index blockRows = 1, Index blockCols = 1)
239 if(iBlock == jBlock && blockRows == blockCols)
244 xpr_.checkBlock(iBlock + blockRows - 1);
247 xpr_.checkBlock(jBlock + blockCols - 1);
253 if(jBlock > iBlock || (iBlock == jBlock && blockCols > blockRows))
258 xpr_.checkBlock(iBlock + blockRows - 1);
261 xpr_.checkBlock(jBlock + blockCols - 1);
270 xpr_.checkBlock(jBlock + blockCols - 1);
273 xpr_.checkBlock(iBlock + blockRows - 1);
281 throw std::invalid_argument(
"Off-diagonal block ranges may not cross the diagonal");
287 template<
typename ScalarType>
288 inline ScalarType coeffInternal(Index
row, Index col)
const
293 return myBlock_(row, col);
298 return myBlock_(row, col);
300 return myBlock_.transpose()(
row, col);
304 return myBlock_.transpose()(
row, col);
308 template<
typename OtherSymmetricBlockMatrixType>
309 void _doAssign(
const SymmetricBlockMatrixBlockExpr<OtherSymmetricBlockMatrixType>& other)
313 assert((BlockType)other.blockType() == SelfAdjoint);
314 triangularView() = other.triangularView().nestedExpression();
318 assert((BlockType)other.blockType() == Plain || (BlockType)other.blockType() == Transposed);
319 if((BlockType)other.blockType() == Transposed)
320 myBlock_ = other.myBlock_.transpose();
322 myBlock_ = other.myBlock_;
326 assert((BlockType)other.blockType() == Plain || (BlockType)other.blockType() == Transposed);
327 if((BlockType)other.blockType() == Transposed)
328 myBlock_.transpose() = other.myBlock_.transpose();
330 myBlock_.transpose() = other.myBlock_;
DenseIndex denseRows_
The scalar size of the referenced block.
Definition: SymmetricBlockMatrixBlockExpr.h:52
SymmetricBlockMatrixType & xpr_
The referenced SymmetricBlockMatrix.
Definition: SymmetricBlockMatrixBlockExpr.h:49
SymmetricBlockMatrixBlockExpr(SymmetricBlockMatrixType &blockMatrix, Index iBlock, Index jBlock)
Create a SymmetricBlockMatrixBlockExpr from the specified block of a SymmetricBlockMatrix.
Definition: SymmetricBlockMatrixBlockExpr.h:79
DenseIndex densei_
The scalar indices of the referenced block.
Definition: SymmetricBlockMatrixBlockExpr.h:50
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
Extracts a row view from a matrix that avoids a copy.
Definition: Matrix.h:246
Helper class that uses templates to select between two types based on whether TEST_TYPE is const or n...
Definition: types.h:84
A matrix expression that references a single block of a SymmetricBlockMatrix.
Definition: SymmetricBlockMatrixBlockExpr.h:22
SymmetricBlockMatrixBlockExpr(SymmetricBlockMatrixType &blockMatrix, Index firstBlock, Index blocks, char dummy)
Create a SymmetricBlockMatrixBlockExpr from the specified range of blocks of a SymmetricBlockMatrix.
Definition: SymmetricBlockMatrixBlockExpr.h:96
SymmetricBlockMatrixBlockExpr(SymmetricBlockMatrixType &blockMatrix, Index firstRowBlock, Index firstColBlock, Index rowBlocks, Index colBlocks)
Create a SymmetricBlockMatrixBlockExpr from the specified range of blocks of a SymmetricBlockMatrix.
Definition: SymmetricBlockMatrixBlockExpr.h:87
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:74
DenseIndex densej_
The scalar indices of the referenced block.
Definition: SymmetricBlockMatrixBlockExpr.h:51
typedef and functions to augment Eigen's MatrixXd
Definition: SymmetricBlockMatrix.h:40
enum gtsam::SymmetricBlockMatrixBlockExpr::BlockType blockType_
The type of the referenced block, as determined by the block position.
DenseIndex denseCols_
The scalar size of the referenced block.
Definition: SymmetricBlockMatrixBlockExpr.h:53