'Which is the fastest method to reshape a vector to a matrix of overlapping windows in C++ using Eigen library?

Let's suppose you have a vector of N elements and you want to create a n by m matrix made of stacked overlapping windows sliced from the original vector. Which is the fastest way to perform this operation in C++ using Eigen library?

for ex (N = 7, window_length(m) = 3, overlap = 2):

0, 1, 2, 3, 4, 5, 6 -> 0, 1, 2
                       1, 2, 3
                       2, 3, 4
                       3, 4, 5
                       4, 5, 6

where m and overlap must be parametric.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source