You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

785 lines
28 KiB

  1. namespace StormEigen {
  2. /** \eigenManualPage QuickRefPage Quick reference guide
  3. \eigenAutoToc
  4. <hr>
  5. <a href="#" class="top">top</a>
  6. \section QuickRef_Headers Modules and Header files
  7. The Eigen library is divided in a Core module and several additional modules. Each module has a corresponding header file which has to be included in order to use the module. The \c %Dense and \c Eigen header files are provided to conveniently gain access to several modules at once.
  8. <table class="manual">
  9. <tr><th>Module</th><th>Header file</th><th>Contents</th></tr>
  10. <tr ><td>\link Core_Module Core \endlink</td><td>\code#include <StormEigen/Core>\endcode</td><td>Matrix and Array classes, basic linear algebra (including triangular and selfadjoint products), array manipulation</td></tr>
  11. <tr class="alt"><td>\link Geometry_Module Geometry \endlink</td><td>\code#include <StormEigen/Geometry>\endcode</td><td>Transform, Translation, Scaling, Rotation2D and 3D rotations (Quaternion, AngleAxis)</td></tr>
  12. <tr ><td>\link LU_Module LU \endlink</td><td>\code#include <StormEigen/LU>\endcode</td><td>Inverse, determinant, LU decompositions with solver (FullPivLU, PartialPivLU)</td></tr>
  13. <tr class="alt"><td>\link Cholesky_Module Cholesky \endlink</td><td>\code#include <StormEigen/Cholesky>\endcode</td><td>LLT and LDLT Cholesky factorization with solver</td></tr>
  14. <tr ><td>\link Householder_Module Householder \endlink</td><td>\code#include <StormEigen/Householder>\endcode</td><td>Householder transformations; this module is used by several linear algebra modules</td></tr>
  15. <tr class="alt"><td>\link SVD_Module SVD \endlink</td><td>\code#include <StormEigen/SVD>\endcode</td><td>SVD decompositions with least-squares solver (JacobiSVD, BDCSVD)</td></tr>
  16. <tr ><td>\link QR_Module QR \endlink</td><td>\code#include <StormEigen/QR>\endcode</td><td>QR decomposition with solver (HouseholderQR, ColPivHouseholderQR, FullPivHouseholderQR)</td></tr>
  17. <tr class="alt"><td>\link Eigenvalues_Module Eigenvalues \endlink</td><td>\code#include <StormEigen/Eigenvalues>\endcode</td><td>Eigenvalue, eigenvector decompositions (EigenSolver, SelfAdjointEigenSolver, ComplexEigenSolver)</td></tr>
  18. <tr ><td>\link Sparse_modules Sparse \endlink</td><td>\code#include <StormEigen/Sparse>\endcode</td><td>%Sparse matrix storage and related basic linear algebra (SparseMatrix, SparseVector) \n (see \ref SparseQuickRefPage for details on sparse modules)</td></tr>
  19. <tr class="alt"><td></td><td>\code#include <StormEigen/Dense>\endcode</td><td>Includes Core, Geometry, LU, Cholesky, SVD, QR, and Eigenvalues header files</td></tr>
  20. <tr ><td></td><td>\code#include <StormEigen/Eigen>\endcode</td><td>Includes %Dense and %Sparse header files (the whole Eigen library)</td></tr>
  21. </table>
  22. <a href="#" class="top">top</a>
  23. \section QuickRef_Types Array, matrix and vector types
  24. \b Recall: Eigen provides two kinds of dense objects: mathematical matrices and vectors which are both represented by the template class Matrix, and general 1D and 2D arrays represented by the template class Array:
  25. \code
  26. typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options> MyMatrixType;
  27. typedef Array<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options> MyArrayType;
  28. \endcode
  29. \li \c Scalar is the scalar type of the coefficients (e.g., \c float, \c double, \c bool, \c int, etc.).
  30. \li \c RowsAtCompileTime and \c ColsAtCompileTime are the number of rows and columns of the matrix as known at compile-time or \c Dynamic.
  31. \li \c Options can be \c ColMajor or \c RowMajor, default is \c ColMajor. (see class Matrix for more options)
  32. All combinations are allowed: you can have a matrix with a fixed number of rows and a dynamic number of columns, etc. The following are all valid:
  33. \code
  34. Matrix<double, 6, Dynamic> // Dynamic number of columns (heap allocation)
  35. Matrix<double, Dynamic, 2> // Dynamic number of rows (heap allocation)
  36. Matrix<double, Dynamic, Dynamic, RowMajor> // Fully dynamic, row major (heap allocation)
  37. Matrix<double, 13, 3> // Fully fixed (usually allocated on stack)
  38. \endcode
  39. In most cases, you can simply use one of the convenience typedefs for \ref matrixtypedefs "matrices" and \ref arraytypedefs "arrays". Some examples:
  40. <table class="example">
  41. <tr><th>Matrices</th><th>Arrays</th></tr>
  42. <tr><td>\code
  43. Matrix<float,Dynamic,Dynamic> <=> MatrixXf
  44. Matrix<double,Dynamic,1> <=> VectorXd
  45. Matrix<int,1,Dynamic> <=> RowVectorXi
  46. Matrix<float,3,3> <=> Matrix3f
  47. Matrix<float,4,1> <=> Vector4f
  48. \endcode</td><td>\code
  49. Array<float,Dynamic,Dynamic> <=> ArrayXXf
  50. Array<double,Dynamic,1> <=> ArrayXd
  51. Array<int,1,Dynamic> <=> RowArrayXi
  52. Array<float,3,3> <=> Array33f
  53. Array<float,4,1> <=> Array4f
  54. \endcode</td></tr>
  55. </table>
  56. Conversion between the matrix and array worlds:
  57. \code
  58. Array44f a1, a1;
  59. Matrix4f m1, m2;
  60. m1 = a1 * a2; // coeffwise product, implicit conversion from array to matrix.
  61. a1 = m1 * m2; // matrix product, implicit conversion from matrix to array.
  62. a2 = a1 + m1.array(); // mixing array and matrix is forbidden
  63. m2 = a1.matrix() + m1; // and explicit conversion is required.
  64. ArrayWrapper<Matrix4f> m1a(m1); // m1a is an alias for m1.array(), they share the same coefficients
  65. MatrixWrapper<Array44f> a1m(a1);
  66. \endcode
  67. In the rest of this document we will use the following symbols to emphasize the features which are specifics to a given kind of object:
  68. \li <a name="matrixonly"></a>\matrixworld linear algebra matrix and vector only
  69. \li <a name="arrayonly"></a>\arrayworld array objects only
  70. \subsection QuickRef_Basics Basic matrix manipulation
  71. <table class="manual">
  72. <tr><th></th><th>1D objects</th><th>2D objects</th><th>Notes</th></tr>
  73. <tr><td>Constructors</td>
  74. <td>\code
  75. Vector4d v4;
  76. Vector2f v1(x, y);
  77. Array3i v2(x, y, z);
  78. Vector4d v3(x, y, z, w);
  79. VectorXf v5; // empty object
  80. ArrayXf v6(size);
  81. \endcode</td><td>\code
  82. Matrix4f m1;
  83. MatrixXf m5; // empty object
  84. MatrixXf m6(nb_rows, nb_columns);
  85. \endcode</td><td class="note">
  86. By default, the coefficients \n are left uninitialized</td></tr>
  87. <tr class="alt"><td>Comma initializer</td>
  88. <td>\code
  89. Vector3f v1; v1 << x, y, z;
  90. ArrayXf v2(4); v2 << 1, 2, 3, 4;
  91. \endcode</td><td>\code
  92. Matrix3f m1; m1 << 1, 2, 3,
  93. 4, 5, 6,
  94. 7, 8, 9;
  95. \endcode</td><td></td></tr>
  96. <tr><td>Comma initializer (bis)</td>
  97. <td colspan="2">
  98. \include Tutorial_commainit_02.cpp
  99. </td>
  100. <td>
  101. output:
  102. \verbinclude Tutorial_commainit_02.out
  103. </td>
  104. </tr>
  105. <tr class="alt"><td>Runtime info</td>
  106. <td>\code
  107. vector.size();
  108. vector.innerStride();
  109. vector.data();
  110. \endcode</td><td>\code
  111. matrix.rows(); matrix.cols();
  112. matrix.innerSize(); matrix.outerSize();
  113. matrix.innerStride(); matrix.outerStride();
  114. matrix.data();
  115. \endcode</td><td class="note">Inner/Outer* are storage order dependent</td></tr>
  116. <tr><td>Compile-time info</td>
  117. <td colspan="2">\code
  118. ObjectType::Scalar ObjectType::RowsAtCompileTime
  119. ObjectType::RealScalar ObjectType::ColsAtCompileTime
  120. ObjectType::Index ObjectType::SizeAtCompileTime
  121. \endcode</td><td></td></tr>
  122. <tr class="alt"><td>Resizing</td>
  123. <td>\code
  124. vector.resize(size);
  125. vector.resizeLike(other_vector);
  126. vector.conservativeResize(size);
  127. \endcode</td><td>\code
  128. matrix.resize(nb_rows, nb_cols);
  129. matrix.resize(StormEigen::NoChange, nb_cols);
  130. matrix.resize(nb_rows, StormEigen::NoChange);
  131. matrix.resizeLike(other_matrix);
  132. matrix.conservativeResize(nb_rows, nb_cols);
  133. \endcode</td><td class="note">no-op if the new sizes match,<br/>otherwise data are lost<br/><br/>resizing with data preservation</td></tr>
  134. <tr><td>Coeff access with \n range checking</td>
  135. <td>\code
  136. vector(i) vector.x()
  137. vector[i] vector.y()
  138. vector.z()
  139. vector.w()
  140. \endcode</td><td>\code
  141. matrix(i,j)
  142. \endcode</td><td class="note">Range checking is disabled if \n NDEBUG or STORMEIGEN_NO_DEBUG is defined</td></tr>
  143. <tr class="alt"><td>Coeff access without \n range checking</td>
  144. <td>\code
  145. vector.coeff(i)
  146. vector.coeffRef(i)
  147. \endcode</td><td>\code
  148. matrix.coeff(i,j)
  149. matrix.coeffRef(i,j)
  150. \endcode</td><td></td></tr>
  151. <tr><td>Assignment/copy</td>
  152. <td colspan="2">\code
  153. object = expression;
  154. object_of_float = expression_of_double.cast<float>();
  155. \endcode</td><td class="note">the destination is automatically resized (if possible)</td></tr>
  156. </table>
  157. \subsection QuickRef_PredefMat Predefined Matrices
  158. <table class="manual">
  159. <tr>
  160. <th>Fixed-size matrix or vector</th>
  161. <th>Dynamic-size matrix</th>
  162. <th>Dynamic-size vector</th>
  163. </tr>
  164. <tr style="border-bottom-style: none;">
  165. <td>
  166. \code
  167. typedef {Matrix3f|Array33f} FixedXD;
  168. FixedXD x;
  169. x = FixedXD::Zero();
  170. x = FixedXD::Ones();
  171. x = FixedXD::Constant(value);
  172. x = FixedXD::Random();
  173. x = FixedXD::LinSpaced(size, low, high);
  174. x.setZero();
  175. x.setOnes();
  176. x.setConstant(value);
  177. x.setRandom();
  178. x.setLinSpaced(size, low, high);
  179. \endcode
  180. </td>
  181. <td>
  182. \code
  183. typedef {MatrixXf|ArrayXXf} Dynamic2D;
  184. Dynamic2D x;
  185. x = Dynamic2D::Zero(rows, cols);
  186. x = Dynamic2D::Ones(rows, cols);
  187. x = Dynamic2D::Constant(rows, cols, value);