Re: [eigen] Possible bug in vector-matrix multiplication? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Possible bug in vector-matrix multiplication?
- From: Manoj Rajagopalan <rmanoj@xxxxxxxxx>
- Date: Tue, 1 Jun 2010 09:47:29 -0400
- Organization: EECS Dept., University of Michigan, Ann Arbor, MI, USA
Hi all,
I am using gcc 4.2.4 on Ubuntu 8.04. Also, I should have mentioned that I am
using Eigen 3 development branch.
-- Manoj
On Tuesday 01 June 2010 08:47:22 am Gael Guennebaud wrote:
> Hi,
>
> which compiler are you using ? because here it obviously fails to compile
> when checking the matrix sizes:
>
> Eigen::ProductBase<Derived, Lhs, Rhs>::ProductBase(const Lhs&, const Rhs&)
> [with Derived = Eigen::GeneralProduct<Eigen::Matrix<double, 33331, 1, 0,
> 33331, 1>, Eigen::Matrix<double, 33331, 33331, 0, 33331, 33331>, 2>, Lhs =
> Eigen::Matrix<double, 33331, 1, 0, 33331, 1>, Rhs = Eigen::Matrix<double,
> 33331, 33331, 0, 33331, 33331>]: Assertion `lhs.cols() == rhs.rows() &&
> "invalid matrix product" && "if you wanted a coeff-wise or a dot product
> use the respective explicit functions"' failed
>
> gael.
>
> On Sun, May 30, 2010 at 5:39 AM, Manoj Rajagopalan <rmanoj@xxxxxxxxx> wrote:
> > Hi eigen developers,
> >
> > The following test program and output performs w=v*M; where w and v are
> > Nx1
> > column vectors and M is NxN matrix. This statement, IMHO, should result
> > in a
> > compile-time error since the product isn't defined. Instead, the effect
> > seems
> > to be w = M.col(0) \kron v where \kron denotes tensor product: w is
> > resized
> > to be (N^2)x1 column vector.
> >
> > This brings me to another question: is there some way to disable
> > automatic right-side resizing during an assignment? This would help to
> > trap bugs such as the above. The automatic resizing is not always
> > desirable.
> >
> > Thanks,
> > Manoj
> >
> > ----------- Sample program and result --------------
> >
> >
> > #include <Eigen/Core>
> > #include <iostream>
> >
> > using namespace Eigen;
> > using namespace std;
> >
> > int main(void)
> > {
> > typedef Matrix<double,Dynamic,1> dvector;
> > typedef Matrix<double,Dynamic,Dynamic> dge_matrix;
> > int const N = 5;
> > dvector v(N);
> > for(int i=0;i<N;++i) v[i] = double(i+1);
> > dge_matrix M(N,N);
> > for(int j=0; j<N; ++j)
> > for(int i=0; i<N; ++i)
> > M(i,j) = double(10*(i+1)+(j+1));
> > dvector w(N);
> > w = v*M;
> > cout << "v' = " << v.transpose() << endl;
> > cout << "M =\n" << M << endl;
> > cout << "w' = " << w.transpose() << endl;
> > return 0;
> > }
> >
> >
> >
> > v' = 1 2 3 4 5
> > M =
> > 11 12 13 14 15
> > 21 22 23 24 25
> > 31 32 33 34 35
> > 41 42 43 44 45
> > 51 52 53 54 55
> > w' = 11 22 33 44 55 21 42 63 84 105 31 62 93 124 155 41 82
> > 123
> > 164 205 51 102 153 204 255