11#ifndef EIGEN_SPARSEBLOCKMATRIX_H
12#define EIGEN_SPARSEBLOCKMATRIX_H
54template<
typename _Scalar,
int _BlockAtCompileTime=Dynamic,
int _Options=ColMajor,
typename _StorageIndex=
int>
class BlockSparseMatrix;
56template<
typename BlockSparseMatrixT>
class BlockSparseMatrixView;
59template<
typename _Scalar,
int _BlockAtCompileTime,
int _Options,
typename _Index>
77template<
typename BlockSparseMatrixT>
86template<
typename Iterator,
bool IsColMajor>
89 typedef typename Iterator::value_type
Triplet;
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()));
101template<
typename BlockSparseMatrixT>
107 typedef typename BlockSparseMatrixT::Index
Index;
110 Flags = BlockSparseMatrixT::Options,
157template<
typename BlockSparseMatrixT,
typename VectorType>
165 Flags = VectorType::Flags
168 typedef typename BlockSparseMatrixT::Index
Index;
185 return m_vec.middleRows(startRow, rowSize);
191 return m_vec.block(startRow,
j, rowSize, 1);
202template<
typename BlockSparseMatrixT,
typename VectorType>
209 Flags = VectorType::Flags
212 typedef typename BlockSparseMatrixT::Index
Index;
225 return m_vec.middleRows(startRow, rowSize);
231 return m_vec.block(startRow,
j, rowSize, 1);
240template<
typename Lhs,
typename Rhs>
245template<
typename BlockSparseMatrixT,
typename VecType>
250 typedef typename BlockSparseMatrixT::Scalar
Scalar;
251 typedef typename BlockSparseMatrixT::Index
Index;
263template<
typename Lhs,
typename Rhs>
265 :
public ProductBase<BlockSparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs>
283template<
typename _Scalar,
int _BlockAtCompileTime,
int _Options,
typename _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;
925 s <<
"("<<itb.
row() <<
", " << itb.
col() <<
")\n";
971template<
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); }
1019template<
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
Matrix3f m
Definition AngleAxis_mimic_euler.cpp:1
ArrayXXi a
Definition Array_initializer_list_23_cxx11.cpp:1
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition StaticAssert.h:127
MatrixXf mat
Definition Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Scalar * b
Definition benchVecAdd.cpp:17
MatrixXf MatrixType
Definition benchmark-blocking-sizes.cpp:52
Definition BlockSparseMatrix.h:144
InnerIterator(const BlockSparseMatrixView &mat, Index outer)
Definition BlockSparseMatrix.h:146
Definition BlockSparseMatrix.h:103
Index outerSize() const
Definition BlockSparseMatrix.h:122
BlockSparseMatrixView(const BlockSparseMatrixT &spblockmat)
Definition BlockSparseMatrix.h:118
BlockSparseMatrixT Nested
Definition BlockSparseMatrix.h:108
@ MaxColsAtCompileTime
Definition BlockSparseMatrix.h:114
@ Flags
Definition BlockSparseMatrix.h:110
@ RowsAtCompileTime
Definition BlockSparseMatrix.h:112
@ MaxRowsAtCompileTime
Definition BlockSparseMatrix.h:115
@ ColsAtCompileTime
Definition BlockSparseMatrix.h:113
@ Options
Definition BlockSparseMatrix.h:111
Ref< typename BlockSparseMatrixT::BlockScalar > Scalar
Definition BlockSparseMatrix.h:105
Scalar coeff(Index row, Index col)
Definition BlockSparseMatrix.h:134
BlockSparseMatrixT::Index Index
Definition BlockSparseMatrix.h:107
Index rows() const
Definition BlockSparseMatrix.h:130
Scalar coeffRef(Index row, Index col)
Definition BlockSparseMatrix.h:138
const BlockSparseMatrixT & m_spblockmat
Definition BlockSparseMatrix.h:153
Index cols() const
Definition BlockSparseMatrix.h:126
Ref< typename BlockSparseMatrixT::BlockRealScalar > RealScalar
Definition BlockSparseMatrix.h:106
Definition BlockSparseMatrix.h:973
Index outer() const
Definition BlockSparseMatrix.h:1001
Index rows() const
Definition BlockSparseMatrix.h:1007
Index m_id
Definition BlockSparseMatrix.h:1015
Index cols() const
Definition BlockSparseMatrix.h:1009
BlockInnerIterator(const BlockSparseMatrix &mat, const Index outer)
Definition BlockSparseMatrix.h:980
const Map< const BlockScalar > value() const
Definition BlockSparseMatrix.h:989
Index m_end
Definition BlockSparseMatrix.h:1016
Index col() const
Definition BlockSparseMatrix.h:1005
Map< BlockScalar > valueRef()
Definition BlockSparseMatrix.h:994
BlockInnerIterator & operator++()
Definition BlockSparseMatrix.h:987
Index index() const
Definition BlockSparseMatrix.h:1000
const Index m_outer
Definition BlockSparseMatrix.h:1014
Index row() const
Definition BlockSparseMatrix.h:1003
const BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, StorageIndex > & m_mat
Definition BlockSparseMatrix.h:1013
Definition BlockSparseMatrix.h:1021
Index m_end
Definition BlockSparseMatrix.h:1074
const Index m_outerB
Definition BlockSparseMatrix.h:1069
InnerIterator & operator++()
Definition BlockSparseMatrix.h:1035
const Index m_outer
Definition BlockSparseMatrix.h:1068
InnerIterator(const BlockSparseMatrix &mat, Index outer)
Definition BlockSparseMatrix.h:1023
Index col() const
Definition BlockSparseMatrix.h:1060
BlockInnerIterator itb
Definition BlockSparseMatrix.h:1070
Index m_start
Definition BlockSparseMatrix.h:1072
Scalar & valueRef()
Definition BlockSparseMatrix.h:1054
Index m_id
Definition BlockSparseMatrix.h:1073
Index row() const
Definition BlockSparseMatrix.h:1061
const Index m_offset
Definition BlockSparseMatrix.h:1071
Index index() const
Definition BlockSparseMatrix.h:1058
const BlockSparseMatrix & m_mat
Definition BlockSparseMatrix.h:1067
const Scalar & value() const
Definition BlockSparseMatrix.h:1050
Index outer() const
Definition BlockSparseMatrix.h:1059
A versatile sparse matrix representation where each element is a block.
Definition BlockSparseMatrix.h:285
friend std::ostream & operator<<(std::ostream &s, const BlockSparseMatrix &m)
Definition BlockSparseMatrix.h:918
const StorageIndex * innerIndexPtr() const
Definition BlockSparseMatrix.h:867
Index blockPtr(Index id) const
Definition BlockSparseMatrix.h:936
void setBlockSize(Index blockSize)
set the block size at runtime for fixed-size block layout
Definition BlockSparseMatrix.h:549
BlockSparseMatrix(const MatrixType &spmat)
Constructor from a sparse matrix.
Definition BlockSparseMatrix.h:389
Index innerSize() const
Definition BlockSparseMatrix.h:753
Ref< BlockScalar > coeffRef(Index brow, Index bcol)
Definition BlockSparseMatrix.h:806
Index nonZeros() const
Definition BlockSparseMatrix.h:862
void reserve(const Index nonzerosblocks)
Allocate the internal array of pointers to blocks and their inner indices.
Definition BlockSparseMatrix.h:596
BlockSparseMatrix(Index brow, Index bcol)
Construct and resize.
Definition BlockSparseMatrix.h:320
StorageIndex * m_indices
Definition BlockSparseMatrix.h:966
bool isCompressed() const
for compatibility purposes with the SparseMatrix class
Definition BlockSparseMatrix.h:872
_StorageIndex StorageIndex
Definition BlockSparseMatrix.h:289
void setBlockStructure(const MatrixType &blockPattern)
Set the nonzero block pattern of the matrix.
Definition BlockSparseMatrix.h:498
NumTraits< Scalar >::Real RealScalar
Definition BlockSparseMatrix.h:288
Index m_innerBSize
Definition BlockSparseMatrix.h:958
StorageIndex * m_outerIndex
Definition BlockSparseMatrix.h:967
Index m_nonzeros
Definition BlockSparseMatrix.h:963
Index blockInnerIndex(Index bi) const
Definition BlockSparseMatrix.h:893
Matrix< Scalar, _BlockAtCompileTime, _BlockAtCompileTime, IsColMajor ? ColMajor :RowMajor > BlockScalar
Definition BlockSparseMatrix.h:303
Index innerToBlock(Index inner) const
Definition BlockSparseMatrix.h:791
Index blockOuterSize(Index bj) const
Definition BlockSparseMatrix.h:903
StorageIndex * innerIndexPtr()
Definition BlockSparseMatrix.h:866
BlockSparseMatrix(const BlockSparseMatrix &other)
Copy-constructor.
Definition BlockSparseMatrix.h:331
~BlockSparseMatrix()
Definition BlockSparseMatrix.h:373
Index blockRows() const
Definition BlockSparseMatrix.h:765
Index outerBlocks() const
Definition BlockSparseMatrix.h:775
@ Flags
Definition BlockSparseMatrix.h:294
@ IsVectorAtCompileTime
Definition BlockSparseMatrix.h:300
@ MaxColsAtCompileTime
Definition BlockSparseMatrix.h:299
@ BlockSize
Definition BlockSparseMatrix.h:295
@ MaxRowsAtCompileTime
Definition BlockSparseMatrix.h:298
@ RowsAtCompileTime
Definition BlockSparseMatrix.h:296
@ Options
Definition BlockSparseMatrix.h:293
@ IsColMajor
Definition BlockSparseMatrix.h:301
@ ColsAtCompileTime
Definition BlockSparseMatrix.h:297
Index blockColsIndex(Index bj) const
Definition BlockSparseMatrix.h:884
BlockSparseMatrix< Scalar, BlockSize, IsColMajor ? ColMajor :RowMajor, StorageIndex > PlainObject
Definition BlockSparseMatrix.h:306
Index blockCols() const
Definition BlockSparseMatrix.h:770
Index m_outerBSize
Definition BlockSparseMatrix.h:959
Map< BlockScalar > insert(Index brow, Index bcol)
Index m_blockSize
Definition BlockSparseMatrix.h:968
Index blockOuterIndex(Index bj) const
Definition BlockSparseMatrix.h:889
StorageIndex * m_blockPtr
Definition BlockSparseMatrix.h:965
BlockSparseMatrix()
Definition BlockSparseMatrix.h:309
Index nonZerosBlocks() const
Definition BlockSparseMatrix.h:860
internal::ref_selector< BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex > >::type Nested
Definition BlockSparseMatrix.h:290
BlockSparseMatrix & operator=(const MatrixType &spmat)
Assignment from a sparse matrix with the same storage order.
Definition BlockSparseMatrix.h:405
Index rows() const
Definition BlockSparseMatrix.h:738
Index innerBlocks() const
Definition BlockSparseMatrix.h:776
Index outerSize() const
Definition BlockSparseMatrix.h:759
Index m_nonzerosblocks
Definition BlockSparseMatrix.h:962
_Scalar Scalar
Definition BlockSparseMatrix.h:287
Matrix< RealScalar, _BlockAtCompileTime, _BlockAtCompileTime, IsColMajor ? ColMajor :RowMajor > BlockRealScalar
Definition BlockSparseMatrix.h:304
Index outerToBlock(Index outer) const
Definition BlockSparseMatrix.h:779
void setFromTriplets(const InputIterator &begin, const InputIterator &end)
Fill values in a matrix from a triplet list.
Definition BlockSparseMatrix.h:631
Index cols() const
Definition BlockSparseMatrix.h:747
friend void swap(BlockSparseMatrix &first, BlockSparseMatrix &second)
Definition BlockSparseMatrix.h:350
StorageIndex * m_innerOffset
Definition BlockSparseMatrix.h:960
void setBlockLayout(const VectorXi &rowBlocks, const VectorXi &colBlocks)
Set the row and column block layouts,.
Definition BlockSparseMatrix.h:563
Index blockRowsIndex(Index bi) const
Definition BlockSparseMatrix.h:876
internal::conditional< _BlockAtCompileTime==Dynamic, Scalar, BlockScalar >::type BlockScalarReturnType
Definition BlockSparseMatrix.h:305
BlockSparseTimeDenseProduct< BlockSparseMatrix, VecType > operator*(const VecType &lhs) const
Definition BlockSparseMatrix.h:854
Scalar * m_values
Definition BlockSparseMatrix.h:964
void resize(Index brow, Index bcol)
Set the number of rows and columns blocks.
Definition BlockSparseMatrix.h:538
StorageIndex * outerIndexPtr()
Definition BlockSparseMatrix.h:868
Index blockInnerSize(Index bi) const
Definition BlockSparseMatrix.h:899
BlockScalarReturnType * valuePtr()
Definition BlockSparseMatrix.h:864
Map< const BlockScalar > coeff(Index brow, Index bcol) const
Definition BlockSparseMatrix.h:832
StorageIndex * m_outerOffset
Definition BlockSparseMatrix.h:961
BlockSparseMatrix & operator=(BlockSparseMatrix other)
Definition BlockSparseMatrix.h:365
const StorageIndex * outerIndexPtr() const
Definition BlockSparseMatrix.h:869
Definition BlockSparseMatrix.h:266
void scaleAndAddTo(Dest &dest, const typename Rhs::Scalar &alpha) const
Definition BlockSparseMatrix.h:273
Definition BlockSparseMatrix.h:204
Ref< Matrix< typename VectorType::Scalar, RowsAtCompileTime, ColsAtCompileTime > > Scalar
Definition BlockSparseMatrix.h:211
Scalar coeffRef(Index bi)
Definition BlockSparseMatrix.h:221
BlockSparseMatrixT::Index Index
Definition BlockSparseMatrix.h:212
BlockVectorReturn(const BlockSparseMatrixT &spblockmat, VectorType &vec)
Definition BlockSparseMatrix.h:214
const BlockSparseMatrixT & m_spblockmat
Definition BlockSparseMatrix.h:235
VectorType & m_vec
Definition BlockSparseMatrix.h:236
@ Flags
Definition BlockSparseMatrix.h:209
@ ColsAtCompileTime
Definition BlockSparseMatrix.h:207
@ RowsAtCompileTime
Definition BlockSparseMatrix.h:208
Index size() const
Definition BlockSparseMatrix.h:217
Scalar coeffRef(Index bi, Index j)
Definition BlockSparseMatrix.h:227
Definition BlockSparseMatrix.h:159
BlockVectorView(const BlockSparseMatrixT &spblockmat, const VectorType &vec)
Definition BlockSparseMatrix.h:170
@ Flags
Definition BlockSparseMatrix.h:165
@ ColsAtCompileTime
Definition BlockSparseMatrix.h:163
@ BlockSize
Definition BlockSparseMatrix.h:162
@ RowsAtCompileTime
Definition BlockSparseMatrix.h:164
Index size() const
Definition BlockSparseMatrix.h:177
BlockSparseMatrixT::Index Index
Definition BlockSparseMatrix.h:168
Index cols() const
Definition BlockSparseMatrix.h:173
const BlockSparseMatrixT & m_spblockmat
Definition BlockSparseMatrix.h:194
Scalar coeff(Index bi) const
Definition BlockSparseMatrix.h:181
const VectorType & m_vec
Definition BlockSparseMatrix.h:195
Scalar coeff(Index bi, Index j) const
Definition BlockSparseMatrix.h:187
An InnerIterator allows to loop over the element of any matrix expression.
Definition CoreIterators.h:34
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
A matrix or vector expression mapping an existing expression.
Definition Ref.h:283
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:28
A versatible sparse matrix representation.
Definition SparseMatrix.h:98
Definition TensorRef.h:81
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
Definition gnuplot_common_settings.hh:64
const unsigned int LvalueBit
Definition Constants.h:144
const unsigned int RowMajorBit
Definition Constants.h:66
RealScalar s
Definition level1_cplx_impl.h:126
RealScalar alpha
Definition level1_cplx_impl.h:147
void sparse_time_dense_product(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
Definition SparseDenseProduct.h:169
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
const unsigned int NestByRefBit
Definition Constants.h:169
const int InnerRandomAccessPattern
Definition SparseUtil.h:48
const int Dynamic
Definition Constants.h:22
Definition BandTriangularSolver.h:13
real function second()
SECOND returns nothing
Definition second_NONE.f:39
Definition Constants.h:507
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:39
Definition Constants.h:522
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233
Definition Constants.h:510
Definition BlockSparseMatrix.h:88
bool operator()(const Triplet &a, const Triplet &b)
Definition BlockSparseMatrix.h:90
Iterator::value_type Triplet
Definition BlockSparseMatrix.h:89
Ref< Matrix< typename BlockSparseMatrixT::Scalar, BlockSparseMatrixT::BlockSize, BlockSparseMatrixT::BlockSize > > Scalar
Definition BlockSparseMatrix.h:80
Ref< Matrix< typename BlockSparseMatrixT::RealScalar, BlockSparseMatrixT::BlockSize, BlockSparseMatrixT::BlockSize > > RealScalar
Definition BlockSparseMatrix.h:81
MatrixXpr XprKind
Definition BlockSparseMatrix.h:65
_Scalar Scalar
Definition BlockSparseMatrix.h:62
_Index Index
Definition BlockSparseMatrix.h:63
Sparse StorageKind
Definition BlockSparseMatrix.h:64
Dense StorageKind
Definition BlockSparseMatrix.h:248
BlockSparseMatrixT::Index Index
Definition BlockSparseMatrix.h:251
MatrixXpr XprKind
Definition BlockSparseMatrix.h:249
BlockSparseMatrixT::Scalar Scalar
Definition BlockSparseMatrix.h:250
Definition ForwardDeclarations.h:17
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2