Re: [eigen] Dot product for complex vectors in Eigen

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


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


On Tue, May 22, 2018 at 4:14 PM, Francois Fayard <fayard@xxxxxxxxxxxxx> wrote:
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



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/