Today I encountered a weird problem when using Eigen library with keyword auto. The scenario is as follows:
Eigen::Affine3d aff;
// aff is assigned with a valid value ...
auto r = aff.rotation();
auto res = r * r;
In the end, the result variable res contains a 3x3 matrix with only zero values, no matter what values aff has. After a bit of googling, I found out some relevant issues and Eigen documentation:
- Eigen auto type deduction in general product
- Eigen and C++11 type inference fails for Cholesky of matrix product
- Lazy Evaluation and Aliasing
I still have not quite understand this issue. As a temporary solution, using auto with Eigen library should be avoided as much as possible.
I will post another article once I understand it fully.