Created
February 18, 2020 05:41
-
-
Save RyodoTanaka/250bf8c17c72d5615732875f0501b7d6 to your computer and use it in GitHub Desktop.
Eigen Vector push_back
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
#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