Error when creating row vector using map in Eigen

I am trying to map my std:vector into an Eigen row vector so I can perform element-wise multiplication. I have the error:
1
2
3
 no matching function for call to ‘Eigen::Map<Eigen::Matrix<std::complex<double>, 1, -1>, 0, Eigen::Stride<0, 0> >::Map(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 10> >::Scalar*, Eigen::EigenBase<Eigen::Matrix<double, 1, 10> >::Index)’
  179 |  Eigen::RowVectorXcd eeKX = Eigen::Map<Eigen::RowVectorXcd, Eigen::Unaligned>(eKX.data(), eKX.size());

And the code is:
1
2
3
4
5
6
7
8
9
Matrix <double, 1, nx> eKX; 
eKX.setZero();
for(int i = 0; i < nx; i++){
			eKX[i] = //some expression  
	}
Eigen::RowVectorXcd eeKX = Eigen::Map<Eigen::RowVectorXcd, Eigen::Unaligned>(eKX.data(), eKX.size()); //error here

	
std::cout << eeKX << endl;

There's no std::vector in the code snippet above?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <vector>
#include <iostream>
#include <complex>
#include <cmath>

#include <Eigen/Dense>

using namespace std::literals;

int main()
{
    std::vector<std::complex<double>> my_vector { 1.0 + 1.0i, 3.0 + 2i, 4.0 - 5.0i }; 
    Eigen::Map<Eigen::RowVectorXcd> map_of_vector(my_vector.data(), my_vector.size());

    // map_of_vector does not contain a copy of my_vector's elements
    map_of_vector *= 0.5;
    std::cout << map_of_vector << '\n';
    for (auto elt: my_vector) std::cout << elt << "  "; std::cout << '\n'; 

    // copy_of_vector contains a copy of my_vector's elements
    Eigen::RowVectorXcd copy_of_vector = map_of_vector;
    copy_of_vector *= 2;
    std::cout << copy_of_vector << '\n';
    for (auto elt: my_vector) std::cout << elt << "  "; std::cout << '\n'; 
}
Last edited on
Thanks!
Topic archived. No new replies allowed.