Re: [eigen] What is the 'correct' way to pass matrix results?

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


On Wed, May 18, 2011 at 4:37 PM, Christoph Hertzberg
<chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> On 18.05.2011 13:42, Hauke Heibel wrote:
>>
>> Hi Christoph,
>>
>> There is no single correct solution. It depends on your requirements
>> and your working environment.
>>
>> On Wed, May 18, 2011 at 12:43 PM, Christoph Hertzberg
>> <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>  wrote:
>>>
>>> 1) Implement an expression template -- this might be ok if your code is
>>>   in pre-final stage ... or if you return using C++0x auto return type;
>>>   otherwise, I think it is a bit too complicated.
>>
>> I agree, that writing an expression is quite complicated but I
>> disagree that using an expression is complicated. Its usage gets only
>> complicated, when you try to store the expression into a temporary
>> which is not a PlainObject, i.e. when you exactly need to know the
>> type of an expression. In most cases you probably do not need this
>> knowledge.
>
> Well, I need to know the type if I want to return it -- unless I use C++0x
> in which case I can return auto (and can also use auto for temporary
> expressions).

Ah, I see. But even here you need to know what you want to return.

Consider this example:

template <typename Derived>
<whatgoeshere??> foo(const MatrixBase<Derived>& m)
{
  return m*m;
}

in C++0x that would be

template <typename Derived>
auto foo(const MatrixBase<Derived>& m) -> decltype(m*m)
{
  return m*m;
}

where you provide type information via decltype. What I mean is that
as far as I can see, you are lost when the function becomes more
complex and have to fall back to hand written expressions.

- Hauke



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