mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-30 17:40:05 +08:00
Fix name clash in "m.block(i,j,m,n)" where m has two meanings.
Fix simple typos in tutorial.
This commit is contained in:
parent
cf3616b2c0
commit
3070164525
@ -192,7 +192,7 @@ loops. Internally, a fixed-size Eigen matrix is just a plain static array, i.e.
|
||||
\code Matrix4f mymatrix; \endcode
|
||||
really amounts to just doing
|
||||
\code float mymatrix[16]; \endcode
|
||||
so this really has zero runtime cost. By constrast, the array of a dynamic-size matrix
|
||||
so this really has zero runtime cost. By contrast, the array of a dynamic-size matrix
|
||||
is always allocated on the heap, so doing
|
||||
\code MatrixXf mymatrix(rows,columns); \endcode
|
||||
amounts to doing
|
||||
@ -240,10 +240,10 @@ Matrix<typename Scalar,
|
||||
Eigen defines the following Matrix typedefs:
|
||||
\li MatrixNT for Matrix<T, N, N>. For example, MatrixXi for Matrix<int, Dynamic, Dynamic>.
|
||||
\li VectorNT for Matrix<T, N, 1>. For example, Vector2f for Matrix<float, 2, 1>.
|
||||
\li MatrixNT for Matrix<T, 1, N>. For example, RowVector3d for Matrix<double, 1, 3>.
|
||||
\li RowVectorNT for Matrix<T, 1, N>. For example, RowVector3d for Matrix<double, 1, 3>.
|
||||
|
||||
Where:
|
||||
\li N can be any one of \c 2,\c 3,\c 4, or \c Dynamic.
|
||||
\li N can be any one of \c 2,\c 3,\c 4, or \c d (meaning \c Dynamic).
|
||||
\li T can be any one of \c i (meaning int), \c f (meaning float), \c d (meaning double),
|
||||
\c cf (meaning complex<float>), or \c cd (meaning complex<double>). The fact that typedefs are only
|
||||
defined for these 5 types doesn't mean that they are the only supported scalar types. For example,
|
||||
@ -253,4 +253,4 @@ Where:
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ linear-algebraic operations. For example, \c matrix1 \c * \c matrix2 means matri
|
||||
and \c vector \c + \c scalar is just not allowed. If you want to perform all kinds of array operations,
|
||||
not linear algebra, see \ref TutorialArrayClass "next page".
|
||||
|
||||
\section TutorialArithmeticAddSub Addition and substraction
|
||||
\section TutorialArithmeticAddSub Addition and subtraction
|
||||
|
||||
The left hand side and right hand side must, of course, have the same numbers of rows and of columns. They must
|
||||
also have the same \c Scalar type, as Eigen doesn't do automatic type promotion. The operators at hand here are:
|
||||
@ -67,7 +67,7 @@ VectorXf a(50), b(50), c(50), d(50);
|
||||
...
|
||||
a = 3*b + 4*c + 5*d;
|
||||
\endcode
|
||||
Eigen compiles it to just one for loop, so that the arrays are traversed only once. Simplyfying (e.g. ignoring
|
||||
Eigen compiles it to just one for loop, so that the arrays are traversed only once. Simplifying (e.g. ignoring
|
||||
SIMD optimizations), this loop looks like this:
|
||||
\code
|
||||
for(int i = 0; i < 50; ++i)
|
||||
@ -124,7 +124,7 @@ introducing a temporary here, so it will compile \c m=m*m as:
|
||||
tmp = m*m;
|
||||
m = tmp;
|
||||
\endcode
|
||||
If you know your matrix product can be safely evluated into the destination matrix without aliasing issue, then you can use the \c nolias() function to avoid the temporary, e.g.:
|
||||
If you know your matrix product can be safely evaluated into the destination matrix without aliasing issue, then you can use the \c noalias() function to avoid the temporary, e.g.:
|
||||
\code
|
||||
c.noalias() += a * b;
|
||||
\endcode
|
||||
|
@ -19,7 +19,7 @@ This tutorial explains the essentials of Block operations together with many exa
|
||||
\section TutorialBlockOperationsWhatIs What are Block operations?
|
||||
Block operations are a set of functions that provide an easy way to access a set of coefficients
|
||||
inside a \b Matrix or \link ArrayBase Array \endlink. A typical example is accessing a single row or
|
||||
column within a given matrix, as well as extracting a sub-matrix from the later.
|
||||
column within a given matrix, as well as extracting a sub-matrix from the latter.
|
||||
|
||||
Blocks are highly flexible and can be used both as \b rvalues and \b lvalues in expressions, simplifying
|
||||
the task of writing combined expressions with Eigen.
|
||||
@ -27,7 +27,7 @@ the task of writing combined expressions with Eigen.
|
||||
\subsection TutorialBlockOperationsFixedAndDynamicSize Block operations and compile-time optimizations
|
||||
As said earlier, a block operation is a way of accessing a group of coefficients inside a Matrix or
|
||||
Array object. Eigen considers two different cases in order to provide compile-time optimization for
|
||||
block operations, regarding whether the the size of the block to be accessed is known at compile time or not.
|
||||
block operations, depending on whether the the size of the block to be accessed is known at compile time or not.
|
||||
|
||||
To deal with these two situations, for each type of block operation Eigen provides a default version that
|
||||
is able to work with run-time dependant block sizes and another one for block operations whose block size is
|
||||
@ -41,20 +41,20 @@ Block operations are implemented such that they are easy to use and combine with
|
||||
matrices or arrays.
|
||||
|
||||
The most general block operation in Eigen is called \link DenseBase::block() .block() \endlink.
|
||||
This function returns a block of size <tt>(m,n)</tt> whose origin is at <tt>(i,j)</tt> by using
|
||||
This function returns a block of size <tt>(p,q)</tt> whose origin is at <tt>(i,j)</tt> by using
|
||||
the following syntax:
|
||||
|
||||
<table class="tutorial_code" align="center">
|
||||
<tr><td align="center">\b Block \b operation</td>
|
||||
<td align="center">Default \b version</td>
|
||||
<td align="center">Optimized version when the<br>size is known at compile time</td></tr>
|
||||
<tr><td>Block of length <tt>(m,n)</tt>, starting at <tt>(i,j)</tt></td>
|
||||
<tr><td>Block of length <tt>(p,q)</tt>, starting at <tt>(i,j)</tt></td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.block(i,j,m,n);\endcode </td>
|
||||
std::cout << m.block(i,j,p,q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.block<m,n>(i,j);\endcode </td>
|
||||
std::cout << m.block<p,q>(i,j);\endcode </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -149,81 +149,81 @@ starting at 0. Therefore, \p col(0) will access the first column and \p col(1) t
|
||||
<tr><td align="center">\b Block \b operation</td>
|
||||
<td align="center">Default version</td>
|
||||
<td align="center">Optimized version when the<br>size is known at compile time</td></tr>
|
||||
<tr><td>Top-left m by n block \link DenseBase::topLeftCorner() * \endlink</td>
|
||||
<tr><td>Top-left p by q block \link DenseBase::topLeftCorner() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.topLeftCorner(m,n);\endcode </td>
|
||||
std::cout << m.topLeftCorner(p,q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.topLeftCorner<m,n>();\endcode </td>
|
||||
std::cout << m.topLeftCorner<p,q>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Bottom-left m by n block
|
||||
<tr><td>Bottom-left p by q block
|
||||
\link DenseBase::bottomLeftCorner() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.bottomLeftCorner(m,n);\endcode </td>
|
||||
std::cout << m.bottomLeftCorner(p,q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.bottomLeftCorner<m,n>();\endcode </td>
|
||||
std::cout << m.bottomLeftCorner<p,q>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Top-right m by n block
|
||||
<tr><td>Top-right p by q block
|
||||
\link DenseBase::topRightCorner() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.topRightCorner(m,n);\endcode </td>
|
||||
std::cout << m.topRightCorner(p,q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.topRightCorner<m,n>();\endcode </td>
|
||||
std::cout << m.topRightCorner<p,q>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Bottom-right m by n block
|
||||
<tr><td>Bottom-right p by q block
|
||||
\link DenseBase::bottomRightCorner() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.bottomRightCorner(m,n);\endcode </td>
|
||||
std::cout << m.bottomRightCorner(p,q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.bottomRightCorner<m,n>();\endcode </td>
|
||||
std::cout << m.bottomRightCorner<p,q>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Block containing the first n<sup>th</sup> rows
|
||||
<tr><td>Block containing the first q rows
|
||||
\link DenseBase::topRows() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.topRows(n);\endcode </td>
|
||||
std::cout << m.topRows(q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.topRows<n>();\endcode </td>
|
||||
std::cout << m.topRows<q>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Block containing the last n<sup>th</sup> rows
|
||||
<tr><td>Block containing the last q rows
|
||||
\link DenseBase::bottomRows() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.bottomRows(n);\endcode </td>
|
||||
std::cout << m.bottomRows(q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.bottomRows<n>();\endcode </td>
|
||||
std::cout << m.bottomRows<q>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Block containing the first n<sup>th</sup> columns
|
||||
<tr><td>Block containing the first p columns
|
||||
\link DenseBase::leftCols() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.leftCols(n);\endcode </td>
|
||||
std::cout << m.leftCols(p);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.leftCols<n>();\endcode </td>
|
||||
std::cout << m.leftCols<p>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Block containing the last n<sup>th</sup> columns
|
||||
<tr><td>Block containing the last q columns
|
||||
\link DenseBase::rightCols() * \endlink</td>
|
||||
<td>\code
|
||||
MatrixXf m;
|
||||
std::cout << m.rightCols(n);\endcode </td>
|
||||
std::cout << m.rightCols(q);\endcode </td>
|
||||
<td>\code
|
||||
Matrix3f m;
|
||||
std::cout << m.rightCols<n>();\endcode </td>
|
||||
std::cout << m.rightCols<q>();\endcode </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
Here there is a simple example showing the power of the operations presented above:
|
||||
Here is a simple example showing the power of the operations presented above:
|
||||
|
||||
<table class="tutorial_code"><tr><td>
|
||||
C++ code:
|
||||
@ -248,7 +248,7 @@ Eigen also provides a set of block operations designed specifically for vectors:
|
||||
<tr><td align="center">\b Block \b operation</td>
|
||||
<td align="center">Default version</td>
|
||||
<td align="center">Optimized version when the<br>size is known at compile time</td></tr>
|
||||
<tr><td>Block containing the first \p n <sup>th</sup> elements row
|
||||
<tr><td>Block containing the first \p n elements
|
||||
\link DenseBase::head() * \endlink</td>
|
||||
<td>\code
|
||||
VectorXf v;
|
||||
@ -257,7 +257,7 @@ std::cout << v.head(n);\endcode </td>
|
||||
Vector3f v;
|
||||
std::cout << v.head<n>();\endcode </td>
|
||||
</tr>
|
||||
<tr><td>Block containing the last \p n <sup>th</sup> elements
|
||||
<tr><td>Block containing the last \p n elements
|
||||
\link DenseBase::tail() * \endlink</td>
|
||||
<td>\code
|
||||
VectorXf v;
|
||||
|
Loading…
Reference in New Issue
Block a user