I want to change the content of a matrix A, of type Eigen::MatrixXd, by blocks in Eigen, the dimensions of the blocks are known at compilation time. I want to get the best performance possible capitalizing on the fact that the size of the blocks are known at compilation time. What is the best approach?
In the minimal example below, I am assuming that the size of the block is 2x2, but in my actual implementation I will be using blocks of known sizes n1xn2. I also need to pass constant blocks of a matrix as an argument to another function that are also of known size, how can I do that with the best performance in Eigen?
#include <Eigen/Dense>
#include <iostream>
template <typename derived>
void change_block(Eigen::MatrixBase<derived> &M){
M=Eigen::MatrixXd::Identity(2,2);
}
int main()
{
Eigen::MatrixXd A(10,10);
std::cout << "Here is the initial matrix:" << endl << A << endl << endl;
auto A_block = A.block<2,2>(0,0);
change_block(A_block);
std::cout << "Here is the matrix after the change:" << endl << A << endl << endl;
}
I have used only basic features of Eigen. Therefore, explanatory comments that allow to understand the suggested approach in deep will be appreciated. I will bw considering rectangular blocks of size between 1x1 and 15x15.
Aucun commentaire:
Enregistrer un commentaire