The class hierarchy

This page explains the design of the core classes in Eigen's class hierarchy and how they fit together. Casual users probably need not concern themselves with these details, but it may be useful for both advanced users and Eigen developers.

Table of contents

Principles

Eigen's class hierarchy is designed so that virtual functions are avoided where their overhead would significantly impair performance. Instead, Eigen achieves polymorphism with the Curiously Recurring Template Pattern (CRTP). In this pattern, the base class (for instance, MatrixBase) is in fact a template class, and the derived class (for instance, Matrix) inherits the base class with the derived class itself as a template argument (in this case, Matrix inherits from MatrixBase<Matrix>). This allows Eigen to resolve the polymorphic function calls at compile time.

In addition, the design avoids multiple inheritance. One reason for this is that in our experience, some compilers (like MSVC) fail to perform empty base class optimization, which is crucial for our fixed-size types.

The core classes

These are the classes that you need to know about if you want to write functions that accept or return Eigen objects.

Base classes

These classes serve as base classes for the five core classes mentioned above. They are more internal and so less interesting for users of the Eigen library.

Inheritance diagrams

The inheritance diagram for Matrix looks as follows:

EigenBase<Matrix>
  <-- DenseCoeffsBase<Matrix>    (direct access case)
    <-- DenseBase<Matrix>
      <-- MatrixBase<Matrix>
        <-- PlainObjectBase<Matrix>    (matrix case)
          <-- Matrix

The inheritance diagram for Array looks as follows:

EigenBase<Array>
  <-- DenseCoeffsBase<Array>    (direct access case)
    <-- DenseBase<Array>
      <-- ArrayBase<Array>
        <-- PlainObjectBase<Array>    (array case)
          <-- Array

The inheritance diagram for some other matrix expression class, here denoted by SomeMatrixXpr, looks as follows:

EigenBase<SomeMatrixXpr>
  <-- DenseCoeffsBase<SomeMatrixXpr>    (direct access or no direct access case)
    <-- DenseBase<SomeMatrixXpr>
      <-- MatrixBase<SomeMatrixXpr>
        <-- SomeMatrixXpr

The inheritance diagram for some other array expression class, here denoted by SomeArrayXpr, looks as follows:

EigenBase<SomeArrayXpr>
  <-- DenseCoeffsBase<SomeArrayXpr>    (direct access or no direct access case)
    <-- DenseBase<SomeArrayXpr>
      <-- ArrayBase<SomeArrayXpr>
        <-- SomeArrayXpr

Finally, consider an example of something that is not a dense expression, for instance a diagonal matrix. The corresponding inheritance diagram is:

EigenBase<DiagonalMatrix>
  <-- DiagonalBase<DiagonalMatrix>
    <-- DiagonalMatrix


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:34:08