Re: [eigen] aliasing system

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


Hi,
   Won't matric.xpr().row(0) be a reference to a Matrix<double,2,2>::row?
So couldn't we still check if it's memory location is the same as any of the expressions on the
right side and if so, set an alias flag? Like:

void _ET_magic_generated_func(M& u, const M& v, const M& w)
{
    if(&u == &v || &u == &w)
{

--- Benoît Jacob <jacob@xxxxxxxxxxxxxxx> wrote:

> Yes, I thought of that. But in some cases it's more complicated than that.
> 
> For example:
> matrix.xpr().row(0) += 2 * matrix.row(1) + matrix.row(2)
> 
> Here, there is no problem. No need to use alias(). Yet your approach based on 
> the memory addresses of objects will detect that the same matrix is being 
> involved on both sides, so it'll decide (wrongly) that an alias is needed. 
> That would be very, very bad for performance because the whole matrix would 
> be copied, not only row(0) !
> 
> Since there is no fully working solution, I prefer keeping things simple and 
> clear, than trying to outsmart users with a solution that doesn't always 
> work.
> 
> Cheers,
> Benoit
> 
> On Thursday 06 September 2007 17:57:59 Andre Krause wrote:
> > Benoît Jacob wrote:
> > > On Thursday 06 September 2007 16:02:15 Andre Krause wrote:
> > >> so then if there is no way to avoid this problem - what about a sort of
> > >> #pragma warning or assertion that gets thrown / printed in DEBUG mode
> > >> only, if a user tries to do
> > >>
> > >> m = m*m;
> > >>
> > >> is there some template magic available to detect this?
> > >
> > > Very good idea. Yes, I think that can be done with partial template
> > > specialization. Will try.
> >
> > wouldnt it be easier to compare the memory adresses of the objects?
> >
> > suppose we have 2x2 matrices
> > u, v, w, and we do:
> >      u = v * w;
> >
> > it will hopefully unroll to some function call to
> >
> >
> > typedef Matrix<float, 2,2> M;
> >
> > void _ET_magic_generated_func(M& u, const M& v, const M& w)
> > {
> > 	#ifdef _DEBUG
> > 	if(&u == &v || &u == &w)
> > 		std::cerr << "some warning!!";
> > 	#endif
> >
> > 	u11 = v11*w11 + v12*w21;
> > 	u21 = v21*w11 + v22*w21;
> > 	u12 = v11*w12 + v12*w22;
> > 	u22 = v21*w12 + v22*w22;
> > }
> >
> >
> > now, if we do the bad thing of
> >
> > m = m*m;
> >
> > it will detect that the pointers are identical and thus matrix product
> > will get wrong result.
> 
> 
> 






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