Re: [eigen] aliasing system

[ Thread Index | Date Index | More Archives ]

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!!";

	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+