You should be using conservativeResize
for tasks like this. The error is a type of aliasing; you're overwriting the data which you're reading from (although, in this case, I believe eigen will throw an explicit error for it)
Head function in eigen3 produces wrong result
-
02-06-2022 - |
Question
I want to get a subset of the vector s, the following code didn't give the right result. But if I write
VectorXd e=s.head(svp)
e is right. Why the following code is wrong? Thanks!
Eigen::JacobiSVD<Eigen::MatrixXd> svd(input, Eigen::ComputeThinU |
Eigen::ComputeThinV);
VectorXd s=svd.singularValues();
int svp=5;
s=s.head(svp); //Wrong!
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow