Re: [eigen] CRTP in eigen: using .derived()

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


Hi Dan,

Yes, the derived() in mat.derived().determinant() should not be needed in code like this.

There *might* be places in Eigen code itself where it's needed (inside the definition of a class inheriting such a method from its curious base).

Also, the only thing that can happen, is that something fails to build if a method is not defined. But if it does build, then for sure it makes no difference. So just check if it compiles.

Cheers,
Benoit

2016-04-20 5:31 GMT-04:00 Dan Čermák <dan.cermak@xxxxxxxxxxxxxxxxxxx>:
Hi folks,

I have a question concerning the CRTP base classes in eigen, for instance
Eigen::MatrixBase. In most examples of generic functions in the documentation,
I see something like this:

template <class Derived>
void do_smth(const Eigen::MatrixBase<Derived>& mat) {
        const double det = mat.derived().determinant();
}

My question is about the mat.derived(), is that necessary?

If I understood crtp correctly, than mat.determinant() should do exactly the
same (provided the base class implements this function).

Are there advantages of using .derived() when constructing expressions?
I could imagine that it makes a difference whether one does e.g.:
        return mat.block(...);
or:
        return mat.derived().block(...);
as the types will be different, but I have no idea what the actual impact is.


Thanks in advance,

Dan





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