Re: [eigen] Dot product for complex vectors in Eigen
• To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
• Subject: Re: [eigen] Dot product for complex vectors in Eigen
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Mon, 28 May 2018 20:04:54 +0200
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=LclcSdYUPvNYJZoysL3AqzJi97rz1TOQEXMac/g/v5I=; b=EBThkdYy+ftQwYhOKisqj3Yw8rs3t5KQyWrhaS0YbP4FwH3pYJvxuoZbWQzKCwD/Yx CgHdO20HnTVgyOrTftLqNKhbP8KRZjCbCd9f8aYyPg8RDhc+V4CpQkaDp8dwFLy3mkEz xUSgDg6R1si3UOs5xkimGeSXosNWTGwCzHzmhhX46qyolTfIXd3RO3XBDNkKr0LYYhdE nVmJC2PzPd/zc9X0CndmG91Wl3uJbixU8p7f+PKxB1R3wBajTpsApKuMIWbRKHW6TCXg cp9fr8oWtX1IpepicLmWStP6vroJFj507+ryucSZLYH1NuyDei/Xx9rZr0qvwz95XzRs pkKw==

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 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/