Search code examples
c++eigen

Eigen::Vector declare with max entries at compile time?


Is there a way to declare an instance of Eigen::Vector while specifying the max. number of elements at compile time? For the case of Eigen::Matrix it is possible to do it via

Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,Eigen::ColMajor,128,128> myMat;

but I don't seem to find a way to do it for Eigen::Vector. Thanks!


Solution

  • Eigen::Vector is just an alias template for an Eigen::Matrix of column size 1, without allowing to specifying an argument for the _MaxRows template parameter of the aliased Eigen::Matrix class template.

    Global matrix typedefs

    template<typename Type , int Size>
    using     Eigen::Vector = Matrix< Type, Size, 1 >
    

    You could always setup your own custom alias that would allow forwarding an argument to _MaxRows:

    template<typename Type, int Size, int MaxRows>
    using MyMaxSizedVector = Eigen::Matrix< Type, Size, 1, Eigen::ColMajor, MaxRows>;