[eigen] Assigning row vector expression to VectorXd

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


Hi,

When assigning a row vector into VectorXd (eg. a column vector), it does an implicit transpose in most cases (like in the line `VectorXd tmp = m.row(i) - m.row(j);` below).

I'm wondering why it doesn't behave the same way in line `VectorXd v3 = (m.row(i) - m.row(j)).cwiseQuotient(q);`. This gives the the wrong result in release mode (but calls`abort` in debug mode due to size mismatch).

Why does the assignment of `v3` behaves differently than the assignment of `tmp` in the example below? Is this documented behavior?

Cheers,
Jean-Claude


    {
        using namespace Eigen;
        MatrixXd m = MatrixXd::Random(10, 4);
        VectorXd q = VectorXd::Random(m.cols());
        Index i = 3;
        Index j = 8;

        VectorXd tmp = m.row(i) - m.row(j);
        VectorXd v1 = tmp.cwiseQuotient(q);
        VectorXd v2 = (m.row(i) - m.row(j)).transpose().cwiseQuotient(q);
        VectorXd v3 = (m.row(i) - m.row(j)).cwiseQuotient(q);

        std::cout << "v1 rows:" << v1.rows() << ", cols:" <<  v1.cols() << std::endl;
        std::cout << "v2 rows:" << v2.rows() << ", cols:" <<  v2.cols() << std::endl;
        std::cout << "v3 rows:" << v3.rows() << ", cols:" <<  v3.cols() << std::endl;

        std::cout << "v1 = " << v1.transpose() << std::endl;
        std::cout << "v2 = " << v2.transpose() << std::endl;
        std::cout << "v3 = " << v3.transpose() << std::endl;
    }

Output in release mode:

v1 rows:4, cols:1
v2 rows:4, cols:1
v3 rows:1, cols:1
v1 = -0.0375015    1.61562    -1.3097  -0.394064
v2 = -0.0375015    1.61562    -1.3097  -0.394064
v3 = -0.0375015



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