\include Tutorial_ArrayClass_interop.cpp
diff --git a/doc/C04_TutorialBlockOperations.dox b/doc/C04_TutorialBlockOperations.dox
index 70773a463..b45cbfbc8 100644
--- a/doc/C04_TutorialBlockOperations.dox
+++ b/doc/C04_TutorialBlockOperations.dox
@@ -13,21 +13,22 @@ provided that you let your compiler optimize.
\b Table \b of \b contents
- \ref TutorialBlockOperationsUsing
- - \ref TutorialBlockOperationsSyntax
- - \ref TutorialBlockOperationsSyntaxColumnRows
- - \ref TutorialBlockOperationsSyntaxCorners
+ - \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) by using
-the following syntax:
+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 \b version |
+ | \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) |
+ | %Block of size (p,q), starting at (i,j) |
\code
matrix.block(i,j,p,q);\endcode |
\code
@@ -35,7 +36,15 @@ matrix.block (i,j);\endcode |
-Therefore, if we want to print the values of a block inside a matrix we can simply write:
+The default version is a method which takes four arguments. It can always be used. The optimized version
+takes two template arguments (the size of the block) and two normal arguments (the position of the block).
+It can only be used if the size of the block is known at compile time, but it may be faster than the
+non-optimized version, especially if the size of the block is small. Both versions can be used on fixed-size
+and dynamic-size matrices and arrays.
+
+The following program uses the default and optimized versions to print the values of several blocks inside a
+matrix.
+
|
\include Tutorial_BlockOperations_print_block.cpp
|
@@ -44,10 +53,15 @@ Output:
\verbinclude Tutorial_BlockOperations_print_block.out
+In the above example the \link DenseBase::block() .block() \endlink function was employed
+to read the values inside matrix \p m . However, blocks can also be used as lvalues, meaning that you can
+assign to a block.
-In the previous example the \link DenseBase::block() .block() \endlink function was employed
-to read the values inside matrix \p m . Blocks can also be used to perform operations and
-assignments within matrices or arrays of different size:
+This is illustrated in the following example, which uses arrays instead of matrices. The coefficients of the
+5-by-5 array \c n are first all set to 0.6, but then the 3-by-3 block in the middle is set to the values in
+\c m . The penultimate line shows that blocks can be combined with matrices and arrays to create more complex
+expressions. Blocks of an array are an array expression, and thus the multiplication here is coefficient-wise
+multiplication.
|
\include Tutorial_BlockOperations_block_assignment.cpp
@@ -57,55 +71,38 @@ Output:
\verbinclude Tutorial_BlockOperations_block_assignment.out
|
+The \link DenseBase::block() .block() \endlink method is used for general block operations, but there are
+other methods for special cases. These are described in the rest of this page.
-Blocks can also be combined with matrices and arrays to create more complex expressions:
-\code
- MatrixXf m(3,3), n(2,2);
- MatrixXf p(3,3);
-
- m.block(0,0,2,2) = m.block(0,0,2,2) * n + p.block(1,1,2,2);
-\endcode
+\section TutorialBlockOperationsSyntaxColumnRows Columns and rows
-It is important to point out that \link DenseBase::block() .block() \endlink is the
-general case for a block operation but there are many other useful block operations,
-as described in the next section.
-
-\section TutorialBlockOperationsSyntax Block operation syntax
-The following tables show a summary of Eigen's block operations and how they are applied to
-fixed- and dynamic-sized Eigen objects.
-
-\subsection TutorialBlockOperationsSyntaxColumnRows Columns and rows
-Other extremely useful block operations are \link DenseBase::col() .col() \endlink and
-\link DenseBase::row() .row() \endlink which provide access to a
-specific row or column. This is a special case in the sense that the syntax for fixed- and
-dynamic-sized objects is exactly the same:
+Individual columns and rows are special cases of blocks. Eigen provides methods to easily access them:
+\link DenseBase::col() .col() \endlink and \link DenseBase::row() .row()\endlink. There is no syntax variant
+for an optimized version.
-| \b Block \b operation |
+ | \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 |
+matrix.row(i);\endcode
\code
-Matrix3f m;
-std::cout << m.row(i);\endcode |
+matrix.row(i);\endcode
| jth column
\link DenseBase::col() * \endlink |
\code
-MatrixXf m;
-std::cout << m.col(j);\endcode |
+matrix.col(j);\endcode
\code
-Matrix3f m;
-std::cout << m.col(j);\endcode |
+matrix.col(j);\endcode
-A simple example demonstrating these feature follows:
+The argument for \p col() and \p row() is the index of the column or row to be accessed, starting at
+0. Therefore, \p col(0) will access the first column and \p col(1) the second one.
|
C++ code:
@@ -113,94 +110,83 @@ C++ code:
|
Output:
-\include Tutorial_BlockOperations_colrow.out
+\verbinclude Tutorial_BlockOperations_colrow.out
|
-\b NOTE: the argument for \p col() and \p row() is the index of the column or row to be accessed,
-starting at 0. Therefore, \p col(0) will access the first column and \p col(1) the second one.
+\section TutorialBlockOperationsSyntaxCorners Corner-related operations
+Eigen also provides special methods for blocks that are flushed against one of the corners or sides of a
+matrix or array. For instance, \link DenseBase::topLeftCorner() .topLeftCorner() \endlink can be used to refer
+to a block in the top-left corner of a matrix. Use matrix.topLeftCorner(p,q) to access the block
+consisting of the coefficients matrix(i,j) with \c i < \c p and \c j < \c q. As an other
+example, blocks consisting of whole rows flushed against the top side of the matrix can be accessed by
+\link DenseBase::topRows() .topRows() \endlink.
+
+The different possibilities are summarized in the following table:
-\subsection TutorialBlockOperationsSyntaxCorners Corner-related operations
-| \b Block \b operation |
+ | \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 |
+matrix.topLeftCorner(p,q);\endcode
\code
-Matrix3f m;
-std::cout << m.topLeftCorner ();\endcode |
+matrix.topLeftCorner();\endcode
| Bottom-left p by q block
\link DenseBase::bottomLeftCorner() * \endlink |
\code
-MatrixXf m;
-std::cout << m.bottomLeftCorner(p,q);\endcode |
+matrix.bottomLeftCorner(p,q);\endcode
\code
-Matrix3f m;
-std::cout << m.bottomLeftCorner ();\endcode |
+matrix.bottomLeftCorner();\endcode
| Top-right p by q block
\link DenseBase::topRightCorner() * \endlink |
\code
-MatrixXf m;
-std::cout << m.topRightCorner(p,q);\endcode |
+matrix.topRightCorner(p,q);\endcode
\code
-Matrix3f m;
-std::cout << m.topRightCorner ();\endcode |
+matrix.topRightCorner();\endcode
| Bottom-right p by q block
\link DenseBase::bottomRightCorner() * \endlink |
\code
-MatrixXf m;
-std::cout << m.bottomRightCorner(p,q);\endcode |
+matrix.bottomRightCorner(p,q);\endcode
\code
-Matrix3f m;
-std::cout << m.bottomRightCorner ();\endcode |
+matrix.bottomRightCorner();\endcode
-| Block containing the first q rows
+ | | %Block containing the first q rows
\link DenseBase::topRows() * \endlink |
\code
-MatrixXf m;
-std::cout << m.topRows(q);\endcode |
+matrix.topRows(q);\endcode
\code
-Matrix3f m;
-std::cout << m.topRows();\endcode |
+matrix.topRows();\endcode
-| Block containing the last q rows
+ | | %Block containing the last q rows
\link DenseBase::bottomRows() * \endlink |
\code
-MatrixXf m;
-std::cout << m.bottomRows(q);\endcode |
+matrix.bottomRows(q);\endcode
\code
-Matrix3f m;
-std::cout << m.bottomRows();\endcode |
+matrix.bottomRows();\endcode
-| Block containing the first p columns
+ | | %Block containing the first p columns
\link DenseBase::leftCols() * \endlink |
\code
-MatrixXf m;
-std::cout << m.leftCols(p);\endcode |
+matrix.leftCols(p);\endcode
\code
-Matrix3f m;
-std::cout << m.leftCols ();\endcode |
+matrix.leftCols();\endcode
-| Block containing the last q columns
+ | | %Block containing the last q columns
\link DenseBase::rightCols() * \endlink |
\code
-MatrixXf m;
-std::cout << m.rightCols(q);\endcode |
+matrix.rightCols(q);\endcode
\code
-Matrix3f m;
-std::cout << m.rightCols();\endcode |
+matrix.rightCols();\endcode
-
-Here is a simple example showing the power of the operations presented above:
+Here is a simple example illustrating the use of the operations presented above:
|
C++ code:
@@ -208,49 +194,38 @@ C++ code:
|
Output:
-\include Tutorial_BlockOperations_corner.out
+\verbinclude Tutorial_BlockOperations_corner.out
|
+\section TutorialBlockOperationsSyntaxVectors Block operations for vectors
-
-
-
-
-
-\subsection TutorialBlockOperationsSyntaxVectors Block operations for vectors
-Eigen also provides a set of block operations designed specifically for vectors:
+Eigen also provides a set of block operations designed specifically for vectors and one-dimensional arrays:
-| \b Block \b operation |
+ | \b %Block \b operation |
Default version |
Optimized version when the size is known at compile time |
-| Block containing the first \p n elements
+ | | %Block containing the first \p n elements
\link DenseBase::head() * \endlink |
\code
-VectorXf v;
-std::cout << v.head(n);\endcode |
+vector.head(n);\endcode
\code
-Vector3f v;
-std::cout << v.head();\endcode |
+vector.head();\endcode
-| Block containing the last \p n elements
+ | | %Block containing the last \p n elements
\link DenseBase::tail() * \endlink |
\code
-VectorXf v;
-std::cout << v.tail(n);\endcode |
+vector.tail(n);\endcode
\code
-Vector3f m;
-std::cout << v.tail();\endcode |
+vector.tail();\endcode
-| Block containing \p n elements, starting at position \p i
+ | | %Block containing \p n elements, starting at position \p i
\link DenseBase::segment() * \endlink |
\code
-VectorXf v;
-std::cout << v.segment(i,n);\endcode |
+vector.segment(i,n);\endcode
\code
-Vector3f m;
-std::cout << v.segment(i);\endcode |
+vector.segment(i);\endcode
@@ -262,7 +237,7 @@ C++ code:
|
Output:
-\include Tutorial_BlockOperations_vector.out
+\verbinclude Tutorial_BlockOperations_vector.out
|