Re: [eigen] Possible bug in vector-matrix multiplication?
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] Possible bug in vector-matrix multiplication?
• From: Manoj Rajagopalan <rmanoj@xxxxxxxxx>
• Date: Tue, 1 Jun 2010 11:36:54 -0400
• Organization: EECS Dept., University of Michigan, Ann Arbor, MI, USA

```hi Gael,

yes, that was it. I had the -DNDEBUG turned on by default, silly me! Also, I
see why it should be a runtime assertion as opposed to a compile-time one:
the <Dynamic,Dynamic> matrix could have just 1 row in which case the
operation would become an outer product but this can only be checked at
runtime.

Thanks for your help. And sorry for the false alarm.

-- Manoj

On Tuesday 01 June 2010 10:07:43 am Gael Guennebaud wrote:
> sorry, it is not a compilation error but a runtime assertion, so I guess
> you are compiling with -DNDEBUG which has for effect to disable assertion
> checking.
>
> gael
>
> On Tue, Jun 1, 2010 at 3:47 PM, Manoj Rajagopalan <rmanoj@xxxxxxxxx> wrote:
> > 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

```

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