[eigen] Blockwise matrix multiplication |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
Hi all,
I have a problem that reduces to a matrix multiplication on blocks around the main diagonal, and I want to verify with you guys if my coding approach is the best possible using Eigen.
I'll illustrate with a concrete example:
Suppose I have a 20x100 source matrix (20 rows, 100 columns).
I need to construct a target matrix, where every consecutive four rows of the source matrix are summarized as three rows using a 3x4 weighting matrix. The target matrix will thus be 15x100, with each group of three consecutive rows being a linear combination of four consecutive rows in the source matrix.
What I do now (and it works fine):
Eigen::MatrixXd source(20,100);
Eigen::MatrixXd target(15,100);
for (int i = 0; i < 5; ++i)
{
Eigen::Matrix<double, 3, 4> weights = getWeights(i);
target.block(3 * i, 0, 3, 100) = weights * source.block(4 * i, 0, 4, 100);
}
.... I was wondering if the code could be written any smarter than this; specifically, without an explicit loop (e.g. using a sparse weighting matrix or something like that). Any feedback is greatly appreciated.
Best regards, Sidney