diff options
author | Tim Holy <holy@wustl.edu> | 2012-02-08 22:11:12 +0100 |
---|---|---|
committer | Tim Holy <holy@wustl.edu> | 2012-02-08 22:11:12 +0100 |
commit | 44b19b432c1fc86da7a1836a23007504d995009a (patch) | |
tree | 916ea545d332ba60a8c4d3f5512345a75097ee05 /doc/snippets | |
parent | 5bb34fd14c74021314744cb1d4a82a39449359cf (diff) |
Add a tutorial page on the Map class, and add a section to FunctionsTakingEigenTypes about multiple-argument functions and the pitfalls when using Map/Expression types.
Diffstat (limited to 'doc/snippets')
-rw-r--r-- | doc/snippets/Tutorial_Map_rowmajor.cpp | 7 | ||||
-rw-r--r-- | doc/snippets/Tutorial_Map_using.cpp | 21 |
2 files changed, 28 insertions, 0 deletions
diff --git a/doc/snippets/Tutorial_Map_rowmajor.cpp b/doc/snippets/Tutorial_Map_rowmajor.cpp new file mode 100644 index 000000000..fd45ace03 --- /dev/null +++ b/doc/snippets/Tutorial_Map_rowmajor.cpp @@ -0,0 +1,7 @@ +int array[8]; +for(int i = 0; i < 8; ++i) array[i] = i; +cout << "Column-major:\n" << Map<Matrix<int,2,4> >(array) << endl; +cout << "Row-major:\n" << Map<Matrix<int,2,4,RowMajor> >(array) << endl; +cout << "Row-major using stride:\n" << + Map<Matrix<int,2,4>, Unaligned, Stride<1,4> >(array) << endl; + diff --git a/doc/snippets/Tutorial_Map_using.cpp b/doc/snippets/Tutorial_Map_using.cpp new file mode 100644 index 000000000..e5e499f1f --- /dev/null +++ b/doc/snippets/Tutorial_Map_using.cpp @@ -0,0 +1,21 @@ +typedef Matrix<float,1,Dynamic> MatrixType; +typedef Map<MatrixType> MapType; +typedef Map<const MatrixType> MapTypeConst; // a read-only map +const int n_dims = 5; + +MatrixType m1(n_dims), m2(n_dims); +m1.setRandom(); +m2.setRandom(); +float *p = &m2(0); // get the address storing the data for m2 +MapType m2map(p,m2.size()); // m2map shares data with m2 +MapTypeConst m2mapconst(p,m2.size()); // a read-only accessor for m2 + +cout << "m1: " << m1 << endl; +cout << "m2: " << m2 << endl; +cout << "Squared euclidean distance: " << (m1-m2).squaredNorm() << endl; +cout << "Squared euclidean distance, using map: " << + (m1-m2map).squaredNorm() << endl; +m2map(3) = 7; // this will change m2, since they share the same array +cout << "Updated m2: " << m2 << endl; +cout << "m2 coefficient 2, constant accessor: " << m2mapconst(2) << endl; +/* m2mapconst(2) = 5; */ // this yields a compile-time error |