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>
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()));
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