30 template <
typename MatrixType,
bool isConst = false>
34 typedef gsEigen::Block<MatrixType> block_t ;
35 typedef gsEigen::Block<MatrixType> * block_ptr_t;
37 typedef gsEigen::Matrix<index_t,gsEigen::Dynamic, 1, gsEigen::ColMajor> Vector_t;
54 const Vector_t & rowSizes,
55 const Vector_t & colSizes)
56 : m_rowSize(rowSizes.size()),
57 m_colSize(colSizes.size())
60 colSizes.sum() == matrix.cols() ,
61 "Invalid block structure.");
67 m_blocks.reserve(m_rowSize*m_colSize);
70 for (
index_t j = 0; j<m_colSize; ++j )
73 for (
index_t i = 0; i<m_rowSize; ++i )
75 tmp =
new block_t( matrix.block(
77 rowSizes[i], colSizes[j])
80 m_blocks.push_back(tmp);
98 const Vector_t & rowSizes)
99 : m_rowSize(rowSizes.size()),
103 "Invalid block structure.");
109 m_blocks.reserve(m_rowSize*m_colSize);
110 const index_t cols = matrix.cols();
113 for (
index_t i = 0; i<m_rowSize; ++i )
115 tmp =
new block_t( matrix.block(row, 0, rowSizes[i], cols ) );
117 m_blocks.push_back(tmp);
128 m_blocks.push_back(
new block_t(matrix.topRows(matrix.rows())) );
136 m_rowSize = other.m_rowSize;
137 m_colSize = other.m_colSize;
141 for (
typename std::vector<block_ptr_t>::const_iterator it
142 = other.m_blocks.begin(); it != other.m_blocks.end(); ++it )
144 tmp =
new block_t(**it);
145 m_blocks.push_back(tmp);
169 "Invalid block requested.");
171 return *m_blocks[j*m_rowSize+i];
179 m_blocks.swap(other.m_blocks);
180 m_rowSize = other.m_rowSize;
181 m_colSize = other.m_colSize;
188 template<
typename OtherDerived>
192 "Assign to invalid block requested.");
195 *m_blocks[j*m_colSize+i] = other;
201 os<<
"Matrix block-view size: "<< mv.m_rowSize <<
"x"<< mv.m_colSize
202 <<
" blocks. Structure:\n";
204 for (
index_t i = 0; i<mv.m_rowSize; ++i )
206 for (
index_t j = 0; j<mv.m_colSize; ++j )
208 block_t & bl = mv(i,j);
209 os<< bl.rows() <<
"x"<<bl.cols() <<
" ";
219 std::vector<block_ptr_t> m_blocks;
gsMatrixBlockView(MatrixType &matrix, const Vector_t &rowSizes, const Vector_t &colSizes)
Creates a block-view of the given matrix.
Definition: gsMatrixBlockView.h:53
gsMatrixBlockView(MatrixType &matrix, const Vector_t &rowSizes)
Creates a block-view of the given matrix, using only one column piece.
Definition: gsMatrixBlockView.h:97
#define index_t
Definition: gsConfig.h:32
size_t numColBlocks() const
Returns the number of col-blocks.
Definition: gsMatrixBlockView.h:163
gsMatrixBlockView(const MatrixType &matrix)
Combatibility constuctor giving the matrix as a block.
Definition: gsMatrixBlockView.h:124
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
size_t numRowBlocks() const
Returns the number of row-blocks.
Definition: gsMatrixBlockView.h:160
friend std::ostream & operator<<(std::ostream &os, const gsMatrixBlockView &mv)
Prints the block structure.
Definition: gsMatrixBlockView.h:199
block_t & operator()(index_t i, index_t j=0) const
Returns the block indexed i (row) and j (column)
Definition: gsMatrixBlockView.h:166
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
void assign(index_t i, index_t j, const gsEigen::EigenBase< OtherDerived > &other)
Overwrites the contents of block (i,j) with matrix other.
Definition: gsMatrixBlockView.h:189
Represents a block-view of the given matrix.
Definition: gsMatrixBlockView.h:31
size_t numBlocks() const
Returns the number of blocks.
Definition: gsMatrixBlockView.h:157
gsMatrixBlockView(const gsMatrixBlockView &other)
Copy constructor.
Definition: gsMatrixBlockView.h:132