Re: [eigen] Quaternion and expression template

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



Hi,

yes our Quaternion class does not feature _expression_ template, but since a Quaternion is only 4 coefficients, and that everything is inlined and unrolled, there is no need for _expression_ template. The compiler easily remove all these small temporaries. This is even more true when vectorization is enabled (Quaternion<float> <=> a single register). Also, note that both the conjugate of a quaternion, and the quaternion-quaternion product cannot be easily/efficiently implemented with _expression_ template because they would require some "if"...

So to conclude, don't worry, I'm pretty sure that "q = q1.conjugate() * q2" is already as fast as a specialized "quat_mult_conj(q, q1, q2)".

Also, only FYI, _expression_ template could be easily implemented for quaternion using the QuaternionWrapper class that I described in the other thread. For instance, QuaternionBase::operator+ would return an _expression_ of the addition of two vector _expression_ wrapped into a QuaternionWrapper:

template<Derived>
template<OtherDerived>
QuaternionWrapper<CwiseBinaryOp<ei_scalar_sum_op<Scalar>,Derived::CoeffType,OtherDerived::CoeffType>
QuaternionBase<Derived>::operator+(const QuaternionBase<OtherDerived>& other) const
{
  return QuaternionWrapper<...>(coeffs() + other.coeff());
}

but again, both conjugate() and the quaternion-quaternion product cannot be efficiently implemented using the ET mechanism.

gael.

On Thu, Oct 29, 2009 at 11:37 AM, Mathieu Gautier <mathieu.gautier@xxxxxx> wrote:
Hi,

I'm currently setting a prototype of our own math library with eigen2 and more precisely using the Geometry part of Eigen2. In my library, I have many rotation composition using quaternion, like :

q = q1.conjugate() * q2 which are implemented through function :

quat_mult_conj(q, q1, q2).

So we avoid any temporary elements due to inversion, multiplication and assignation. But I' rather use the first notation if possible, it could also remove many of our operations (mult_conj, conj_mult, etc..)

Actually in Eigen2, _expression_ templates are used with MatrixBase through the CWise* or productBase classes. Since Quaternion doesn't inherited from MatrixBase, it doesn't seem possible to reuse the CWise* mecanism. Do I have to provide a new mecanism based to the CWise* or productBase ones to use _expression_ template with the Quaternion classes?

If so, these classes will inherit from the new QuaternionBase, are there specifics traps to avoid or part of existing code that could be reused ?

--
Mathieu Gautier


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