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

1

13

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.

Unending answered 31/7, 2014 at 12:27 Comment(0)
T
14

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)

Tingey answered 31/7, 2014 at 12:46 Comment(2)
Thanks, for solving it, sorry for the stupid question.Unending
Note: It appears there's no M.IsColMajor (but obviously !M.IsRowMajor works).Matteo

© 2022 - 2024 — McMap. All rights reserved.