I have an Eigen::Matrix<double, M, N> matrix;
and I have a function that needs only a 3x3 slice and modifies it
void ModifyBlock(Eigen::Matrix<double, 3, 3> & block){
// A stupid example
block += Eigen::Matrix<double, 3, 3>::Identity();
}
Passing a slice of the original matrix is not possible as the following code fails to compile:
int main(int argc, char *argv[]){
const int M = 10;
const int N = 20;
Eigen::Matrix<double, M, N> matrix;
// Initialize matrix
ModifyBlock(matrix(vector<int>{1,3,7}, vector<int>{0,2,4});
return 0;
}
cannot bind non-const lvalue reference of type ‘Eigen::Matrix<double, 3, 3>&’ to an rvalue of type ‘Eigen::Matrix<double, 3, 3>
I wonder if there is a way to do this.
In the documentation I could not find a mention of that the slices are necessarily constant references.
Aucun commentaire:
Enregistrer un commentaire