Search code examples
c++eigen

eigen: get next block of the matrix with stride =2


Does Eigen support getting next block with stride =2?

I observed the default behavior is with stride =1 in this:

m.block<F, F>(i, j)

I am looking for solution which can give me next block with non-1 stride as shown in the animated Convolution Demo in the following link:

http://cs231n.github.io/convolutional-networks/

If Eigen does not support it, what would be a good way of indexing to get next block with stride=k?


Solution

  • With the new slicing and indexing API which will be introduced in Eigen 3.4 (currently in the master branch), you can write Matlab-Style slicing, e.g.,

       M(Eigen::seqN(i, Eigen::fix<F>, Eigen::fix<stride>),
         Eigen::seqN(j, Eigen::fix<F>, Eigen::fix<stride>));
    

    Returns a block starting at (i,j) of size F x F with stride. The Eigen::fix are optional, but may give slightly better runtime.

    Working example: https://godbolt.org/z/wzRdp7

    More documentation: http://eigen.tuxfamily.org/dox-devel/group__TutorialSlicingIndexing.html

    With Eigen 3.3 you need to write some Map-based solution as suggested by @AviGinsburg.