aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorGravatar Carlos Becker <carlosbecker@gmail.com>2010-07-08 18:16:39 +0100
committerGravatar Carlos Becker <carlosbecker@gmail.com>2010-07-08 18:16:39 +0100
commit951da96f146f3c6dc806a9e3d0fbbd96bbeb495b (patch)
treebf11f91e8ad4549e09d4f410ed39bef0b107c184 /doc
parentcb3aad1d91082dcf5edc6e5fe0fe883bbe816ebc (diff)
Added more redux types/examples in tutorial and fixed some display issues
Diffstat (limited to 'doc')
-rw-r--r--doc/C07_TutorialReductionsVisitorsBroadcasting.dox51
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp24
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp28
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp~28
4 files changed, 122 insertions, 9 deletions
diff --git a/doc/C07_TutorialReductionsVisitorsBroadcasting.dox b/doc/C07_TutorialReductionsVisitorsBroadcasting.dox
index 17124cb3b..b2c5b62cb 100644
--- a/doc/C07_TutorialReductionsVisitorsBroadcasting.dox
+++ b/doc/C07_TutorialReductionsVisitorsBroadcasting.dox
@@ -11,6 +11,8 @@ This tutorial explains Eigen's reductions, visitors and broadcasting and how the
\b Table \b of \b contents
- \ref TutorialReductionsVisitorsBroadcastingReductions
+ - \ref TutorialReductionsVisitorsBroadcastingReductionsNorm
+ - \ref TutorialReductionsVisitorsBroadcastingReductionsBool
- FIXME: .redux()
- \ref TutorialReductionsVisitorsBroadcastingVisitors
- \ref TutorialReductionsVisitorsBroadcastingPartialReductions
@@ -21,7 +23,7 @@ This tutorial explains Eigen's reductions, visitors and broadcasting and how the
\section TutorialReductionsVisitorsBroadcastingReductions Reductions
In Eigen, a reduction is a function that is applied to a certain matrix or array, returning a single
-value of type scalar. One of the most used reductions is \link MatrixBase::sum() .sum() \endlink,
+value of type scalar. One of the most used reductions is \link DenseBase::sum() .sum() \endlink,
which returns the addition of all the coefficients inside a given matrix or array.
<table class="tutorial_code"><tr><td>
@@ -33,6 +35,37 @@ Output: \include tut_arithmetic_redux_basic.out
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 will see later on.
+
+\subsection TutorialReductionsVisitorsBroadcastingReductionsNorm Norm reductions
+Eigen also provides reductions to obtain the norm or squared norm of a vector with \link DenseBase::norm() norm() \endlink and \link DenseBase::squaredNorm() squaredNorm() \endlink respectively.
+These operations can also operate on objects such as Matrices or Arrays, as shown in the following example:
+
+<table class="tutorial_code"><tr><td>
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp
+</td>
+<td>
+Output:
+\verbinclude Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.out
+</td></tr></table>
+
+\subsection TutorialReductionsVisitorsBroadcastingReductionsBool Boolean-like reductions
+
+Another interesting type of reductions are the ones that deal with \b true and \b false values:
+ - \link DenseBase::all() all() \endlink returns \b true if all of the coefficients in a given Matrix or \link ArrayBase Array \endlink are \b true .
+ - \link DenseBase::any() any() \endlink returns \b true if at least one of the coefficients in a given Matrix or \link ArrayBase Array \endlink are \b true .
+ - \link DenseBase::count() count() \endlink returns the number of \b true coefficients in a given Matrix or \link ArrayBase Array \endlink.
+
+Their behaviour can be seen in the following example:
+
+<table class="tutorial_code"><tr><td>
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp
+</td>
+<td>
+Output:
+\verbinclude Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.out
+</td></tr></table>
+
+
\section TutorialReductionsVisitorsBroadcastingVisitors Visitors
Visitors are useful when the location of a coefficient inside a Matrix or
\link ArrayBase Array \endlink wants to be obtained. The simplest example are the
@@ -43,10 +76,10 @@ the location of the greatest or smallest coefficient in a Matrix or
The arguments passed to a visitor are pointers to the variables where the
row and column position are to be stored. These variables are of type
-\link DenseBase::Index Index \endlink FIXME: link? ok?, as shown below:
+\link DenseBase::Index Index \endlink (FIXME: link ok?), as shown below:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_visitors.cpp
</td>
<td>
Output:
@@ -66,7 +99,7 @@ A simple example is obtaining the sum of the elements
in each column in a given matrix, storing the result in a row-vector:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_colwise.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_colwise.cpp
</td>
<td>
Output:
@@ -76,7 +109,7 @@ Output:
The same operation can be performed row-wise:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_rowwise.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_rowwise.cpp
</td>
<td>
Output:
@@ -92,7 +125,7 @@ Here there is another example that aims to find the the column whose sum of elem
within a matrix. With column-wise partial reductions this can be coded as:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
</td>
<td>
Output:
@@ -129,7 +162,7 @@ A simple example is to add a certain column-vector to each column in a matrix.
This can be accomplished with:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple.cpp
</td>
<td>
Output:
@@ -144,7 +177,7 @@ The same applies for the \link ArrayBase Array \endlink class, where the equival
Therefore, to perform the same operation row-wise we can do:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple_rowwise.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_broadcast_simple_rowwise.cpp
</td>
<td>
Output:
@@ -160,7 +193,7 @@ the nearest neighbour of a vector <tt>v</tt> within the columns of matrix <tt>m<
computing the squared Euclidean distance with the partial reduction named \link DenseBase::squaredNorm() squaredNorm() \endlink:
<table class="tutorial_code"><tr><td>
-\include Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp
+Example: \include Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp
</td>
<td>
Output:
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp
new file mode 100644
index 000000000..10916877f
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_bool.cpp
@@ -0,0 +1,24 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ MatrixXf m(2,2), n(2,2);
+
+ m << 0,2,
+ 3,4;
+
+ n << 1,2,
+ 3,4;
+
+ cout << "m.all() = " << m.all() << endl;
+ cout << "m.any() = " << m.any() << endl;
+ cout << "m.count() = " << m.count() << endl;
+ cout << endl;
+ cout << "n.all() = " << n.all() << endl;
+ cout << "n.any() = " << n.any() << endl;
+ cout << "n.count() = " << n.count() << endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp
new file mode 100644
index 000000000..f3364d7fc
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp
@@ -0,0 +1,28 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ VectorXf v(2);
+ MatrixXf m(2,2), n(2,2);
+
+ v << 5,
+ 10;
+
+ m << 2,2,
+ 3,4;
+
+ n << 1, 2,
+ 32,12;
+
+ cout << "v.norm() = " << v.norm() << endl;
+ cout << "m.norm() = " << m.norm() << endl;
+ cout << "n.norm() = " << n.norm() << endl;
+ cout << endl;
+ cout << "v.squaredNorm() = " << v.squaredNorm() << endl;
+ cout << "m.squaredNorm() = " << m.squaredNorm() << endl;
+ cout << "n.squaredNorm() = " << n.squaredNorm() << endl;
+}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp~ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp~
new file mode 100644
index 000000000..03057f8d2
--- /dev/null
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_reductions_norm.cpp~
@@ -0,0 +1,28 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace std;
+using namespace Eigen;
+
+int main()
+{
+ VectorXf v(2);
+ MatrixXf m(2,2), n(2,2);
+
+ v << 2,
+ 5;
+
+ m << 0,2,
+ 3,4;
+
+ n << 1,2,
+ 3,4;
+
+ cout << "v.norm() = " << m.norm() << endl;
+ cout << "m.norm() = " << m.norm() << endl;
+ cout << "n.norm() = " << m.norm() << endl;
+ cout << endl;
+ cout << "v.squaredNorm() = " << v.squaredNorm() << endl;
+ cout << "m.squaredNorm() = " << m.squaredNorm() << endl;
+ cout << "n.squaredNorm() = " << n.squaredNorm() << endl;
+}