Created
January 23, 2017 19:42
-
-
Save mlohry/551fbbe7a0286330010ebee0c50d6030 to your computer and use it in GitHub Desktop.
eigen map
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 <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