Re: [eigen] Permuted Matrix

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


2010/7/20 Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>:
> Christoph Hertzberg wrote:
>> template<class Derived>
>> void access_test(const MatrixBase<Derived>& m1) {
>>       MatrixBase<Derived> m2 = m1;
>>       m2 += m1;
>> }
>>
>> int main(void) {
>>       Matrix3d A, B;
>>       access_test(A*B);
>> }
>
> with Eigen2 this actually compiles, but (as it seems) gets stuck in some
> infinite loop ...

Just for the record --- these infinite loops are a known problem with
Eigen2 that's been fixed in Eigen3.

Explanations: rvalue-only expressions don't implement write methods
such as coeffRef, but in Eigen2, MatrixBase still defines them as
calling the method in the Derived class. Since the method isn't
actually reimplemented in the Derived class, it actually calls again
the method from MatrixBase, leading to infinite recursion.

This was fixed in Eigen3 by the introduction of the DenseCoeffsBase
class, which is specialized separately for lvalue and rvalue
expressions. So this kind of error is caught at compile time.

Also for the record --- your code above,

   MatrixBase<Derived> m2 = m1;

is not going to work anyway since m2 is declared as MatrixBase i.e. as
an empty object. We have added some safeguards against constructing
bad MatrixBase objects but apparently we need some more. Maybe we
could actually make the copy constructor private?

Benoit


>
>
> --
> ----------------------------------------------
> Dipl.-Inf. Christoph Hertzberg
> Cartesium 0.051
> Universität Bremen
> Enrique-Schmidt-Straße 5
> 28359 Bremen
>
> Tel: (+49) 421-218-64252
> ----------------------------------------------
>
>
>



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