Last active
September 23, 2022 04:52
-
-
Save mtao/5537814 to your computer and use it in GitHub Desktop.
Eigen always eats the first two values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[mtao@ruemo ~/hg/testcode/c++/eigen/head]% cat main.cpp | |
#include <Eigen/Dense> | |
#include <iostream> | |
int main(int,char**) | |
{ | |
Eigen::Matrix<double,Eigen::Dynamic,1> x(20); | |
std::iota(x.begin(),x.end(),0); | |
// 0 1 2 3 4.... | |
std::cout << x.transpose() << std::endl; | |
x = x.head(x.size()-1); | |
// for some reason this consistently eats the first two values so you get | |
// ~0 ~0 2 3 .... where ~0 seems to consistently be something like 1e-310 | |
std::cout << x.transpose() << std::endl; | |
std::iota(x.begin(),x.end(),0); | |
// Same thing now happens with new slices, but only for the first two elements | |
x = x({0,1,2,3}); | |
std::cout << x.transpose() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment