Using eigen2, and given a matrix A
a_0_0, a_0_1, a_0_2, ...
a_1_0, a_1_0, a_1_2, ...
...
and a matrix B:
b_0_0, b_0_1, b_0_2, ...
b_1_0, b_1_1, b_1_2, ...
...
and where A and B have the same dimensions, I would like to interleave the rows, producing:
a_0_0, a_0_1, a_0_2, ...
b_0_0, b_0_1, b_0_2, ...
a_1_0, a_1_0, a_1_2, ...
b_1_0, b_1_1, b_1_2, ...
...
Obviously I can write a function that will construct an output matrix of the proper dimensions, then loop over each of the input matrices and assign elements to the result. I’d rather not re-invent the wheel though, so if eigen2 already has a mechanism to express this sort of matrix surgery elegantly I’d much prefer to use it.
I did look through the eigen2 docs and nothing jumped out at me as obviously correct. The closest thing I found was MatrixBase::select, but that does ‘element from a or element from b’, where what I want is ‘element from a then element from b in the next row’.
Efficiency is not of paramount concern since I don’t need to do this in the fast path, only at initialization.
I apologize for the formatting if there is a better way to represent matrices.
Multiply each R x C matrix by a 2R x R matrix consisting of zeroes and ones on the appropriate diagonal, then add.
Matrix 1
Matrix 2