* 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 /** \page TutorialCore Tutorial 1/4 - Core features
\ingroup Tutorial \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" <div class="eimainmenu">\ref index "Overview"
| \b Core \b features | \b Core \b features
| \ref TutorialGeometry "Geometry" | \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. second variable.
\section TutorialArithmeticRedux Basic arithmetic reduction operations \section TutorialArithmeticRedux Basic arithmetic reduction operations
Eigen also provides some reduction operations to obtain values such as the sum or the maximum 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.
or minimum of all the coefficients in a given matrix or vector.
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"> 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.
<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;
// minimum value will be stored in minValue There also exist variants of the \c minCoeff and \c maxCoeff functions returning the coordinates of the respective coefficient via the arguments:
// 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;
// maximum value will be stored in maxValue <table class="tutorial_code"><tr><td>
// and the row and column where it was found in row and col, Example: \include tut_arithmetic_redux_minmax.cpp
// (these two parameters are optional) </td>
float maxValue = m.maxCoeff(&row,&col);\endcode</td></tr> <td>
<tr><td> Output: \include tut_arithmetic_redux_minmax.out
Product between all coefficients in a matrix</td><td>\code </td></tr></table>
MatrixXf m;
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> \section TutorialArithmeticValidity Validity of operations
<tr><td>
Matrix's trace</td><td>\code
MatrixXf m;
float trace = m.trace();\endcode</td></tr>
</table>
\subsection TutorialArithmeticValidity Validity of operations
Eigen checks the validity of the operations that you perform. When possible, 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, 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: 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> <a href="#" class="top">top</a>
\section QuickRef_Types Array, matrix and vector types \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: \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 \code
typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options> MyMatrixType; 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="matrixonly"><a/>\matrixworld linear algebra matrix and vector only
\li <a name="arrayonly"><a/>\arrayworld array objects only \li <a name="arrayonly"><a/>\arrayworld array objects only
\subsection QuickRef_Basics Basic matrix manipulation \subsection QuickRef_Basics Basic matrix manipulation
<table class="tutorial_code"> <table class="tutorial_code">

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**) int main(int, char**)
{ {
cout.precision(3);
${snippet_source_code} ${snippet_source_code}
return 0; 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; Matrix2i a; a << 1, 2, 3, 4;
cout << "Here is the matrix a:\n" << a << endl; 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; MatrixXf a(2,3); a << 1, 2, 3, 4, 5, 6;
cout << "Here is the initial matrix a:\n" << a << endl; cout << "Here is the initial matrix a:\n" << a << endl;
a.transposeInPlace(); a.transposeInPlace();
cout << "and after being transposed:\n" << a << endl; cout << "and after being transposed:\n" << a << endl;