I can't figure out if and how it's possible to map a two-dimensional double array to an Eigen::Matrix.
Is it possible to map an array double d[][]
which I receive as double** p
to an Eigen::Matrix?
While one-dimensinal arrays work fine, I wasn't able to map p
to Eigen::Map<Eigen::Matrix<double, n, n>>
. Is that possible and how could it be done? The size n
is not really constant, but I could accept a hard coded size.
I tried several versions, but none worked. I thought the following should work (assume the size n
would be 4).
Eigen::Map<Eigen::Matrix<double, 4, 4>> p_OUTPUT(&p[0][0]);
The code compiles and runs, but only the elements of the first column and the first element of the second column map the correct values. Using p[0]
as argument yields the same result.
Other versions I tried (for example without the &
) did not compile.
n
a compile time constant? And are you surep
is adouble**
? – Hallern
is not a constant, but a hard coded size would be OK. And yes, I'm quite surep
is adouble**
becausep[row][col] += ...
works. – Daphie