|Re: [eigen] Quaternion and expression template|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Quaternion and expression template
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Thu, 29 Oct 2009 12:42:38 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=Xp3eNY3MMVs4cSVdKPv++A2i2iNANN8n0M6mxpaO1ao=; b=d+rnobN/qf62YQ4SdqczUZ1E7UPVk9k/Ufykjs52OMdUM2vmZjM5urOuwgv59j56QB EqxW7sRjEa7Z2oPoCzPCqll0kcPyn9YCRd3HbFM8y5eBJYc44N9n1mrKAvCAZg7eoUYW r6L9XzoWVGPXFTY1t6u+Sqf1Ehdb+vCk51kN4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=bzBbRFX/EpgnlKh1Acr36bl1LnpgBZM3335zp3/FhtoVcCyI1UQDQh4StBsXdNZk6S tySPMcX1XSshKihagaHSeyEguOv6ZhXEnk9Jnpy8t8ebzS3/VabWHSxs/bbCwjEWXt7d ABvtaSv49LxfWvfY7OfAhkZ3n2KewPxkS/Bfg=
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:
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.
On Thu, Oct 29, 2009 at 11:37 AM, Mathieu Gautier <mathieu.gautier@xxxxxx>
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 ?