I've noticed some unexpected behaviour in Eigen:
int n=10; //value is irrelevant
Eigen::MatrixXd A(n);
Eigen::VectorXd v(n);
//works:
Eigen::MatrixXd B = A;
B += v.asDiagonal();
//error:
Eigen::MatrixXd C = A + v.asDiagonal();
In the second case, the compiler complains that there is no suitable operator+ availaible taking a MatrixXd and a DiagonalWrapper<...>. (The same holds for other operators as well).
Is this intended? And if yes, is there a neat way around the two-line alternative (first assign, then subtract)?
Unfortunately that seems to be the expected behaviour (probably due to optimisation reasons, but it's just a guess). You can, however, do the following:
Eigen::MatrixXd C = A + v.asDiagonal().toDenseMatrix();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With