I'm trying to understand the debug output of CodeLLDB in vs-code. I have two programs doing almost the same thing, but while debugging, I can see the following difference:
The way an Eigen matrix is displayed differs. In program A, a matrix is shown as
Eigen::Matrix<float, 4, 4, 4, 4, 4>
and in program B a similar matrix is shown as
Eigen::Matrix<float, -1, -1, 0, -1, -1>
in the CodeLLDB debugger.
This is after only initializing the matrices (before resizing them to some required number of rows and columns). What do these numbers indicate? (they clearly are not related to the matrix size...)
The Matrix
class is documented here. A Matrix
is a templated class allowing standard numeric or user defined types, dynamic or fixed sizing for rows and columns and other options. The signature is:
template<typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_> class Eigen::Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ >
The Scalar_
is the type of the matrix, float
, double
, int
, whatever.
Rows_
and Cols_
are the sizes of the matrix. Dynamic
is a constant -1
. If a positive quantity is not provided at compile time this tells Eigen
that the matrix is dynamic. These values are related to MaxRows_
and MaxCols_
.
Options_
is the most complicated one.
Options_ A combination of either RowMajor or ColMajor, and of either AutoAlign or DontAlign. The former controls storage order, and defaults to column-major. The latter controls alignment, which is required for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size.
There is an enum
in Constants.h that defines some of the values. Normally 0
is there as most matrices are defaulted to be auto-aligned and column major. RowMajor
is 1
and DontAlign
is 2
.
So to decode your two matrices:
Matrix<float,4,4,4,4,4>
is a matrix holding float
values of fixed size 4 x 4 with option of 4
. Note that 4
is not a valid template parameter so some operation has happened on that matrix which set the options to that value. This is equivalent to the typedef Matrix4f
(again with some other operation).
Matrix<float,-1,-1,0,-1,-1>
is a matrix holding float
values of dynamic size that is column-major and auto aligned. This is equivalent to MatrixXf
.