Eigen  3.2.7
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Block< XprType, BlockRows, BlockCols, InnerPanel > Class Template Reference

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.

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)

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>
using namespace Eigen;
using namespace std;
template<typename Derived>
topLeftCorner(MatrixBase<Derived>& m, int rows, int cols)
{
return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
}
template<typename Derived>
topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols)
{
return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
}
int main(int, char**)
{
cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
cout << "Now the matrix m is:" << endl << m << endl;
return 0;
}

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>
using namespace Eigen;
using namespace std;
template<typename Derived>
topLeft2x2Corner(MatrixBase<Derived>& m)
{
return Eigen::Block<Derived, 2, 2>(m.derived(), 0, 0);
}
template<typename Derived>
topLeft2x2Corner(const MatrixBase<Derived>& m)
{
return Eigen::Block<const Derived, 2, 2>(m.derived(), 0, 0);
}
int main(int, char**)
{
cout << topLeft2x2Corner(4*m) << endl; // calls the const version
topLeft2x2Corner(m) *= 2; // calls the non-const version
cout << "Now the matrix m is:" << endl << m << endl;
return 0;
}

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

Inherits BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, internal::traits< XprType >::StorageKind >.

Public Member Functions

 Block (XprType &xpr, Index i)
 
 Block (XprType &xpr, Index a_startRow, Index a_startCol)
 
 Block (XprType &xpr, Index a_startRow, Index a_startCol, Index blockRows, Index blockCols)
 

Constructor & Destructor Documentation

Block ( XprType &  xpr,
Index  i 
)
inline

Column or Row constructor

Block ( XprType &  xpr,
Index  a_startRow,
Index  a_startCol 
)
inline

Fixed-size constructor

References Eigen::Dynamic.

Block ( XprType &  xpr,
Index  a_startRow,
Index  a_startCol,
Index  blockRows,
Index  blockCols 
)
inline

Dynamic-size constructor

References Eigen::Dynamic.


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