Skip to content

Instantly share code, notes, and snippets.

@mtao
Last active September 23, 2022 04:52
Show Gist options
  • Save mtao/5537814 to your computer and use it in GitHub Desktop.
Save mtao/5537814 to your computer and use it in GitHub Desktop.
Eigen always eats the first two values
[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