Re: [eigen] Bug in traspose

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


OK, first off I think you're right on this: we need to replace .newline() by 
operator, because of the relative priority of these operators!

http://www.cplusplus.com/doc/tutorial/operators.html

operator, has the lowest priority. Whatever set of operators we choose must 
have equal priorities and left-to-right associativity. The one exception is 
the first operator which may have higher priority.

There is a problem with this:

> Matrix2d m;
> m <<= (1, 2),
>       (3, 4);

Here the first operator, refers to the object 1 and the compiler will treat it 
as an "int". Since we can't overload operator, on a POD type, I see no way to 
make this work. Same problem with every solution you're proposing with a 
parenthesis ( before the 1.

This is why I proposed this list() method. By having MatrixBase::list() return 
a CommaInitializer, we allow the compiler to understand that the subsequent 
operator, is CommaInitializer::operator, .

But you are right that we may replace list() by an operator (this operator 
would return an object of type CommaInitializer). I would suggest << instead 
of <<=, since 1) it has left-to-right associativity and 2) <<= would suggest 
compound-assignment.

> or maybe we don't need end()

You are right! The purpose of end() was to check that the initialization list 
had the right size, but this is better done anyway in the destructor of 
CommaInitializer.

Regarding newline, I see not other solution but doing << Eigen::NewLine. 
Indeed, << is the only operator with that priority (except >> which would 
really be nonsensical).

So the updated solution would be:

Matrix4d m;    // or, for dynamic size, MatrixXd m(4,4);
m << 1, 2, Eigen::NewLine,
     3, 4;

Cheers,

Benoit

Attachment: signature.asc
Description: This is a digitally signed message part.



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