Re: [eigen] still the solve() API debate

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


On Fri, Sep 11, 2009 at 3:22 PM, Hauke Heibel
<hauke.heibel@xxxxxxxxxxxxxx> wrote:
> On Fri, Sep 11, 2009 at 3:13 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
>> Same thing when we do A.solveInPlace(b.start(n)), start() returns a
>> temporary, same problem, whence the idea of inplace() or whatever we
>> call it.
>
> Ok, I just caught up with re-reading... that's indeed ugly. But as you
> guys already observed, in new compiler versions we already have rvalue
> references.

> Benoit, what about your idea of passing Matrices by
> reference and MatrixBase by value? You suggested to do that in the
> "MatrixBase::swap - why const" thread? This approach would allow an
> easy transition towards rvalues references in the future.

I've thought about it and I really don't see how to it safely and in a
generic way, and I really doubt that's possible.



I also have to say that my Reference<> solution becomes very tricky as
soon as you want to restrict your function to a MatrixBase<>, e.g.:

template<Derived> Derived& solve(Reference<Derived> b);

will match any type which can be explicitly converted to a Reference,
while we usually want to do:

template<Derived> Derived& solve(Reference<MatrixBase<Derived> > b);

but if you declare your function like this,

MatrixXf m;
A.solve(m.ref());

won't compile because the type of m.ref() is Reference<Matrix<...> >.
The unique way to make it working is to make Reference<Matrix<...> >
inheriting Reference<MatrixBase<Matrix<...> > >. (this is because the
solve function is template, and casting by inheritance is only kind of
casting which is allowed to select the function to  instanciate)

That complicates the practical implementation of Reference<>. I'll
look into it more precisely.

gael.

> Hauke
>
>
>



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