* update redux section

* fix output precision to 3 for the snippets
This commit is contained in:
Gael Guennebaud 2010-06-28 13:30:10 +02:00
parent 768bdd08c8
commit dbefd7aafb
8 changed files with 52 additions and 45 deletions

View File

@ -3,6 +3,8 @@ namespace Eigen {
/** \page TutorialCore Tutorial 1/4 - Core features
\ingroup Tutorial
<p style="font-size:2em"> WARNING this page is deprecated, and will be removed soon, don't look at it :) </p>
<div class="eimainmenu">\ref index "Overview"
| \b Core \b features
| \ref TutorialGeometry "Geometry"

View File

@ -143,53 +143,28 @@ When using complex numbers, Eigen's dot product is conjugate-linear in the first
second variable.
\section TutorialArithmeticRedux Basic arithmetic reduction operations
Eigen also provides some reduction operations to obtain values such as the sum or the maximum
or minimum of all the coefficients in a given matrix or vector.
Eigen also provides some reduction operations to reduce a given matrix or vector to a single value such as the sum (<tt>a.sum()</tt>), product (<tt>a.sum()</tt>), or the maximum (<tt>a.maxCoeff()</tt>) and minimum (<tt>a.minCoeff()</tt>) of all its coefficients.
TODO: convert this from table format to tutorial/examples format.
<table class="tutorial_code"><tr><td>
Example: \include tut_arithmetic_redux_basic.cpp
</td>
<td>
Output: \include tut_arithmetic_redux_basic.out
</td></tr></table>
<table class="tutorial_code" align="center">
<tr><td align="center">\b Reduction \b operation</td><td align="center">\b Usage \b example</td></tr>
<tr><td>
Sum of all the coefficients in a matrix</td><td>\code
MatrixXf m;
float totalSum = m.sum();\endcode</td></tr>
<tr><td>
Maximum coefficient in a matrix</td><td>\code
MatrixXf m;
int row, col;
The \em trace of a matrix, as returned by the function \c trace(), is the sum of the diagonal coefficients and can also be computed as efficiently using <tt>a.diagonal().sum()</tt>, as we see later on.
// minimum value will be stored in minValue
// and the row and column where it was found in row and col,
// (these two parameters are optional)
float minValue = m.minCoeff(&row,&col);\endcode</td></tr>
<tr><td>
Maximum coefficient in a matrix</td><td>\code
MatrixXf m;
int row, col;
There also exist variants of the \c minCoeff and \c maxCoeff functions returning the coordinates of the respective coefficient via the arguments:
// maximum value will be stored in maxValue
// and the row and column where it was found in row and col,
// (these two parameters are optional)
float maxValue = m.maxCoeff(&row,&col);\endcode</td></tr>
<tr><td>
Product between all coefficients in a matrix</td><td>\code
MatrixXf m;
<table class="tutorial_code"><tr><td>
Example: \include tut_arithmetic_redux_minmax.cpp
</td>
<td>
Output: \include tut_arithmetic_redux_minmax.out
</td></tr></table>
float product = m.prod();\endcode</td></tr>
<tr><td>
Mean of coefficients in a matrix</td><td>\code
MatrixXf m;
float mean = m.mean();\endcode</td></tr>
<tr><td>
Matrix's trace</td><td>\code
MatrixXf m;
float trace = m.trace();\endcode</td></tr>
</table>
\subsection TutorialArithmeticValidity Validity of operations
\section TutorialArithmeticValidity Validity of operations
Eigen checks the validity of the operations that you perform. When possible,
it checks them at compile-time, producing compilation errors. These error messages can be long and ugly,
but Eigen writes the important message in UPPERCASE_LETTERS_SO_IT_STANDS_OUT. For example:

View File

@ -35,6 +35,7 @@ namespace Eigen {
<a href="#" class="top">top</a>
\section QuickRef_Types Array, matrix and vector types
\b Recall: Eigen provides two kinds of dense objects: mathematical matrices and vectors which are both represented by the template class Matrix, and general 1D and 2D arrays represented by the template class Array:
\code
typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options> MyMatrixType;
@ -87,7 +88,6 @@ In the rest of this document we will use the following symbols to emphasize the
\li <a name="matrixonly"><a/>\matrixworld linear algebra matrix and vector only
\li <a name="arrayonly"><a/>\arrayworld array objects only
\subsection QuickRef_Basics Basic matrix manipulation
<table class="tutorial_code">
@ -371,7 +371,7 @@ Coefficient-wise operators for matrices and vectors:
<tr><td>\code
mat1.cwiseMin(mat2)
mat1.cwiseMax(mat2)
mat1.cwiseAbs2()
mat1.cwiseAbs2()
mat1.cwiseAbs()
mat1.cwiseSqrt()
mat1.cwiseProduct(mat2)

View File

@ -0,0 +1,16 @@
#include <iostream>
#include <Eigen/Dense>
using namespace std;
int main()
{
Eigen::Matrix2d mat;
mat << 1, 2,
3, 4;
cout << "Here is mat.sum(): " << mat.sum() << endl;
cout << "Here is mat.prod(): " << mat.prod() << endl;
cout << "Here is mat.mean(): " << mat.mean() << endl;
cout << "Here is mat.minCoeff(): " << mat.minCoeff() << endl;
cout << "Here is mat.maxCoeff(): " << mat.maxCoeff() << endl;
cout << "Here is mat.trace(): " << mat.trace() << endl;
}

View File

@ -11,6 +11,7 @@ using namespace std;
int main(int, char**)
{
cout.precision(3);
${snippet_source_code}
return 0;
}

View File

@ -0,0 +1,10 @@
Matrix3f m = Matrix3f::Random();
std::ptrdiff_t i, j;
float minOfM = m.minCoeff(&i,&j);
cout << "Here is the matrix m:\n" << m << endl;
cout << "Its minimum coefficient (" << minOfM << ") is at position (" << i << "," << j << ")\n\n";
RowVector4i v = RowVector4i::Random();
int maxOfV = v.maxCoeff(&i);
cout << "Here is the vector v: " << v << endl;
cout << "Its maximum coefficient (" << maxOfV << ") is at position " << i << endl;

View File

@ -1,4 +1,5 @@
Matrix2i a; a << 1, 2, 3, 4;
cout << "Here is the matrix a:\n" << a << endl;
a = a.transpose(); // fails
cout << "and the aliasing effect:\n" << a << endl;
a = a.transpose(); // !!! do NOT do this !!!
cout << "and the result of the aliasing effect:\n" << a << endl;

View File

@ -1,4 +1,6 @@
MatrixXf a(2,3); a << 1, 2, 3, 4, 5, 6;
cout << "Here is the initial matrix a:\n" << a << endl;
a.transposeInPlace();
cout << "and after being transposed:\n" << a << endl;