XapaJIaMnu
XapaJIaMnu

Reputation: 1500

How to check if Eigen Matrix is column major or row major?

I need to use the underlying arrays of several eigen matrices that could be RowMajor or ColumnMajor.

Is there any way to check which of the formats is used? (besides comparing the first column, with the first n elements of the row/column)

I found the isRowMajor as part of an Enum in the base class for Eigen, but I don't know how to access it from inside my code.

Upvotes: 13

Views: 4886

Answers (1)

MagunRa
MagunRa

Reputation: 563

The following works for me (EigenMatrixType is anything derived from Eigen::MatrixBase)

EigenMatrixType M(...);   
std::cout << "IsRowMajor?: " << M.IsRowMajor << std::endl;

(edit: It seems to work also with SparseMatrix, even if i cannot find the enum in the the SparseMatrixBase documentation)

Upvotes: 14

Related Questions