Go to the documentation of this file.
11 #ifndef EIGEN_SPARSEBLOCKMATRIX_H
12 #define EIGEN_SPARSEBLOCKMATRIX_H
54 template<
typename _Scalar,
int _BlockAtCompileTime=Dynamic,
int _Options=ColMajor,
typename _StorageIndex=
int>
class BlockSparseMatrix;
59 template<
typename _Scalar,
int _BlockAtCompileTime,
int _Options,
typename _Index>
71 BlockSize = _BlockAtCompileTime,
77 template<
typename BlockSparseMatrixT>
86 template<
typename Iterator,
bool IsColMajor>
92 return ((
a.col() ==
b.col() &&
a.row() <
b.row()) || (
a.col() <
b.col()));
94 return ((
a.row() ==
b.row() &&
a.col() <
b.col()) || (
a.row() <
b.row()));
101 template<
typename BlockSparseMatrixT>
102 class BlockSparseMatrixView :
public SparseMatrixBase<BlockSparseMatrixT>
110 Flags = BlockSparseMatrixT::Options,
157 template<
typename BlockSparseMatrixT,
typename VectorType>
185 return m_vec.middleRows(startRow, rowSize);
191 return m_vec.block(startRow,
j, rowSize, 1);
202 template<
typename BlockSparseMatrixT,
typename VectorType>
225 return m_vec.middleRows(startRow, rowSize);
231 return m_vec.block(startRow,
j, rowSize, 1);
240 template<
typename Lhs,
typename Rhs>
245 template<
typename BlockSparseMatrixT,
typename VecType>
263 template<
typename Lhs,
typename Rhs>
264 class BlockSparseTimeDenseProduct
265 :
public ProductBase<BlockSparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs>
283 template<
typename _Scalar,
int _BlockAtCompileTime,
int _Options,
typename _StorageIndex>
284 class BlockSparseMatrix :
public SparseMatrixBase<BlockSparseMatrix<_Scalar,_BlockAtCompileTime, _Options,_StorageIndex> >
352 std::swap(first.m_innerBSize, second.m_innerBSize);
353 std::swap(first.m_outerBSize, second.m_outerBSize);
354 std::swap(first.m_innerOffset, second.m_innerOffset);
355 std::swap(first.m_outerOffset, second.m_outerOffset);
356 std::swap(first.m_nonzerosblocks, second.m_nonzerosblocks);
357 std::swap(first.m_nonzeros, second.m_nonzeros);
358 std::swap(first.m_values, second.m_values);
359 std::swap(first.m_blockPtr, second.m_blockPtr);
360 std::swap(first.m_indices, second.m_indices);
361 std::swap(first.m_outerIndex, second.m_outerIndex);
362 std::swap(first.m_BlockSize, second.m_blockSize);
388 template<
typename MatrixType>
404 template<
typename MatrixType>
408 &&
"Trying to assign to a zero-size matrix, call resize() first");
419 blockPattern.startVec(bj);
422 typename MatrixType::InnerIterator it_spmat(spmat,
j);
423 for(; it_spmat; ++it_spmat)
426 if(!nzblocksFlag[bi])
429 nzblocksFlag[bi] =
true;
430 blockPattern.insertBackByOuterInnerUnordered(bj, bi) =
true;
437 blockPattern.finalize();
449 typename MatrixType::InnerIterator it_spmat(spmat,
j);
450 for(; it_spmat; ++it_spmat)
472 m_values[idxVal] = it_spmat.value();
497 template<
typename MatrixType>
500 resize(blockPattern.rows(), blockPattern.cols());
501 reserve(blockPattern.nonZeros());
513 std::vector<int> nzBlockIdx;
514 typename MatrixType::InnerIterator it(blockPattern, bj);
517 nzBlockIdx.push_back(it.index());
519 std::sort(nzBlockIdx.begin(), nzBlockIdx.end());
522 for(
StorageIndex idx = 0; idx < nzBlockIdx.size(); ++idx)
599 "TRYING TO RESERVE ZERO-SIZE MATRICES, CALL resize() first");
630 template<
typename InputIterator>
640 std::sort(begin,
end, tripletcomp);
647 rowBlocks.setZero(); colBlocks.setZero();
650 nzblock_outer.setZero();
652 for(InputIterator it(begin); it !=
end; ++it)
654 eigen_assert(it->row() >= 0 && it->row() <
this->blockRows() && it->col() >= 0 && it->col() <
this->blockCols());
660 eigen_assert((rowBlocks[it->row()] == 0 || rowBlocks[it->row()] == it->value().rows()) &&
661 "NON CORRESPONDING SIZES FOR ROW BLOCKS");
662 eigen_assert((colBlocks[it->col()] == 0 || colBlocks[it->col()] == it->value().cols()) &&
663 "NON CORRESPONDING SIZES FOR COLUMN BLOCKS");
664 rowBlocks[it->row()] =it->value().rows();
665 colBlocks[it->col()] = it->value().cols();
667 nz_outer(
IsColMajor ? it->col() : it->row()) += it->value().rows() * it->value().cols();
668 nzblock_outer(
IsColMajor ? it->col() : it->row())++;
692 for(InputIterator it(begin); it!=
end; ++it)
697 StorageIndex block_size = it->value().rows()*it->value().cols();
699 memcpy(&(
m_values[nz_marker]), it->value().data(), block_size *
sizeof(
Scalar));
853 template<
typename VecType>
916 class BlockInnerIterator;
922 BlockInnerIterator itb(
m,
j);
925 s <<
"("<<itb.row() <<
", " << itb.col() <<
")\n";
926 s << itb.value() <<
"\n";
971 template<
typename _Scalar,
int _BlockAtCompileTime,
int _Options,
typename _StorageIndex>
981 : m_mat(
mat),m_outer(outer),
1007 inline Index rows()
const {
return (m_mat.m_blockSize==
Dynamic) ? (m_mat.m_innerOffset[index()+1] - m_mat.m_innerOffset[index()]) : m_mat.m_blockSize; }
1009 inline Index cols()
const {
return (m_mat.m_blockSize==
Dynamic) ? (m_mat.m_outerOffset[m_outer+1]-m_mat.m_outerOffset[m_outer]) : m_mat.m_blockSize;}
1010 inline operator bool()
const {
return (m_id < m_end); }
1019 template<
typename _Scalar,
int _BlockAtCompileTime,
int _Options,
typename _StorageIndex>
1030 m_id = m_mat.blockInnerIndex(itb.index());
1032 m_end = m_mat.blockInnerIndex(itb.index()+1);
1043 m_id = m_mat.blockInnerIndex(itb.index());
1045 m_end = m_mat.blockInnerIndex(itb.index()+1);
1052 return itb.value().coeff(m_id - m_start, m_offset);
1056 return itb.valueRef().coeff(m_id - m_start, m_offset);
1062 inline operator bool()
const
1079 #endif // EIGEN_SPARSEBLOCKMATRIX_H
Scalar coeff(Index bi) const
Ref< Matrix< typename VectorType::Scalar, RowsAtCompileTime, ColsAtCompileTime > > Scalar
Ref< typename BlockSparseMatrixT::BlockRealScalar > RealScalar
bool isCompressed() const
for compatibility purposes with the SparseMatrix class
Namespace containing all symbols from the Eigen library.
A versatible sparse matrix representation.
BlockSparseMatrixT::Scalar Scalar
void setBlockLayout(const VectorXi &rowBlocks, const VectorXi &colBlocks)
Set the row and column block layouts,.
Ref< Matrix< typename BlockSparseMatrixT::RealScalar, BlockSparseMatrixT::BlockSize, BlockSparseMatrixT::BlockSize > > RealScalar
A versatile sparse matrix representation where each element is a block.
NumTraits< Scalar >::Real RealScalar
InnerIterator & operator++()
BlockSparseMatrixT::Index Index
Scalar coeffRef(Index bi)
internal::ref_selector< BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex > >::type Nested
const BlockSparseMatrixT & m_spblockmat
const BlockSparseMatrix & m_mat
const unsigned int RowMajorBit
void resize(Index brow, Index bcol)
Set the number of rows and columns blocks.
Index blockRowsIndex(Index bi) const
void setFromTriplets(const InputIterator &begin, const InputIterator &end)
Fill values in a matrix from a triplet list.
BlockSparseMatrix< Scalar, BlockSize, IsColMajor ? ColMajor :RowMajor, StorageIndex > PlainObject
const BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, StorageIndex > & m_mat
BlockSparseMatrix(Index brow, Index bcol)
Construct and resize.
Index outerBlocks() const
Matrix< Scalar, _BlockAtCompileTime, _BlockAtCompileTime, IsColMajor ? ColMajor :RowMajor > BlockScalar
const Map< const BlockScalar > value() const
const BlockSparseMatrixT & m_spblockmat
BlockSparseTimeDenseProduct< BlockSparseMatrix, VecType > operator*(const VecType &lhs) const
Ref< typename BlockSparseMatrixT::BlockScalar > Scalar
Index blockPtr(Index id) const
BlockSparseTimeDenseProduct & operator=(const BlockSparseTimeDenseProduct &)
Matrix< RealScalar, _BlockAtCompileTime, _BlockAtCompileTime, IsColMajor ? ColMajor :RowMajor > BlockRealScalar
const BlockSparseMatrixT & m_spblockmat
const Scalar & value() const
Index innerToBlock(Index inner) const
BlockSparseMatrix(const BlockSparseMatrix &other)
Copy-constructor.
static const Similarity3 id
Ref< const Matrix< typename BlockSparseMatrixT::Scalar,(RowsAtCompileTime==1)? 1 :BlockSize,(ColsAtCompileTime==1)? 1 :BlockSize > > Scalar
void scaleAndAddTo(Dest &dest, const typename Rhs::Scalar &alpha) const
Scalar coeff(Index bi, Index j) const
BlockSparseMatrix & operator=(const MatrixType &spmat)
Assignment from a sparse matrix with the same storage order.
Map< const BlockScalar > coeff(Index brow, Index bcol) const
Index blockInnerSize(Index bi) const
BlockSparseTimeDenseProduct(const Lhs &lhs, const Rhs &rhs)
const unsigned int LvalueBit
void sparse_time_dense_product(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
StorageIndex * m_innerOffset
Index nonZerosBlocks() const
void reserve(const Index nonzerosblocks)
Allocate the internal array of pointers to blocks and their inner indices.
BlockInnerIterator(const BlockSparseMatrix &mat, const Index outer)
BlockSparseMatrixT::Index Index
void setBlockStructure(const MatrixType &blockPattern)
Set the nonzero block pattern of the matrix.
BlockVectorView(const BlockSparseMatrixT &spblockmat, const VectorType &vec)
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)
BlockSparseMatrix(const MatrixType &spmat)
Constructor from a sparse matrix.
internal::conditional< _BlockAtCompileTime==Dynamic, Scalar, BlockScalar >::type BlockScalarReturnType
Ref< Matrix< typename BlockSparseMatrixT::Scalar, BlockSparseMatrixT::BlockSize, BlockSparseMatrixT::BlockSize > > Scalar
A matrix or vector expression mapping an existing array of data.
An InnerIterator allows to loop over the element of any matrix expression.
Index blockInnerIndex(Index bi) const
friend void swap(BlockSparseMatrix &first, BlockSparseMatrix &second)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
void setBlockSize(Index blockSize)
set the block size at runtime for fixed-size block layout
Scalar coeff(Index row, Index col)
friend std::ostream & operator<<(std::ostream &s, const BlockSparseMatrix &m)
StorageIndex * innerIndexPtr()
Index blockColsIndex(Index bj) const
StorageIndex * m_outerIndex
BlockSparseMatrixT::Index Index
BlockSparseMatrixT::Index Index
A matrix or vector expression mapping an existing expression.
InnerIterator(const BlockSparseMatrix &mat, Index outer)
Index outerToBlock(Index outer) const
BlockSparseMatrixView(const BlockSparseMatrixT &spblockmat)
Index blockOuterSize(Index bj) const
bool operator()(const Triplet &a, const Triplet &b)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
BlockSparseMatrixT Nested
const StorageIndex * innerIndexPtr() const
Map< BlockScalar > insert(Index brow, Index bcol)
StorageIndex * m_outerOffset
BlockSparseMatrix & operator=(BlockSparseMatrix other)
const StorageIndex * outerIndexPtr() const
Map< BlockScalar > valueRef()
The matrix class, also used for vectors and row-vectors.
BlockScalarReturnType * valuePtr()
Index innerBlocks() const
Scalar coeffRef(Index bi, Index j)
const int InnerRandomAccessPattern
static const EIGEN_DEPRECATED end_t end
BlockVectorReturn(const BlockSparseMatrixT &spblockmat, VectorType &vec)
_StorageIndex StorageIndex
const unsigned int NestByRefBit
InnerIterator(const BlockSparseMatrixView &mat, Index outer)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
StorageIndex * m_blockPtr
StorageIndex * outerIndexPtr()
BlockInnerIterator & operator++()
Scalar coeffRef(Index row, Index col)
Ref< BlockScalar > coeffRef(Index brow, Index bcol)
Iterator::value_type Triplet
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Index blockOuterIndex(Index bj) const
gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:00:46