Re: [eigen] Vectorwise dot product feature request |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Vectorwise dot product feature request
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Wed, 7 Jul 2010 18:11:18 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=L6ktRFpKJYICKuTCoXlm0Sq3uSv6P63WentGJjgw+m4=; b=oHk6ASxliquHdjkKiAu3NiDLUYKWD0Jxy+HY+I3DDDvIKdTpToHZF62QAj6HeocurZ /dO0voaAfK7UeW33A98Wq3TyIJknMm+YcrPYJyuQGI1mhly++bVPV8HjKGRcaIeao2Se r6rPKxZyPBgSCdUSr7GdaYibqO9mAOiwRkArE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=M21du+n+3l/+EZTB7+Yg7YlVr/H7INY1zAtyit62kcHl4bDeqtpf57IpuI2N7KVvpM DwEl+qcf72kIgd8epG9mkrCZyRUMyTqwfT/IS2gNWcOO4mrzqgtFR9Nd/gUotpzBIb2k eWwZHUV7ovAtymoFZmxc3wpQz8hu9xOD2n5BY=
Indeed, the broadcasting functions are just shortcut for what Hauke
proposed, and I think it would make sense to also add one for coeff
wise products. The problem is that currently the col/row-wise API is
100% common between Array and Matrix, and we have to split it first
that is a very boring task.... so be patient ;)
gael
On Wed, Jul 7, 2010 at 4:29 PM, Hauke Heibel
<hauke.heibel@xxxxxxxxxxxxxx> wrote:
> It is already possible. You can choose one of the following methods:
>
> mat.array() *= Replicate<Vector2d,1,Dynamic>(vec,1,mat.cols()).array();
> mat.array() *= vec.replicate(1,mat.cols()).array();
>
> Here, they have probably the same performance.
>
> - Hauke
>
> On Wed, Jul 7, 2010 at 4:22 PM, Johan Pauwels
> <johan.pauwels@xxxxxxxxxxxxx> wrote:
>> On 2010-07-07 15:40, Gael Guennebaud wrote:
>>>
>>> actually, this is more subtle :) When an inner product is detected, it
>>> returns an InnerProduct object which can be converted into a scalar
>>> type:
>>>
>>
>> Interesting explanation, thanks.
>>
>> I have another vectorwise question/request. I'd like to broadcast a
>> coefficient-wise product like "mat.array().colwise() *= vec.array()". Is it
>> possible to do this now? Or will it be in the future?
>>
>> Kind regards,
>> Johan
>>>
>>>
>>> On Wed, Jul 7, 2010 at 2:46 PM, Márton Danóczy<marton78@xxxxxxxxxx> wrote:
>>>
>>>>
>>>> Because .dot() returns a scalar, whereas multiplication returns an 1x1
>>>> matrix.
>>>>
>>>> Marton
>>>>
>>>>
>>>>
>>>> On 7 July 2010 14:15, Johan Pauwels<johan.pauwels@xxxxxxxxxxxxx> wrote:
>>>>
>>>>>
>>>>> On 2010-07-07 13:02, Aron Ahmadia wrote:
>>>>>
>>>>> That looks suspiciously like a transposed multiply to me...
>>>>>
>>>>> Ugh, exactly. Sorry for the bother. My mind was so set on a collection
>>>>> of
>>>>> independent columns and broadcasting operations, that I forgot the basic
>>>>> matrix multiplication. One might wonder why there even is a .dot()
>>>>> syntax?
>>>>>
>>>>> Regards,
>>>>> Johan
>>>>>
>>>>> A
>>>>>
>>>>> On Wed, Jul 7, 2010 at 1:59 PM, Johan
>>>>> Pauwels<johan.pauwels@xxxxxxxxxxxxx>
>>>>> wrote:
>>>>>
>>>>>>
>>>>>> Hello all,
>>>>>>
>>>>>> Would it be possible to allow a vectorwise dot product as in the
>>>>>> example
>>>>>> below?
>>>>>>
>>>>>> #include<Eigen/Core>
>>>>>>
>>>>>> int main()
>>>>>> {
>>>>>> Eigen::MatrixXf mat = Eigen::MatrixXf::Random(5,2);
>>>>>> Eigen::VectorXf vec = Eigen::VectorXf::Random(5);
>>>>>> Eigen::RowVectorXf result(2);
>>>>>>
>>>>>> // this syntax
>>>>>> result = mat.colwise().dot(vec);
>>>>>> // instead of this for loop
>>>>>> for (int i = 0; i< mat.cols(); ++i)
>>>>>> {
>>>>>> result[i] = mat.col(i).dot(vec);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> Regards,
>>>>>> Johan
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>>
>
>
>