namespace Eigen { /** \page TutorialBlockOperations Tutorial page 4 - %Block operations \ingroup Tutorial \li \b Previous: \ref TutorialArrayClass \li \b Next: \ref TutorialAdvancedInitialization This tutorial page explains the essentials of block operations. A block is a rectangular part of a matrix or array. Blocks expressions can be used both as rvalues and as lvalues. As usual with Eigen expressions, this abstraction has zero runtime cost provided that you let your compiler optimize. \b Table \b of \b contents - \ref TutorialBlockOperationsUsing - \ref TutorialBlockOperationsSyntax - \ref TutorialBlockOperationsSyntaxColumnRows - \ref TutorialBlockOperationsSyntaxCorners \section TutorialBlockOperationsUsing Using block operations The most general block operation in Eigen is called \link DenseBase::block() .block() \endlink. This function returns a block of size (p,q) whose origin is at (i,j) by using the following syntax:
\b Block \b operation | Default \b version | Optimized version when the size is known at compile time |
Block of size (p,q), starting at (i,j) | \code matrix.block(i,j,p,q);\endcode | \code
matrix.block (i,j);\endcode |
\include Tutorial_BlockOperations_print_block.cpp | Output: \verbinclude Tutorial_BlockOperations_print_block.out |
\include Tutorial_BlockOperations_block_assignment.cpp | Output: \verbinclude Tutorial_BlockOperations_block_assignment.out |
\b Block \b operation | Default version | Optimized version when the size is known at compile time |
ith row \link DenseBase::row() * \endlink | \code MatrixXf m; std::cout << m.row(i);\endcode | \code Matrix3f m; std::cout << m.row(i);\endcode |
jth column \link DenseBase::col() * \endlink | \code MatrixXf m; std::cout << m.col(j);\endcode | \code Matrix3f m; std::cout << m.col(j);\endcode |
C++ code: \include Tutorial_BlockOperations_colrow.cpp | Output: \include Tutorial_BlockOperations_colrow.out |
\b Block \b operation | Default version | Optimized version when the size is known at compile time |
Top-left p by q block \link DenseBase::topLeftCorner() * \endlink | \code MatrixXf m; std::cout << m.topLeftCorner(p,q);\endcode | \code
Matrix3f m;
std::cout << m.topLeftCorner ();\endcode |
Bottom-left p by q block \link DenseBase::bottomLeftCorner() * \endlink | \code MatrixXf m; std::cout << m.bottomLeftCorner(p,q);\endcode | \code
Matrix3f m;
std::cout << m.bottomLeftCorner ();\endcode |
Top-right p by q block \link DenseBase::topRightCorner() * \endlink | \code MatrixXf m; std::cout << m.topRightCorner(p,q);\endcode | \code
Matrix3f m;
std::cout << m.topRightCorner ();\endcode |
Bottom-right p by q block \link DenseBase::bottomRightCorner() * \endlink | \code MatrixXf m; std::cout << m.bottomRightCorner(p,q);\endcode | \code
Matrix3f m;
std::cout << m.bottomRightCorner ();\endcode |
Block containing the first q rows \link DenseBase::topRows() * \endlink | \code MatrixXf m; std::cout << m.topRows(q);\endcode | \code
Matrix3f m;
std::cout << m.topRows();\endcode |
Block containing the last q rows \link DenseBase::bottomRows() * \endlink | \code MatrixXf m; std::cout << m.bottomRows(q);\endcode | \code
Matrix3f m;
std::cout << m.bottomRows();\endcode |
Block containing the first p columns \link DenseBase::leftCols() * \endlink | \code MatrixXf m; std::cout << m.leftCols(p);\endcode | \code
Matrix3f m;
std::cout << m.leftCols ();\endcode |
Block containing the last q columns \link DenseBase::rightCols() * \endlink | \code MatrixXf m; std::cout << m.rightCols(q);\endcode | \code
Matrix3f m;
std::cout << m.rightCols();\endcode |
C++ code: \include Tutorial_BlockOperations_corner.cpp | Output: \include Tutorial_BlockOperations_corner.out |
\b Block \b operation | Default version | Optimized version when the size is known at compile time |
Block containing the first \p n elements \link DenseBase::head() * \endlink | \code VectorXf v; std::cout << v.head(n);\endcode | \code
Vector3f v;
std::cout << v.head |
Block containing the last \p n elements \link DenseBase::tail() * \endlink | \code VectorXf v; std::cout << v.tail(n);\endcode | \code
Vector3f m;
std::cout << v.tail |
Block containing \p n elements, starting at position \p i \link DenseBase::segment() * \endlink | \code VectorXf v; std::cout << v.segment(i,n);\endcode | \code
Vector3f m;
std::cout << v.segment |
C++ code: \include Tutorial_BlockOperations_vector.cpp | Output: \include Tutorial_BlockOperations_vector.out |