Skip to content

Instantly share code, notes, and snippets.

@mlohry
Created January 23, 2017 19:42
Show Gist options
  • Save mlohry/551fbbe7a0286330010ebee0c50d6030 to your computer and use it in GitHub Desktop.
Save mlohry/551fbbe7a0286330010ebee0c50d6030 to your computer and use it in GitHub Desktop.
eigen map
#include <iostream>
#include <Eigen/Dense>
int main(){
Eigen::MatrixXd A(3,2); // 3x2 dynamically sized matrix
A << 0,1,2,
3,4,5;
std::cout << "A=\n" << A << "\n";
// this one *copies* the values into a column vector
// Eigen::MatrixXd Avec(Eigen::Map<Eigen::MatrixXd>(A.data(), A.cols()*A.rows(), 1));
// this one *remaps* the values by reference into a column vector
Eigen::Map<Eigen::MatrixXd> Avec = Eigen::Map<Eigen::MatrixXd>(A.data(), A.cols()*A.rows(), 1);
std::cout << "Avec=\n" << Avec << "\n";
std::cout << "Modifying vector\n";
Avec(2,0) = 9.9;
std::cout << "Avec=\n" << Avec << "\n";
std::cout << "A=\n" << A << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment