2009/3/31 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> 2009/3/31 Patrick Mihelich <patrick.mihelich@xxxxxxxxx>:
>> OK, right. But you do not always have to use the lowest-common-denominator
>> behavior (return by value). MatrixBase knows the Derived type and can return
>> by const-reference for Derived types with dense storage (Matrix, Map).
>
> ah right, good idea. I'll look into that.
>
>> OK but this is more verbose, and it's rather surprising that it doesn't do
>> the same thing as m(i,j) or even m.coeff(i,j). I do not think Matrix should
>> override the coeff() methods from MatrixBase with different signatures; more
>> generally I'd suggest that for any MatrixBase method foo, m.foo() and
>> m.derived().foo() should always behave identically.
>
> I understand. Good idea. I do that and I update you....
It's done now (in trunk).
I have actually taken a shortcut compared to the traditional c++ way
of doing this as you exposed.
Namely, Eigen expressions already had a DirectAccess flag which means
that coeffRef is available and that the data is stored
piecewise-contiguously in memory (piecewise meaning that a "stride" is
allowed between consecutive rows/cols).
So what I did was define a CoeffReturnType in MatrixBase, that is
either "const Scalar&" or "Scalar" depending on whether the xpr has
the DirectAccess flag, that's all.
That has the advantage of being a small local modification and not
requiring any more boilerplate code in all xpr classes.
>
>> BTW, there is a mistake in MapBase: const Scalar coeff(int index) const
>> should return const Scalar&.
>
> woops, good catch !
part of the same commit.
Cheers,
Benoit