Re: [eigen] vector-cwise operator +=/-=

[ Thread Index | Date Index | More Archives ]

indeed we already allow col_vector = row_vector, but I'm not sure we should allow coeff-wise binary operators to work between column and row vectors... is it always safe ? is it really more convenient ?

About the last question, e.g., your example is better written like this:

v3 += m.transpose() * v2;


On Wed, Dec 16, 2009 at 9:39 AM, Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx> wrote:
Hi guys,

I think it would be cool, if the following code worked:

#include <Eigen/Core>
#include <Eigen/Array>

using namespace Eigen;

void main ()
  Matrix<double,3,1> v3;
  Matrix<double,2,1> v2;
  Matrix<double,2,3> m;

  m << 1,2,3,4,5,6;
  v2 << 7,8;
  v3 << 4,5,6;

  v3 += v2.transpose() * m; // expected 43, 59, 57
  std::cout << v3 << std::endl;

The simple assignment

v3 = v2.transpose() * m;

is already working and if I am not totally wrong, the only thing which keeps this current example from working is the ctor of CwiseBinaryOp. In particular the lines

ei_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());

(these are redundant, right?). I think, if we simply make this check less restrictive in the sense that we allow the assignment of vectors and their transposed counterparts (having the same size...) we would be done. Any objections or comments against such a change?

- Hauke

Mail converted by MHonArc 2.6.19+