[eigen] Lazy evaluation and adjoint(): Bug?

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


Dear All,

while  desperately investigating my current "Learning Eigen" project, I came across the following problem.

I'm using Matrices for self defined complex types, where conj() is defined as

template<class Q>
typename boost::enable_if< boost::is_complex<Q>, MyType<Q> >::type conj( const MyType< Q >& a)
{
    static int counter(0);
    std::cout << "#MyType conjugate called " << ++counter << " : " << a << std::endl;
    return MyType<Q>( conj( a.z1() ), conj( a.z2() ));
};

Now, somewhere deep in my code I have the following rotation:

std::cout << "#------Lazy----------\n";
TpMatrix TT0  =  U.adjoint() * T * U;

std::cout << "#------helper-----------\n";
TpMatrix Uadj = U.adjoint()  ;

std::cout << "#-----------------\n";
TpMatrix TT   = Uadj * T * U;
	
std::cout << "#-------Diff------\n\n" << TT -TT0 << std::endl;;


where the involved matrices have dimension 10x10.

Now, in the evaluation of TT0 MyType::conj gets called precisely one time,
while in the evaluation of Uadj it gets called 100 == 10*10 times, which I would naively expect.

Am I'm missing something?

I also just tested that
TpMatrix TT1  =  (U.adjoint() * T).eval()  * U;

calls MyType::conj only once.

Is this intended behaviour? Am I'm missing something?
Since TT is different from TT0 I assume that Eigen is too lazy here.
Sadly, I still don't know enough of Eigens internals to make sense of the code paths shown by ddd/gdb.

Any help is highly appreciated,
best regards,
Peter





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