Discussion:
[eigen] Dot product for complex vectors in Eigen
Francois Fayard
2018-05-22 14:14:57 UTC
Permalink
Hi,

I would like to get a regular “dot product” of two complex vectors a and b without any conjugate : \sum_{k = 0}^{n-1} a_k * b_k

The following code :

Eigen::VectorXcd a(
);
Eigen::VectorXcd b(
);
std::complex<double> ans = a.dot(b);

takes the conjugate of one of the vector which is not what I would like to get. What is the recommended way to do that?

Best regards,
François Fayard
Gael Guennebaud
2018-05-28 18:04:54 UTC
Permalink
You can do:

std::complex<double> ans = a.transpose()*b;

or:

std::complex<double> ans = a.cwiseProduct(b).sum();

The first version returns a 1x1 expression which implicitly convertible to
a scalar (that's the only case where that's possible). The second returns a
scalar.

gael
Post by Francois Fayard
Hi,
I would like to get a regular “dot product” of two complex vectors a and b
without any conjugate : \sum_{k = 0}^{n-1} a_k * b_k
Eigen::VectorXcd a(
);
Eigen::VectorXcd b(
);
std::complex<double> ans = a.dot(b);
takes the conjugate of one of the vector which is not what I would like to
get. What is the recommended way to do that?
Best regards,
François Fayard
Loading...