Search code examples
c++eigeneigen3

what does the rows() method do?


In the eigen documentation, which is generally pretty good, I see references to a rows() method of MatrixBase. I am currently trying to find a way to get the number of rows in a matrix without knowing the orientation (Row/Column-major) of the matrix so it would be really convenient to simply call rows().

But I can't find this documented anywhere. What is this method? What does it do? Does it just return Eigen::Dynamic for dynamic matrices, or does it know the number of rows?

Looking at the reference page for MatrixBase, I see several mentions of MatrixBase::rows() but no link... Any ideas?


Solution

  • The rows() method does indeed return the numbers of rows. It is defined in the class EigenBase, of which MatrixBase is a subclass. Its documentation is at http://eigen.tuxfamily.org/dox/structEigen_1_1EigenBase.html#a5552abd83dbd03c85cea6d61fd8875a5 . One way to find it is to type "rows" in the search field in the upper right of the Eigen documentation and then to click "rows" in the popup that appears; that opens a list of rows() methods defined in the library, including EigenBase::rows().

    The documentation does not say this explicitly, but the rows() method does return the actual number of rows, determined at run-time. The constant RowsAtCompileTime returns Dynamic for dynamic-size matrices and the number of rows for static-size matrices.

    The mentions to MatrixBase::rows() in the documentation is a remnant of the past that needs to be eliminated. Thanks for your compliments about the documentation, but we know it can be improved.