mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-21 04:14:26 +08:00
doc fixes, and extended Basic Linear Algebra and Reductions sections
This commit is contained in:
parent
db8fbf2b39
commit
8afaeb4ad5
@ -11,7 +11,7 @@ namespace Eigen {
|
|||||||
* (accessible from MatrixBase::cwise()), including:
|
* (accessible from MatrixBase::cwise()), including:
|
||||||
* - matrix-scalar sum,
|
* - matrix-scalar sum,
|
||||||
* - coeff-wise comparison operators,
|
* - coeff-wise comparison operators,
|
||||||
* - sin, cos, sqrt, pow, exp, log, square, cube, reciprocal.
|
* - sin, cos, sqrt, pow, exp, log, square, cube, inverse (reciprocal).
|
||||||
*
|
*
|
||||||
* This module also provides various MatrixBase methods, including:
|
* This module also provides various MatrixBase methods, including:
|
||||||
* - \ref MatrixBase::all() "all", \ref MatrixBase::any() "any",
|
* - \ref MatrixBase::all() "all", \ref MatrixBase::any() "any",
|
||||||
|
@ -64,7 +64,7 @@ template<typename Derived> class MapBase
|
|||||||
|
|
||||||
inline int stride() const { return derived().stride(); }
|
inline int stride() const { return derived().stride(); }
|
||||||
|
|
||||||
/** \Returns an expression equivalent to \c *this but having the \c PacketAccess constant
|
/** \returns an expression equivalent to \c *this but having the \c PacketAccess constant
|
||||||
* set to \c ForceAligned. Must be reimplemented by the derived class. */
|
* set to \c ForceAligned. Must be reimplemented by the derived class. */
|
||||||
AlignedDerivedType forceAligned() { return derived().forceAligned(); }
|
AlignedDerivedType forceAligned() { return derived().forceAligned(); }
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ struct ei_someOrthogonal_selector<Derived,2>
|
|||||||
/** \returns an orthogonal vector of \c *this
|
/** \returns an orthogonal vector of \c *this
|
||||||
*
|
*
|
||||||
* The size of \c *this must be at least 2. If the size is exactly 2,
|
* The size of \c *this must be at least 2. If the size is exactly 2,
|
||||||
* then the returned vector is a counter clock wise rotation of \c *this, \ie (-y,x).
|
* then the returned vector is a counter clock wise rotation of \c *this, i.e., (-y,x).
|
||||||
*
|
*
|
||||||
* \sa cross()
|
* \sa cross()
|
||||||
*/
|
*/
|
||||||
|
@ -153,53 +153,130 @@ Eigen's comma initializer usually yields to very optimized code without any over
|
|||||||
|
|
||||||
<h2>Basic Linear Algebra</h2>
|
<h2>Basic Linear Algebra</h2>
|
||||||
|
|
||||||
As long as you use mathematically well defined operators, you can basically write your matrix
|
In short all mathematically well defined operators can be used right away as in the following exemple:
|
||||||
and vector expressions using standard arithmetic operators:
|
|
||||||
\code
|
\code
|
||||||
mat1 = mat1*1.5 + mat2 * mat3/4;
|
mat4 -= mat1*1.5 + mat2 * mat3/4;
|
||||||
\endcode
|
\endcode
|
||||||
|
which includes two matrix scalar products ("mat1*1.5" and "mat3/4"), a matrix-matrix product ("mat2 * mat3/4"),
|
||||||
|
a matrix addition ("+") and substraction with assignment ("-=").
|
||||||
|
|
||||||
\b dot \b product (inner product):
|
<table>
|
||||||
\code
|
<tr><td>
|
||||||
scalar = vec1.dot(vec2);
|
matrix/vector product</td><td>\code
|
||||||
\endcode
|
col2 = mat1 * col1;
|
||||||
|
row2 = row1 * mat1; row1 *= mat1;
|
||||||
\b outer \b product:
|
mat3 = mat1 * mat2; mat3 *= mat1; \endcode
|
||||||
\code
|
</td></tr>
|
||||||
mat = vec1 * vec2.transpose();
|
<tr><td>
|
||||||
\endcode
|
add/subtract</td><td>\code
|
||||||
|
mat3 = mat1 + mat2; mat3 += mat1;
|
||||||
\b cross \b product: The cross product is defined in the Geometry module, you therefore have to include it first:
|
mat3 = mat1 - mat2; mat3 -= mat1;\endcode
|
||||||
\code
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
scalar product</td><td>\code
|
||||||
|
mat3 = mat1 * s1; mat3 = s1 * mat1; mat3 *= s1;
|
||||||
|
mat3 = mat1 / s1; mat3 /= s1;\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
dot product (inner product)</td><td>\code
|
||||||
|
scalar = vec1.dot(vec2);\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
outer product</td><td>\code
|
||||||
|
mat = vec1 * vec2.transpose();\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
cross product</td><td>\code
|
||||||
#include <Eigen/Geometry>
|
#include <Eigen/Geometry>
|
||||||
vec3 = vec1.cross(vec2);
|
vec3 = vec1.cross(vec2);\endcode</td></tr>
|
||||||
\endcode
|
</table>
|
||||||
|
|
||||||
|
|
||||||
By default, Eigen's only allows mathematically well defined operators.
|
In Eigen only mathematically well defined operators can be used right away,
|
||||||
However, thanks to the .cwise() operator prefix, Eigen's matrices also provide
|
but don't worry, thanks to the .cwise() operator prefix, Eigen's matrices also provide
|
||||||
a very powerful numerical container supporting most common coefficient wise operators:
|
a very powerful numerical container supporting most common coefficient wise operators:
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr><td></td><td></td><tr>
|
|
||||||
|
<tr><td>Coefficient wise product</td>
|
||||||
|
<td>\code mat3 = mat1.cwise() * mat2; \endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
Add a scalar to all coefficients</td><td>\code
|
||||||
|
mat3 = mat1.cwise() + scalar;
|
||||||
|
mat3.cwise() += scalar;
|
||||||
|
mat3.cwise() -= scalar;
|
||||||
|
\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
Coefficient wise division</td><td>\code
|
||||||
|
mat3 = mat1.cwise() / mat2; \endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
Coefficient wise reciprocal</td><td>\code
|
||||||
|
mat3 = mat1.cwise().inverse(); \endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
Coefficient wise comparisons \n
|
||||||
|
(support all operators)</td><td>\code
|
||||||
|
mat3 = mat1.cwise() < mat2;
|
||||||
|
mat3 = mat1.cwise() <= mat2;
|
||||||
|
mat3 = mat1.cwise() > mat2;
|
||||||
|
etc.
|
||||||
|
\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
Trigo:\n sin, cos, tan</td><td>\code
|
||||||
|
mat3 = mat1.cwise().sin();
|
||||||
|
etc.
|
||||||
|
\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
Power:\n pow, square, cube, sqrt, exp, log</td><td>\code
|
||||||
|
mat3 = mat1.cwise().square();
|
||||||
|
mat3 = mat1.cwise().pow(5);
|
||||||
|
mat3 = mat1.cwise().log();
|
||||||
|
etc.
|
||||||
|
\endcode
|
||||||
|
</td></tr>
|
||||||
|
<tr><td>
|
||||||
|
min, max, absolute value</td><td>\code
|
||||||
|
mat3 = mat1.cwise().min(mat2);
|
||||||
|
mat3 = mat1.cwise().max(mat2);
|
||||||
|
mat3 = mat1.cwise().abs(mat2);
|
||||||
|
mat3 = mat1.cwise().abs2(mat2);
|
||||||
|
\endcode</td></tr>
|
||||||
</table>
|
</table>
|
||||||
* Coefficient wise product: \code mat3 = mat1.cwise() * mat2; \endcode
|
|
||||||
* Coefficient wise division: \code mat3 = mat1.cwise() / mat2; \endcode
|
|
||||||
* Coefficient wise reciprocal: \code mat3 = mat1.cwise().inverse(); \endcode
|
|
||||||
* Add a scalar to a matrix: \code mat3 = mat1.cwise() + scalar; \endcode
|
|
||||||
* Coefficient wise comparison: \code mat3 = mat1.cwise() < mat2; \endcode
|
|
||||||
* Finally, \c .cwise() offers many common numerical functions including abs, pow, exp, sin, cos, tan, e.g.:
|
|
||||||
\code mat3 = mat1.cwise().sin(); \endcode
|
|
||||||
|
|
||||||
<h2>Reductions</h2>
|
<h2>Reductions</h2>
|
||||||
|
|
||||||
\code
|
Reductions can be done matrix-wise, column-wise or row-wise, e.g.:
|
||||||
scalar = mat.sum(); scalar = mat.norm(); scalar = mat.minCoeff();
|
<table>
|
||||||
vec = mat.colwise().sum(); vec = mat.colwise().norm(); vec = mat.colwise().minCoeff();
|
<tr><td>\code mat \endcode
|
||||||
vec = mat.rowwise().sum(); vec = mat.rowwise().norm(); vec = mat.rowwise().minCoeff();
|
</td><td>\code
|
||||||
|
5 3 1
|
||||||
|
2 7 8
|
||||||
|
9 4 6
|
||||||
\endcode
|
\endcode
|
||||||
Other natively supported reduction operations include maxCoeff(), norm2(), all() and any().
|
</td></tr>
|
||||||
|
<tr><td>\code mat.minCoeff(); \endcode</td><td>\code 1 \endcode</td></tr>
|
||||||
|
<tr><td>\code mat.maxCoeff(); \endcode</td><td>\code 9 \endcode</td></tr>
|
||||||
|
<tr><td>\code mat.colwise().minCoeff(); \endcode</td><td>\code 2 3 1 \endcode</td></tr>
|
||||||
|
<tr><td>\code mat.colwise().maxCoeff(); \endcode</td><td>\code 9 7 8 \endcode</td></tr>
|
||||||
|
<tr><td>\code mat.rowwise().minCoeff(); \endcode</td><td>\code
|
||||||
|
1
|
||||||
|
2
|
||||||
|
4
|
||||||
|
\endcode</td></tr>
|
||||||
|
<tr><td>\code mat.rowwise().maxCoeff(); \endcode</td><td>\code
|
||||||
|
5
|
||||||
|
8
|
||||||
|
9
|
||||||
|
\endcode</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
Eigen provides several other reduction methods such as sum(), norm(), norm2(), all(), and any().
|
||||||
|
The all() and any() functions are especially useful in combinaison with coeff-wise comparison operators.
|
||||||
|
|
||||||
<h2>Sub matrices</h2>
|
<h2>Sub matrices</h2>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user