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

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Confusion about MatrixBase::multiply() and MatrixBase::leftmultiply()*From*: Michael <michaelvsk@xxxxxx>*Date*: Sun, 23 Nov 2008 18:48:59 +0100

Thank you very much! I would have never found this error. :) Regards, Michael jacob@xxxxxxxxxxxxxxx schrieb:

sidenote: with eigen1, to construct a matrix from a row-major array, usereadRows().with eigen2 you could do: A << 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 5, 0, 0, 0, 1; or you could specify that your matrix itself is row-major. Cheers, Benoit Quoting jacob@xxxxxxxxxxxxxxx:aaah everything is suddenly more clear... the "matrix" array is row-major, not column-major. But the Matrix::Matrix(array) constructor expects a column-major array. So the matrix that you're effectively constructing, is the transpose of what you wanted. Cheers, Benoit PS. Any reason you do all these "new" ? Also, Eigen does provide operator<< to easily print a matrix or vector; and you don't need to include both matrix.h and vector.h. And, let me encourage you to switch to eigen2 :) Quoting Michael <michaelvsk@xxxxxx>: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]^Twe 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 somewhereinstead 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 manythat were fixed. With Eigen2, there is no multiply() andleftmultiply()functions anymore, there is only * and *=, so you just do vec *=matrixor vec = vec * matrix, and it automatically handles aliasing;moreoverif you know that there is no aliasing involved here (because thesourceand 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]^Tthen A.multiply(*v, v) is [0 0 -5 24]^T but it should be [0 0 01]^T.And A.leftmultiply(*v, v) is [0 0 0 1]but it should be [0 0 -524]^T.If it possible that someone has confound something here? Or isit my mistake?!Greetings Michael---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ---------------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ---------------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ---

---

**References**:**[eigen] Confusion about MatrixBase::multiply() and MatrixBase::leftmultiply()***From:*Michael

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

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

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

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

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

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

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Confusion about MatrixBase::multiply() and MatrixBase::leftmultiply()** - Next by Date:
**[eigen] delaying beta2 a bit?** - Previous by thread:
**Re: [eigen] Confusion about MatrixBase::multiply() and MatrixBase::leftmultiply()** - Next by thread:
**[eigen] delaying beta2 a bit?**

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