Re: [eigen] Returning an expression unifying two types of matrices

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


Gael Guennebaud wrote:
> I see two options:
> 
> 1 - you replace getG by getG_diag and getG_full, and anytime you have
> to use G, you do something like:
> 
> if(obj.gIsDiag())
>   bla * obj.getG_diag() * blabla;
> else
>   bla * obj.getG_full() * blabla;

Since I have these expression in several places I'd like to keep
changing these as few as possible. But this is straightforward and
simple.

> 2 - you add a template <typename Rhs> multByG(const Rhs& rhs) const {
> return ...; } function that will return a temporary. Since G is always
> squared, the returned type (a Matrix<> object, not an expression) will
> always be the same. You might need two versions to multiply on the
> right or on the left. You might also write a very small wrapper
> storing a ref to obj with custom operators* that will do the dynamic
> branching:
> 
>  bla * obj.getG() * blabla;
> 
> obj.getG() will return a wrapper object, bla * obj.getG() will be
> evaluated by your custom operator* that will do the branching and
> return a Matrix<> object.

The only disadvantage here is the creation of the temporary. But I'll
try this and check its effects on performance.
I could add a member to save the result and return a const reference to
it. But that it wouldn't be thread-safe anymore.

I already tested the first option. Now I will investigate the second
option.

Many thanks.

Jens



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