Re: [eigen] Confusion about MatrixBase::multiply() and MatrixBase::leftmultiply()

[ Thread Index | Date Index | More Archives ]


The problem here is that multiply(vector, result) and
leftmultiply(vector, result) assume that vector is different from
*result. In your case you tried to apply these methods with the same
vector on both sides, and that produces a wrong result because the
vector has been partly updated when it is used again to compute the
rest of the product. This is called an aliasing effect.

I can see that I forgot to mention that in the documentation.

Please consider to port to Eigen2, as this issue is one of the many
that were fixed. With Eigen2, there is no multiply() and leftmultiply()
functions anymore, there is only * and *=, so you just do vec *= matrix
or vec = vec * matrix, and it automatically handles aliasing; moreover
if you know that there is no aliasing involved here (because the source
and destination vectors are distinct) then you can do: dest_vec =
(src_vec * matrix).lazy() to force lazy-evaluation i.e. remove the
temporary variable and compute the product in place like eigen1's
multiply() and leftmultiply() did.


Quoting Michael <michaelvsk@xxxxxx>:

I have a problem with Eigen 1.05 and the functions
MatrixBase::multiply() and MatrixBase::leftmultiply().

The help says that MatrixBase::multiply() computes *this * vector.
and MatrixBase::leftmultiply() cumputes vector * *this (where vector
will be transposed).

But if I have the matrix

A = [1..0..0..0]

and the vector v = [0 0 -5 1]^T

then A.multiply(*v, v) is [0 0 -5 24]^T but it should be [0 0 0 1]^T.

And A.leftmultiply(*v, v) is [0 0 0 1]but it should be [0 0 -5 24]^T.

If it possible that someone has confound something here? Or is it my mistake?!



This message was sent using IMP, the Internet Messaging Program.


Mail converted by MHonArc 2.6.19+