1 namespace Eigen { 2 3 /** \eigenManualPage TutorialReshapeSlicing Reshape and Slicing 4 5 %Eigen does not expose convenient methods to take slices or to reshape a matrix yet. 6 Nonetheless, such features can easily be emulated using the Map class. 7 8 \eigenAutoToc 9 10 \section TutorialReshape Reshape 11 12 A reshape operation consists in modifying the sizes of a matrix while keeping the same coefficients. 13 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. 14 Here is a typical example creating a 1D linear view of a matrix: 15 16 <table class="example"> 17 <tr><th>Example:</th><th>Output:</th></tr> 18 <tr><td> 19 \include Tutorial_ReshapeMat2Vec.cpp 20 </td> 21 <td> 22 \verbinclude Tutorial_ReshapeMat2Vec.out 23 </td></tr></table> 24 25 Remark how the storage order of the input matrix modifies the order of the coefficients in the linear view. 26 Here is another example reshaping a 2x6 matrix to a 6x2 one: 27 <table class="example"> 28 <tr><th>Example:</th><th>Output:</th></tr> 29 <tr><td> 30 \include Tutorial_ReshapeMat2Mat.cpp 31 </td> 32 <td> 33 \verbinclude Tutorial_ReshapeMat2Mat.out 34 </td></tr></table> 35 36 37 38 \section TutorialSlicing Slicing 39 40 Slicing consists in taking a set of rows, columns, or elements, uniformly spaced within a matrix. 41 Again, the class Map allows to easily mimic this feature. 42 43 For instance, one can skip every P elements in a vector: 44 <table class="example"> 45 <tr><th>Example:</th><th>Output:</th></tr> 46 <tr><td> 47 \include Tutorial_SlicingVec.cpp 48 </td> 49 <td> 50 \verbinclude Tutorial_SlicingVec.out 51 </td></tr></table> 52 53 One can olso take one column over three using an adequate outer-stride or inner-stride depending on the actual storage order: 54 <table class="example"> 55 <tr><th>Example:</th><th>Output:</th></tr> 56 <tr><td> 57 \include Tutorial_SlicingCol.cpp 58 </td> 59 <td> 60 \verbinclude Tutorial_SlicingCol.out 61 </td></tr></table> 62 63 */ 64 65 } 66