Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel > Class Template Reference

Expression of a fixed-size or dynamic-size block. More...

+ Inheritance diagram for Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >:

Public Types

typedef Impl Base
 
typedef internal::remove_all_t< XprType > NestedExpression
 

Public Member Functions

 Block (XprType &xpr, Index i)
 
 Block (XprType &xpr, Index startRow, Index startCol)
 
 Block (XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
 

Private Types

typedef BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits< XprType >::StorageKind > Impl
 

Detailed Description

template<typename XprType, int BlockRows, int BlockCols, bool InnerPanel>
class Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >

Expression of a fixed-size or dynamic-size block.

Template Parameters
XprTypethe type of the expression in which we are taking a block
BlockRowsthe number of rows of the block we are taking at compile time (optional)
BlockColsthe number of columns of the block we are taking at compile time (optional)
InnerPanelis true, if the block maps to a set of rows of a row major matrix or to set of columns of a column major matrix (optional). The parameter allows to determine at compile time whether aligned access is possible on the block expression.

This class represents an expression of either a fixed-size or dynamic-size block. It is the return type of DenseBase::block(Index,Index,Index,Index) and DenseBase::block<int,int>(Index,Index) and most of the time this is the only way it is used.

However, if you want to directly maniputate block expressions, for instance if you want to write a function returning such an expression, you will need to use this class.

Here is an example illustrating the dynamic case:

#include <Eigen/Core>
#include <iostream>
template<typename Derived>
{
return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
}
template<typename Derived>
{
return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
}
int main(int, char**)
{
std::cout << topLeftCorner(4*m, 2, 3) << std::endl; // calls the const version
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
std::cout << "Now the matrix m is:" << std::endl << m << std::endl;
return 0;
}
Matrix3f m
EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL FixedBlockXpr<...,... >::Type topLeftCorner(NRowsType cRows, NColsType cCols)
Definition: BlockMethods.h:249
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:107
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
static const IdentityReturnType Identity()
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
int main(int, char **)
Definition: class_Block.cpp:18

Output:

4 0 0
0 4 0
Now the matrix m is:
5 0 0 0
0 5 0 0
0 0 1 0
0 0 0 1
Note
Even though this expression has dynamic size, in the case where XprType has fixed size, this expression inherits a fixed maximal size which means that evaluating it does not cause a dynamic memory allocation.

Here is an example illustrating the fixed-size case:

#include <Eigen/Core>
#include <iostream>
template<typename Derived>
{
return Eigen::Block<Derived, 2, 2>(m.derived(), 0, 0);
}
template<typename Derived>
{
return Eigen::Block<const Derived, 2, 2>(m.derived(), 0, 0);
}
int main(int, char**)
{
std::cout << topLeft2x2Corner(4*m) << std::endl; // calls the const version
topLeft2x2Corner(m) *= 2; // calls the non-const version
std::cout << "Now the matrix m is:" << std::endl << m << std::endl;
return 0;
}
Eigen::Block< Derived, 2, 2 > topLeft2x2Corner(Eigen::MatrixBase< Derived > &m)

Output:

4 0
0 4
Now the matrix m is:
2 0 0
0 2 0
0 0 1
See also
DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock

Definition at line 105 of file Block.h.

Member Typedef Documentation

◆ Base

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
typedef Impl Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Base

Definition at line 111 of file Block.h.

◆ Impl

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Impl
private

Definition at line 108 of file Block.h.

◆ NestedExpression

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
typedef internal::remove_all_t<XprType> Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::NestedExpression

Definition at line 115 of file Block.h.

Constructor & Destructor Documentation

◆ Block() [1/3]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Block ( XprType &  xpr,
Index  i 
)
inline

Column or Row constructor

Definition at line 120 of file Block.h.

120  : Impl(xpr,i)
121  {
122  eigen_assert( (i>=0) && (
123  ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
124  ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
125  }
#define eigen_assert(x)
Definition: Macros.h:902
BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits< XprType >::StorageKind > Impl
Definition: Block.h:108

◆ Block() [2/3]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Block ( XprType &  xpr,
Index  startRow,
Index  startCol 
)
inline

Fixed-size constructor

Definition at line 130 of file Block.h.

131  : Impl(xpr, startRow, startCol)
132  {
133  EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
134  eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows()
135  && startCol >= 0 && BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
136  }
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
const int Dynamic
Definition: Constants.h:24

◆ Block() [3/3]

template<typename XprType , int BlockRows, int BlockCols, bool InnerPanel>
Eigen::Block< XprType, BlockRows, BlockCols, InnerPanel >::Block ( XprType &  xpr,
Index  startRow,
Index  startCol,
Index  blockRows,
Index  blockCols 
)
inline

Dynamic-size constructor

Definition at line 141 of file Block.h.

144  : Impl(xpr, startRow, startCol, blockRows, blockCols)
145  {
146  eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==blockRows)
147  && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==blockCols));
148  eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows
149  && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols);
150  }

The documentation for this class was generated from the following file: