aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/CustomizingEigen_NullaryExpr.dox
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2016-09-22 22:27:54 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2016-09-22 22:27:54 +0200
commit9bcdc8b75669d2a2ec3a7e1fe6ae96854a0bc2e4 (patch)
tree2eed12553abe0217ec1b551624224e22bf6844b9 /doc/CustomizingEigen_NullaryExpr.dox
parentca3746c6f8f788e4cc6ad9c88d1857c85be19a3b (diff)
Add a nullary-functor example performing index-based sub-matrices.
Diffstat (limited to 'doc/CustomizingEigen_NullaryExpr.dox')
-rw-r--r--doc/CustomizingEigen_NullaryExpr.dox27
1 files changed, 27 insertions, 0 deletions
diff --git a/doc/CustomizingEigen_NullaryExpr.dox b/doc/CustomizingEigen_NullaryExpr.dox
index d70f81065..37c8dcd89 100644
--- a/doc/CustomizingEigen_NullaryExpr.dox
+++ b/doc/CustomizingEigen_NullaryExpr.dox
@@ -53,6 +53,33 @@ showing that the program works as expected:
This implementation of \c makeCirculant is much simpler than \ref TopicNewExpressionType "defining a new expression" from scratch.
+
+\section NullaryExpr_Indexing Example 2: indexing rows and columns
+
+The goal here is to mimic MatLab's ability to index a matrix through two vectors of indices referencing the rows and columns to be picked respectively, like this:
+
+\snippet nullary_indexing.out main1
+
+To this end, let us first write a nullary-functor storing references to the input matrix and to the two arrays of indices, and implementing the required \c operator()(i,j):
+
+\snippet nullary_indexing.cpp functor
+
+Then, let's create an \c indexing(A,rows,cols) function creating the nullary expression:
+
+\snippet nullary_indexing.cpp function
+
+Finally, here is an example of how this function can be used:
+
+\snippet nullary_indexing.cpp main1
+
+This straightforward implementation is already quite powerful as the row or column index arrays can also be expressions to perform offsetting, modulo, striding, reverse, etc.
+
+\snippet nullary_indexing.cpp main2
+
+and the output is:
+
+\snippet nullary_indexing.out main2
+
*/
}