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

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


1. Yes the 5 in the matrix have to be positive.

2. Here is a small example to test the functions:

#include <iostream>
#include <eigen/matrix.h>
#include <eigen/vector.h>
using namespace Eigen;
int main(int argc, char** argv)
{
  Vector4f *v = new Vector4f(0.0f, 0.0f, -5.0f, 1.0f);
  Vector4f *result = new Vector4f();

  float matrix[] = { 1.0f, 0.0f, 0.0f, 0.0f,
                     0.0f, 1.0f, 0.0f, 0.0f,
                     0.0f, 0.0f, 1.0f, 5.0f,
                     0.0f, 0.0f, 0.0f, 1.0f};

  Matrix4f *A = new Matrix4f(matrix);

  A->multiply(*v, result);
  std::cout << "Result is: [" << result->x() << " " << result ->y()
            << " " << result->z() << " " << result->w() << "]\n";

  A->leftmultiply(*v, result);
  std::cout << "Result is: [" << result->x() << " " << result ->y()
            << " " << result->z() << " " << result->w() << "]\n";
}


I get this result:

Result is: [0 0 -5 -24]
Result is: [0 0 0 1]

Regards,

Michael


jacob@xxxxxxxxxxxxxxx schrieb:
Hi,

Please, could you send me a selfcontained, compiling test case?

Another thing, with your matrix A and your vector v,
A = [1..0..0..0]
....[0..1..0..0]
....[0..0..1.-5]
....[0..0..0..1]

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

we have:
A*v = (0 0 -10 1)
so A.multiply(v, &result) should set result to (0 0 -10 1),

and we have:
v*A = (0 0 -5 26)
so A.leftmultiply(v, &result) should set result to (0 0 -5 26).

From the values that you give it seems that you meant +5 somewhere instead of -5.

Cheers,
Benoit

Quoting Michael <michaelvsk@xxxxxx>:

Hi,
and thanks for your reply. At first I also thought that this is the
problem but then I tested it with a separate result vector and the
results are exactly the same.

Greetings
Michael

jacob@xxxxxxxxxxxxxxx schrieb:
Hello,

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.

Cheers,
Benoit

Quoting Michael <michaelvsk@xxxxxx>:

Hello,
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]
....[0..1..0..0]
....[0..0..1.-5]
....[0..0..0..1]

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?!

Greetings

Michael


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


---


---



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


---


---


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