namespace Eigen { /** \eigenManualPage TutorialReshapeSlicing Reshape and Slicing %Eigen does not expose convenient methods to take slices or to reshape a matrix yet. Nonetheless, such features can easily be emulated using the Map class. \eigenAutoToc \section TutorialReshape Reshape A reshape operation consists in modifying the sizes of a matrix while keeping the same coefficients. Instead of modifying the input matrix itself, which is not possible for compile-time sizes, the approach consist in creating a different \em view on the storage using class Map. Here is a typical example creating a 1D linear view of a matrix:
Example:Output:
\include Tutorial_ReshapeMat2Vec.cpp \verbinclude Tutorial_ReshapeMat2Vec.out
Remark how the storage order of the input matrix modifies the order of the coefficients in the linear view. Here is another example reshaping a 2x6 matrix to a 6x2 one:
Example:Output:
\include Tutorial_ReshapeMat2Mat.cpp \verbinclude Tutorial_ReshapeMat2Mat.out
\section TutorialSlicing Slicing Slicing consists in taking a set of rows, or columns, or elements, uniformly spaced within a matrix. Again, the class Map allows to easily mimic this feature. For instance, one can take skip every P elements in a vector:
Example:Output:
\include Tutorial_SlicingVec.cpp \verbinclude Tutorial_SlicingVec.out
One can olso take one column over three using an adequate outer-stride or inner-stride depending on the actual storage order:
Example:Output:
\include Tutorial_SlicingCol.cpp \verbinclude Tutorial_SlicingCol.out
*/ }