Registered Member
|
Dear all,
I am currently in the process of extending Eigen for my specific needs (using the plugins mechanism and some classes). I must admit I am lost between the base classes, the main classes, the derived idiom... and when to use these depending on the cases. I currently copy function signatures from Eigen and adapt them to my needs and when it does not compile I try something else. I am definitely not keen on this way of going forward as I do not perfectly understand what is going on behind the hood or even may it be good practices to apply. For QuaternionBase return types of methods for example, when looking at the Eigen implementation, some functions return a type "Quaternion<Scalar>", others a type "Derived&" and yet others "QuaternionBase&"... I am not sure why this is so and infer what type to use in which case from these observations... Another example involving QuaternionBase methods arguments: it seems that for any argument using an Eigen type another template argument needs to be defined for the method. i.e.
I am not sure why... Currently I have the feeling I need to understand deeply how Eigen is coded in order to be able to extend it. Of course I have read the documentation, though things are not clear yet to me. Any tip on this one? Kind regards, Antoine. |
Moderator
|
This way to declare myFunc permits to accept any but only objects for which QuaternionBase (or MatrixBase) is a base class. You could also declare it as:
template<typename QuatType, ...> ... myFunc(const QuatType &q, ...) but then myFunc can be called on anything and the compilation errors will be less obvious if the actual QuatType is not compatible with QuaternionBase. The other questions are a bit too vague, please be more specific on your concerns. |
Registered Member
|
Thanks Gael, I will separate things in several questions and sharpen my descriptions.
I would like to extend classes Matrix and Quaternion so they compute some additional functions with Matrix<Scalar, 3, 1> as 'this', arguments, and return values. With The Quaternions extension I can had the function below to the file defined in EIGEN_QUATERNIONBASE_PLUGIN:
But when I want to extend the Matrix class (using EIGEN_MATRIXBASE_PLUGIN), also to work on Matrix<Scalar, 3, 1>, I need to do
1) Is there a way to enforce at compile-time that myVec has size (3, 1), i.e. specifying a Matrix<Scalar, 3, 1> argument type for myMatFunc ? 2) Is there a way to enforce at compile-time that 'this' has size (3, 1)? Do we need to test it at run-time? It is the same problem for function 'cross' which can only work on 3D vectors, so how is it done in there? I had a look to the code but I must admit I got lost... Kind regards, Antoine. |
Moderator
|
The Eigen way is to add the following in the body of your function:
this will trigger a readable compilation error. An alternative is to use the enable_if mechanism, but that solution pollutes the prototype, e.g.:
|
Registered Member
|
Wow, this is really unusual to me... But that definitely does the trick, thanks!
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]