![]() Registered Member ![]()
|
Hi,
I'm new to Eigen and need some help. I tried searching through the forums but only found 1 post that was similar to my issue (see viewtopic.php?f=74&t=89083&p=164378&hilit=how+to+use+map ). However, what I thought was the answer to my question produces compile errors. Here is my setup: double array[12] = {1,2, 3,4, 5,6, 7,8, 9,0, 9,8}; //I want to map this array into a complex matrix: Map<MatrixXcd> A(array, 2, 3); But I get the following compile error: error: no matching function for call to Eigen::Map<Eigen::Matrix<std::complex<double>, 10000, 10000, 2, 10000, 10000>, 1>::Map(const double*&, int, int) eigen/Eigen/src/Core/Map.h:78: note: candidates are: Eigen::Map<MatrixType, PacketAccess>::Map(const typename Eigen::ei_traits<Eigen::Map<MatrixType, _PacketAccess> >::Scalar*, int, int) [with MatrixType = Eigen::Matrix<std::complex<double>, 10000, 10000, 2, 10000, 10000>, int PacketAccess = 1] eigen/Eigen/src/Core/Map.h:76: note: Eigen::Map<MatrixType, PacketAccess>::Map(const typename Eigen::ei_traits<Eigen::Map<MatrixType, _PacketAccess> >::Scalar*, int) [with MatrixType = Eigen::Matrix<std::complex<double>, 10000, 10000, 2, 10000, 10000>, int PacketAccess = 1] eigen/Eigen/src/Core/Map.h:74: note: Eigen::Map<MatrixType, PacketAccess>::Map(const typename Eigen::ei_traits<Eigen::Map<MatrixType, _PacketAccess> >::Scalar*) [with MatrixType = Eigen::Matrix<std::complex<double>, 10000, 10000, 2, 10000, 10000>, int PacketAccess = 1] eigen/Eigen/src/Core/Map.h:61: note: Eigen::Map<Eigen::Matrix<std::complex<double>, 10000, 10000, 2, 10000, 10000>, 1>::Map(const Eigen::Map<Eigen::Matrix<std::complex<double>, 10000, 10000, 2, 10000, 10000>, 1>&) Any help would be appreciated. Thanks, Edward |
![]() Moderator ![]()
|
your "array" is of type double* while your are mapping a MatrixXcd which is a matrix of std::complex<double> and so the ctor of Map is expecting a std::complex<double>*. Use MatrixXd (without the 'c') for a matrix of double.
|
![]() Registered Member ![]()
|
Sorry about not being so clear. The goal is to take an array of doubles, which in reality are complex numbers: real interleaved with imag, and map them to a Matrix of complex doubles.
So the array I had previously specified:
is really meant to be a "3x2" matrix of complex doubles. For example, the (1,1) element would be 1+2i. In the link I included in my original post, the thread seemed to suggest that you can use Map<MatrixXcd> as long as the real and imag doubles were interleaved with each other in a single double array. Obviously, this was not the correct conclusion. The question is, is there anyway to take an array of doubles and map them to a complex matrix? Couple notes: 1] The code I show is not the actual code that is being used. Meaning, I cannot change it and just specify array to be a std::complex<double> array. The interface I am working with dictates that I will receive a ptr to an array of complex doubles, real interleaved with imag. 2] I realize that I said "3x2" matrix above, implying row-dominance(?) but that in playing around with Map<MatrixXd> (note, no "c" in the Matrix), it seems that mappings are column-dominant. That is fine. Whether the map comes out transposed or not is not a big issue. I just want to get the mapping to work. |
![]() Moderator ![]()
|
you simply have to cast your pointer:
Map<MatrixXcd> A(reinterpret_cast<std::complex<double>*>(array), 3, 2); and if you wan a row major mapping: typedef Matrix<double,Dynamic,Dynamic,RowMajor> RowMajorMatrixXcd; Map<RowMajorMatrixXcd> A(....); |
![]() Registered Member ![]()
|
Thanks for the response. I didn't realize that for the std::complex<double> object the memory was all laid out contiguously, hence allowing for a straight cast. I tried it out and it worked perfectly. Thanks!
Also thanks for the tip on row-dominance. |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]