TutorialReshapeSlicing.dox 1.9 KB

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