From 2abe7d8c6e11a02fc345f6ae464b4b759b092a67 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 6 Jan 2013 23:57:54 +0100 Subject: Rename the dox files: the number prefixes are not needed anymore --- doc/TutorialMapClass.dox | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 doc/TutorialMapClass.dox (limited to 'doc/TutorialMapClass.dox') diff --git a/doc/TutorialMapClass.dox b/doc/TutorialMapClass.dox new file mode 100644 index 000000000..a5c20f1bf --- /dev/null +++ b/doc/TutorialMapClass.dox @@ -0,0 +1,86 @@ +namespace Eigen { + +/** \eigenManualPage TutorialMapClass Interfacing with raw buffers: the Map class + +This page explains how to work with "raw" C/C++ arrays. +This can be useful in a variety of contexts, particularly when "importing" vectors and matrices from other libraries into Eigen. + +\eigenAutoToc + +\section TutorialMapIntroduction Introduction + +Occasionally you may have a pre-defined array of numbers that you want to use within Eigen as a vector or matrix. While one option is to make a copy of the data, most commonly you probably want to re-use this memory as an Eigen type. Fortunately, this is very easy with the Map class. + +\section TutorialMapTypes Map types and declaring Map variables + +A Map object has a type defined by its Eigen equivalent: +\code +Map > +\endcode +Note that, in this default case, a Map requires just a single template parameter. + +To construct a Map variable, you need two other pieces of information: a pointer to the region of memory defining the array of coefficients, and the desired shape of the matrix or vector. For example, to define a matrix of \c float with sizes determined at compile time, you might do the following: +\code +Map mf(pf,rows,columns); +\endcode +where \c pf is a \c float \c * pointing to the array of memory. A fixed-size read-only vector of integers might be declared as +\code +Map mi(pi); +\endcode +where \c pi is an \c int \c *. In this case the size does not have to be passed to the constructor, because it is already specified by the Matrix/Array type. + +Note that Map does not have a default constructor; you \em must pass a pointer to intialize the object. However, you can work around this requirement (see \ref TutorialMapPlacementNew). + +Map is flexible enough to accomodate a variety of different data representations. There are two other (optional) template parameters: +\code +Map +\endcode +\li \c MapOptions specifies whether the pointer is \c #Aligned, or \c #Unaligned. The default is \c #Unaligned. +\li \c StrideType allows you to specify a custom layout for the memory array, using the Stride class. One example would be to specify that the data array is organized in row-major format: + + + + + +
Example:Output:
\include Tutorial_Map_rowmajor.cpp \verbinclude Tutorial_Map_rowmajor.out
+However, Stride is even more flexible than this; for details, see the documentation for the Map and Stride classes. + +\section TutorialMapUsing Using Map variables + +You can use a Map object just like any other Eigen type: + + + + + +
Example:Output:
\include Tutorial_Map_using.cpp \verbinclude Tutorial_Map_using.out
+ +However, when writing functions taking Eigen types, it is important to realize that a Map type is \em not identical to its Dense equivalent. See \ref TopicFunctionTakingEigenTypesMultiarguments for details. + +\section TutorialMapPlacementNew Changing the mapped array + +It is possible to change the array of a Map object after declaration, using the C++ "placement new" syntax: + + + + + +
Example:Output:
\include Map_placement_new.cpp \verbinclude Map_placement_new.out
+Despite appearances, this does not invoke the memory allocator, because the syntax specifies the location for storing the result. + +This syntax makes it possible to declare a Map object without first knowing the mapped array's location in memory: +\code +Map A(NULL); // don't try to use this matrix yet! +VectorXf b(n_matrices); +for (int i = 0; i < n_matrices; i++) +{ + new (&A) Map(get_matrix_pointer(i)); + b(i) = A.trace(); +} +\endcode + +*/ + +} -- cgit v1.2.3