Re: [eigen] aliasing system

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


Hi,
  Shoot, didn't get to complete the email. Well nevermind, I don't know enough about the code to
say anything about how to modify the expression templates to successfully test if the object on
the left side is the same as one (or more) of the objects on the right side. It seems like it
should be possible to do though by adding the overhead of an additional for loop to check all of
the rhs arguments. It might be worth running a performance test to see the performance hit.

Cheers
Ben



--- 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/