Re: [eigen] aliasing system

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


The point of my example with rows was that if we want to determine if 
rows/columns/blocks/minors overlap in memory, we're trying to do something 
that can't be done at compile-time (because the arguments that you pass to 
these functions is not necessary a compile-time constant). Hence that will 
have a cost, and if you want to handle all cases it'll be a big cost (you'll 
have to check for each entry in the matrix if overlapping occurs at that 
entry).

Another issue is that the memory location of matrices themselves is not 
necessary known at compile-time. What if we are traversing an array of 
matrices, for instance. The address of the matrix array_of_matrices[i] 
depends on i...

Benoit

P.S. I'll contribute a paragraph to this week's KDE commit-digest on Eigen2.

On Thursday 06 September 2007 21:48:00 Schleimer, Ben wrote:
> 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.


Attachment: signature.asc
Description: This is a digitally signed message part.



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