Do not use auto
when initializing your matrices, as it will make A = B
a shallow copy. auto
will also cause other unexpected results. Use MatrixXd
instead.
#include <iostream>
#include "Eigen/Dense"
using namespace Eigen;
typedef Matrix<double,Dynamic,Dynamic,RowMajor> MyMatrix;
int main()
{
double a[] = {1,2,3,4};
auto M = Map<MyMatrix>(a, 2, 2);
auto G = M;
MatrixXd g = M;
G(0,0) = 0;
std::cout << M << "\n" << std::endl;
std::cout << G << "\n" << std::endl;
std::cout << g << "\n" << std::endl;
}
The codes would output:
0 2
3 4
0 2
3 4
1 2
3 4