Re: [eigen] Quaternion and expression template

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


2009/10/29 Gael Guennebaud
> 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"...

Time for some bikeshedding:
Actually this "if" doesn't matter because the loop will always be
unrolled (we'd put meta unrollers there too) so the if would evaluate
at compile time. It's like if "if" in the Minor expression that i use
to compute 3x3 determinants.

Benoit



>
> 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/