Re: [eigen] Vectorwise dot product feature request

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


actually, this is more subtle :) When an inner product is detected, it
returns an InnerProduct object which can be converted into a scalar
type:

VectorXf v0, v1;

float s = v0.adjoint() * v1;

works, but that's a bit tricky to use, because for instance:

float s = 2.f * (v0.adjoint() * v1);

won't work because here the 1x1 InnerProduct object, is primarily a
1x1 matrix, and so when it is multiplied by 2.f it becomes a general
1x1 matrix which cannot be converted into a scalar (because of many
good reasons...)

gael



On Wed, Jul 7, 2010 at 2:46 PM, Márton Danóczy <marton78@xxxxxxxxx> 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
>>>
>>>
>>
>>
>>
>
>
>



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