From 8afaeb4ad5fbcde1fb25ab5c8f9a9d120db4b13b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 20 Aug 2008 13:07:46 +0000 Subject: [PATCH] doc fixes, and extended Basic Linear Algebra and Reductions sections --- Eigen/Array | 2 +- Eigen/src/Core/MapBase.h | 2 +- Eigen/src/Geometry/OrthoMethods.h | 2 +- doc/QuickStartGuide.dox | 141 +++++++++++++++++++++++------- 4 files changed, 112 insertions(+), 35 deletions(-) diff --git a/Eigen/Array b/Eigen/Array index d2a6eca0e..74d8fa888 100644 --- a/Eigen/Array +++ b/Eigen/Array @@ -11,7 +11,7 @@ namespace Eigen { * (accessible from MatrixBase::cwise()), including: * - matrix-scalar sum, * - 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: * - \ref MatrixBase::all() "all", \ref MatrixBase::any() "any", diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 4f61d1529..58afd68ab 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -64,7 +64,7 @@ template class MapBase 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. */ AlignedDerivedType forceAligned() { return derived().forceAligned(); } diff --git a/Eigen/src/Geometry/OrthoMethods.h b/Eigen/src/Geometry/OrthoMethods.h index b826a96fb..046ca0c88 100644 --- a/Eigen/src/Geometry/OrthoMethods.h +++ b/Eigen/src/Geometry/OrthoMethods.h @@ -96,7 +96,7 @@ struct ei_someOrthogonal_selector /** \returns an orthogonal vector of \c *this * * 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() */ diff --git a/doc/QuickStartGuide.dox b/doc/QuickStartGuide.dox index cff5cafe5..0128ded7b 100644 --- a/doc/QuickStartGuide.dox +++ b/doc/QuickStartGuide.dox @@ -153,53 +153,130 @@ Eigen's comma initializer usually yields to very optimized code without any over

Basic Linear Algebra

-As long as you use mathematically well defined operators, you can basically write your matrix -and vector expressions using standard arithmetic operators: +In short all mathematically well defined operators can be used right away as in the following exemple: \code -mat1 = mat1*1.5 + mat2 * mat3/4; +mat4 -= mat1*1.5 + mat2 * mat3/4; \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): -\code -scalar = vec1.dot(vec2); -\endcode - -\b outer \b product: -\code -mat = vec1 * vec2.transpose(); -\endcode - -\b cross \b product: The cross product is defined in the Geometry module, you therefore have to include it first: -\code + + + + + + + +
+matrix/vector product\code +col2 = mat1 * col1; +row2 = row1 * mat1; row1 *= mat1; +mat3 = mat1 * mat2; mat3 *= mat1; \endcode +
+add/subtract\code +mat3 = mat1 + mat2; mat3 += mat1; +mat3 = mat1 - mat2; mat3 -= mat1;\endcode +
+scalar product\code +mat3 = mat1 * s1; mat3 = s1 * mat1; mat3 *= s1; +mat3 = mat1 / s1; mat3 /= s1;\endcode +
+dot product (inner product)\code +scalar = vec1.dot(vec2);\endcode +
+outer product\code +mat = vec1 * vec2.transpose();\endcode +
+cross product\code #include -vec3 = vec1.cross(vec2); -\endcode +vec3 = vec1.cross(vec2);\endcode
-By default, Eigen's only allows mathematically well defined operators. -However, thanks to the .cwise() operator prefix, Eigen's matrices also provide +In Eigen only mathematically well defined operators can be used right away, +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: - + + + + + + + + + +
Coefficient wise product\code mat3 = mat1.cwise() * mat2; \endcode +
+Add a scalar to all coefficients\code +mat3 = mat1.cwise() + scalar; +mat3.cwise() += scalar; +mat3.cwise() -= scalar; +\endcode +
+Coefficient wise division\code +mat3 = mat1.cwise() / mat2; \endcode +
+Coefficient wise reciprocal\code +mat3 = mat1.cwise().inverse(); \endcode +
+Coefficient wise comparisons \n +(support all operators)\code +mat3 = mat1.cwise() < mat2; +mat3 = mat1.cwise() <= mat2; +mat3 = mat1.cwise() > mat2; +etc. +\endcode +
+Trigo:\n sin, cos, tan\code +mat3 = mat1.cwise().sin(); +etc. +\endcode +
+Power:\n pow, square, cube, sqrt, exp, log\code +mat3 = mat1.cwise().square(); +mat3 = mat1.cwise().pow(5); +mat3 = mat1.cwise().log(); +etc. +\endcode +
+min, max, absolute value\code +mat3 = mat1.cwise().min(mat2); +mat3 = mat1.cwise().max(mat2); +mat3 = mat1.cwise().abs(mat2); +mat3 = mat1.cwise().abs2(mat2); +\endcode
-* 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

Reductions

-\code -scalar = mat.sum(); scalar = mat.norm(); scalar = mat.minCoeff(); -vec = mat.colwise().sum(); vec = mat.colwise().norm(); vec = mat.colwise().minCoeff(); -vec = mat.rowwise().sum(); vec = mat.rowwise().norm(); vec = mat.rowwise().minCoeff(); +Reductions can be done matrix-wise, column-wise or row-wise, e.g.: + + + + + + + + +
\code mat \endcode +\code +5 3 1 +2 7 8 +9 4 6 \endcode -Other natively supported reduction operations include maxCoeff(), norm2(), all() and any(). +
\code mat.minCoeff(); \endcode\code 1 \endcode
\code mat.maxCoeff(); \endcode\code 9 \endcode
\code mat.colwise().minCoeff(); \endcode\code 2 3 1 \endcode
\code mat.colwise().maxCoeff(); \endcode\code 9 7 8 \endcode
\code mat.rowwise().minCoeff(); \endcode\code +1 +2 +4 +\endcode
\code mat.rowwise().maxCoeff(); \endcode\code +5 +8 +9 +\endcode
+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.

Sub matrices