Skip to content

Instantly share code, notes, and snippets.

@RyodoTanaka
Created February 18, 2020 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyodoTanaka/250bf8c17c72d5615732875f0501b7d6 to your computer and use it in GitHub Desktop.
Save RyodoTanaka/250bf8c17c72d5615732875f0501b7d6 to your computer and use it in GitHub Desktop.
Eigen Vector push_back
#include <Eigen/Core>
namespace Eigen {
namespace Vector {
template <class T>
inline void push_back(Eigen::Matrix<T,Eigen::Dynamic,1>& v, const T d) {
Eigen::Matrix<T,Eigen::Dynamic,1> tmp = v;
v.resize(tmp.size() + 1);
v.head(tmp.size()) = tmp;
v[v.size()-1] = d;
}
} // namespace Vector
} // namespace Eigen
int main(void) {
Eigen::VectorXd a;
Eigen::VectorXi b;
Eigen::Vector::push_back<double>(a,3.5);
Eigen::Vector::push_back<int>(b,2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment