[eigen] Returning an expression unifying two types of matrices

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


I'm facing a problem and don't know how to approach it.
In my code I have many expressions of the form y.transpose() * getG() *
y, where y is a column vector of length n and getG() returns a reference
to a nxn matrix.
Sometimes I know that G is diagonal (at run-time) and I'd like to use
this information when evaluating the expressions (storing a diagonal is
also much cheaper).
I need to store G somewhere to return it. But G is either a full matrix
or a diagonal matrix. So what do I store? Storing both and initializing
only one is an option. Are there better options? I can decide at
run-time inside getG() what to return but what's the type returned by

I've read
But it won't help.

Any idea is very appreciated. Thanks.


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