Skip to content

Slicing with Eigen::seq and Eigen::last is not compile time size

Summary

According to the documentation, slicing with Eigen::seq using Eigen::last and Eigen::fix should have compile time size, but it doesn't.

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : 3.4.0
  • Compiler Version : Gcc12.2
  • Compile Flags : -std=c++14 -O3 -Wall -Wextra -DNDEBUG=1
  • Vector Extension : -

Minimal Example

Godbold Link

int main()
{
    Eigen::Vector<double, 10> v;
    for (int i = 0; i < 10; i++) {
        v(i) = i;
    }

    auto slice = v(Eigen::seq(Eigen::last - Eigen::fix<2>, Eigen::last - Eigen::fix<1>));

    std::cout << "rows: " << decltype(slice)::RowsAtCompileTime << std::endl; // rows: -1
    std::cout << "slice: " << slice.transpose() << std::endl; // slice: 7 8
    return 0;
}

Steps to reproduce

See Minimal Example.

What is the current bug behavior?

RowsAtCompileTime of the slice is Dynamic(-1).

What is the expected correct behavior?

RowsAtCompileTime of the slice is not Dynamic(-1), i.e., 2 in the minimal example.