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.

133 lines
6.4 KiB

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