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.

129 lines
6.2 KiB

  1. namespace StormEigen {
  2. /** \page TopicClassHierarchy The class hierarchy
  3. This page explains the design of the core classes in Eigen's class hierarchy and how they fit together. Casual
  4. users probably need not concern themselves with these details, but it may be useful for both advanced users
  5. and Eigen developers.
  6. \eigenAutoToc
  7. \section TopicClassHierarchyPrinciples Principles
  8. Eigen's class hierarchy is designed so that virtual functions are avoided where their overhead would
  9. significantly impair performance. Instead, Eigen achieves polymorphism with the Curiously Recurring Template
  10. Pattern (CRTP). In this pattern, the base class (for instance, \c MatrixBase) is in fact a template class, and
  11. the derived class (for instance, \c Matrix) inherits the base class with the derived class itself as a
  12. template argument (in this case, \c Matrix inherits from \c MatrixBase<Matrix>). This allows Eigen to
  13. resolve the polymorphic function calls at compile time.
  14. In addition, the design avoids multiple inheritance. One reason for this is that in our experience, some
  15. compilers (like MSVC) fail to perform empty base class optimization, which is crucial for our fixed-size
  16. types.
  17. \section TopicClassHierarchyCoreClasses The core classes
  18. These are the classes that you need to know about if you want to write functions that accept or return Eigen
  19. objects.
  20. - Matrix means plain dense matrix. If \c m is a \c %Matrix, then, for instance, \c m+m is no longer a
  21. \c %Matrix, it is a "matrix expression".
  22. - MatrixBase means dense matrix expression. This means that a \c %MatrixBase is something that can be
  23. added, matrix-multiplied, LU-decomposed, QR-decomposed... All matrix expression classes, including
  24. \c %Matrix itself, inherit \c %MatrixBase.
  25. - Array means plain dense array. If \c x is an \c %Array, then, for instance, \c x+x is no longer an
  26. \c %Array, it is an "array expression".
  27. - ArrayBase means dense array expression. This means that an \c %ArrayBase is something that can be
  28. added, array-multiplied, and on which you can perform all sorts of array operations... All array
  29. expression classes, including \c %Array itself, inherit \c %ArrayBase.
  30. - DenseBase means dense (matrix or array) expression. Both \c %ArrayBase and \c %MatrixBase inherit
  31. \c %DenseBase. \c %DenseBase is where all the methods go that apply to dense expressions regardless of
  32. whether they are matrix or array expressions. For example, the \link DenseBase::block() block(...) \endlink
  33. methods are in \c %DenseBase.
  34. \section TopicClassHierarchyBaseClasses Base classes
  35. These classes serve as base classes for the five core classes mentioned above. They are more internal and so
  36. less interesting for users of the Eigen library.
  37. - PlainObjectBase means dense (matrix or array) plain object, i.e. something that stores its own dense
  38. array of coefficients. This is where, for instance, the \link PlainObjectBase::resize() resize() \endlink
  39. methods go. \c %PlainObjectBase is inherited by \c %Matrix and by \c %Array. But above, we said that
  40. \c %Matrix inherits \c %MatrixBase and \c %Array inherits \c %ArrayBase. So does that mean multiple
  41. inheritance? No, because \c %PlainObjectBase \e itself inherits \c %MatrixBase or \c %ArrayBase depending
  42. on whether we are in the matrix or array case. When we said above that \c %Matrix inherited
  43. \c %MatrixBase, we omitted to say it does so indirectly via \c %PlainObjectBase. Same for \c %Array.
  44. - DenseCoeffsBase means something that has dense coefficient accessors. It is a base class for
  45. \c %DenseBase. The reason for \c %DenseCoeffsBase to exist is that the set of available coefficient
  46. accessors is very different depending on whether a dense expression has direct memory access or not (the
  47. \c DirectAccessBit flag). For example, if \c x is a plain matrix, then \c x has direct access, and
  48. \c x.transpose() and \c x.block(...) also have direct access, because their coefficients can be read right
  49. off memory, but for example, \c x+x does not have direct memory access, because obtaining any of its
  50. coefficients requires a computation (an addition), it can't be just read off memory.
  51. - EigenBase means anything that can be evaluated into a plain dense matrix or array (even if that would
  52. be a bad idea). \c %EigenBase is really the absolute base class for anything that remotely looks like a
  53. matrix or array. It is a base class for \c %DenseCoeffsBase, so it sits below all our dense class
  54. hierarchy, but it is not limited to dense expressions. For example, \c %EigenBase is also inherited by
  55. diagonal matrices, sparse matrices, etc...
  56. \section TopicClassHierarchyInheritanceDiagrams Inheritance diagrams
  57. The inheritance diagram for Matrix looks as follows:
  58. <pre>
  59. EigenBase&lt;%Matrix&gt;
  60. <-- DenseCoeffsBase&lt;%Matrix&gt; (direct access case)
  61. <-- DenseBase&lt;%Matrix&gt;
  62. <-- MatrixBase&lt;%Matrix&gt;
  63. <-- PlainObjectBase&lt;%Matrix&gt; (matrix case)
  64. <-- Matrix
  65. </pre>
  66. The inheritance diagram for Array looks as follows:
  67. <pre>
  68. EigenBase&lt;%Array&gt;
  69. <-- DenseCoeffsBase&lt;%Array&gt; (direct access case)
  70. <-- DenseBase&lt;%Array&gt;
  71. <-- ArrayBase&lt;%Array&gt;
  72. <-- PlainObjectBase&lt;%Array&gt; (array case)
  73. <-- Array
  74. </pre>
  75. The inheritance diagram for some other matrix expression class, here denoted by \c SomeMatrixXpr, looks as
  76. follows:
  77. <pre>
  78. EigenBase&lt;SomeMatrixXpr&gt;
  79. <-- DenseCoeffsBase&lt;SomeMatrixXpr&gt; (direct access or no direct access case)
  80. <-- DenseBase&lt;SomeMatrixXpr&gt;
  81. <-- MatrixBase&lt;SomeMatrixXpr&gt;
  82. <-- SomeMatrixXpr
  83. </pre>
  84. The inheritance diagram for some other array expression class, here denoted by \c SomeArrayXpr, looks as
  85. follows:
  86. <pre>
  87. EigenBase&lt;SomeArrayXpr&gt;
  88. <-- DenseCoeffsBase&lt;SomeArrayXpr&gt; (direct access or no direct access case)
  89. <-- DenseBase&lt;SomeArrayXpr&gt;
  90. <-- ArrayBase&lt;SomeArrayXpr&gt;
  91. <-- SomeArrayXpr
  92. </pre>
  93. Finally, consider an example of something that is not a dense expression, for instance a diagonal matrix. The
  94. corresponding inheritance diagram is:
  95. <pre>
  96. EigenBase&lt;%DiagonalMatrix&gt;
  97. <-- DiagonalBase&lt;%DiagonalMatrix&gt;
  98. <-- DiagonalMatrix
  99. </pre>
  100. */
  101. }