Hello Ninja, Welcome again. As we have covered many articles on Eigen, you might be very confident about this topic. You must have thought about how difficult it would be to perform all maths calculations manually.
In this article, we will cover Eigen's class hierarchy. Before that, let’s move with the introduction of Eigen.
What is Eigen?
Eigen is a C++ library. It has several uses and can help with challenging maths-related operations, including the dot and cross product, multiplication, and different algebraic operations.
This collection is a boon for everyone who works in the robotics sector. It helps in doing several tasks and has many robotics applications.
It is having algorithms for linear algebra, geometric transformations, numerical solvers, matrix operations, and vector operations. We may simplify the task of programmers by using the Eigen library.
So, let’s start with Eigen's class hierarchy.
Eigen's Class Hierarchy
In Eigen, we deal with Eigen's Class Hierarchy very much. We generally avoid Virtual functions in situations where their overhead would noticeably reduce performance according to the way Eigen's class hierarchy is built. Instead, Eigen uses the Curiously Recurring Template Pattern to achieve polymorphism (CRTP).
CRTP: In order to prevent duplicating that method or other such functions in each derived class, the CRTP can be used.
In this way, the derived class (for ex., Matrix) inherits from the base class by using the derived class itself as a template parameter. The base class (for ex., MatrixBase) is really a template class. This enables Eigen to handle the calls to polymorphic functions during compilation.
The design also prevents multiple inheritances. Some compilers (like MSVC), which are essential for our fixed-size types, do not empty base class optimisation.
As we have covered some briefs of Eigen's class hierarchy, we now move to core classes and base classes. Before that, we will cover the topic ‘Dense’ in brief.
Dense in Eigen
All of the member functions for such MatrixXd type are defined in the Eigen/Dense header file. This header file's classes and functions are all under the Eigen namespace.
Core Classes
You must be aware of these classes if you wish to create functions that take or return Eigen objects.
The term dense array expression is ArrayBase. As a result, an ArrayBase can be multiplied by an array, added to, and used for various array operations.
Array simply refers to a dense array. For example, if x is an array, then x+x is an "array expression" rather than an array.
DenseBase denotes a dense expression (matrix or array). DenseBase is inherited by ArrayBase and MatrixBase alike. All the methods that are applicable to dense expressions, whether they are matrix or array expressions, go into the DenseBase class. Block(...) methods, for ex., are present in DenseBase.
A dense matrix expression is referred to as MatrixBase. Thus, a MatrixBase is an object that can be added to, multiplied by a matrix, decomposed into LU(lower-upper) and QR(orthogonal and upper triangular) and more. MatrixBase is inherited by all matrix expression classes, including Matrix itself.
It seems a little confusing but read it completely, you will surely get benefits from this blog, and it become easier for you.
Base Classes
The five core classes use these classes as their foundation.
Matrix
MatrixBase
Array
ArrayBase
DenseBase
Since they are internal, Eigen library users will find them less useful.
Array and Matrix are both derived from PlainObjectBase. The term "plainObject" refers to a dense (matrix or array) plain object. For example, the set() and resize() functions are located here.
DenseBase's base class is called DenseCoeffsBase. Depending on whether an expression uses direct memory access. It has distinct accessors for dense expressions.
The whole base class for everything that even somewhat resembles a matrix or array is EigenBase. Although it is not just for dense expressions, it lies below the whole dense class hierarchy. Diagonal matrices, sparse matrices, etc., may all inherit from EigenBase as well.
Inheritance Diagrams
The Matrix inheritance diagram appears as follows:
The Array inheritance diagram looks like this:
The following is the inheritance diagram for another matrix expression class, now denoted by SomeMatrixXpr:
The following is the inheritance diagram for some other type of array expression, here denoted by SomeArrayXpr:
Finally, examine an illustration of a non-dense statement, such as a diagonal matrix. The inheritance chart that corresponds to this is:
Finally, we have covered Eigen's class hierarchy with the Inheritance diagram. Now it's time to look over some FAQ’s.
The unique set of scalar values known as Eigen values is connected to the linear equations found in matrix equations.
Does Eigen library employ Cuda?
Eigen is a wonderful library that can now be used inside CUDA kernels since version 3.3.
Is Eigen suitable with R?
For R, the RcppEigen package offers bindings and other features.
Does Eigen make use of OpenMP?
Eigen utilises the number of threads supplied by OpenMP unless setNbThreads is called.
Is Eigen compatible with Java?
Yes, there is a Java wrapper for Eigen called “jeigen”.
Conclusion
This article briefly discussed Eigen's class hierarchy, Core and Base Classes, and Inheritance Diagram. For more information on Eigen and related topics, refer to the following articles: