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 TutorialBlockOperationsSyntaxColumnRows - \ref TutorialBlockOperationsSyntaxCorners - \ref TutorialBlockOperationsSyntaxVectors \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). There are two versions, whose syntax is as follows:
\b %Block \b operation | Default 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 matrix.row(i);\endcode | \code matrix.row(i);\endcode |
jth column \link DenseBase::col() * \endlink | \code matrix.col(j);\endcode | \code matrix.col(j);\endcode |
C++ code: \include Tutorial_BlockOperations_colrow.cpp | Output: \verbinclude 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 matrix.topLeftCorner(p,q);\endcode | \code
matrix.topLeftCorner ();\endcode |
Bottom-left p by q block \link DenseBase::bottomLeftCorner() * \endlink | \code matrix.bottomLeftCorner(p,q);\endcode | \code
matrix.bottomLeftCorner ();\endcode |
Top-right p by q block \link DenseBase::topRightCorner() * \endlink | \code matrix.topRightCorner(p,q);\endcode | \code
matrix.topRightCorner ();\endcode |
Bottom-right p by q block \link DenseBase::bottomRightCorner() * \endlink | \code matrix.bottomRightCorner(p,q);\endcode | \code
matrix.bottomRightCorner ();\endcode |
%Block containing the first q rows \link DenseBase::topRows() * \endlink | \code matrix.topRows(q);\endcode | \code
matrix.topRows();\endcode |
%Block containing the last q rows \link DenseBase::bottomRows() * \endlink | \code matrix.bottomRows(q);\endcode | \code
matrix.bottomRows();\endcode |
%Block containing the first p columns \link DenseBase::leftCols() * \endlink | \code matrix.leftCols(p);\endcode | \code
matrix.leftCols ();\endcode |
%Block containing the last q columns \link DenseBase::rightCols() * \endlink | \code matrix.rightCols(q);\endcode | \code
matrix.rightCols();\endcode |
C++ code: \include Tutorial_BlockOperations_corner.cpp | Output: \verbinclude 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 vector.head(n);\endcode | \code
vector.head |
%Block containing the last \p n elements \link DenseBase::tail() * \endlink | \code vector.tail(n);\endcode | \code
vector.tail |
%Block containing \p n elements, starting at position \p i \link DenseBase::segment() * \endlink | \code vector.segment(i,n);\endcode | \code
vector.segment |
C++ code: \include Tutorial_BlockOperations_vector.cpp | Output: \verbinclude Tutorial_BlockOperations_vector.out |