Registered Member
|
Hi,
First of all thank you for your amazing library. I'm trying to understand what's going on in the following code. - I'm applying a 3D transformation (R|C) on some 3d point data. - I'm using the operator() to apply the transformation either to a vector or a matrix. You will find below the code I used in order to reproduce the issue. Using the operator() on Vec3 data in a loop seems like 1x slower than calling the operator() on the matrix. I did not expect such a timing difference. $ ./main For loop (Pose with Vec3): 259ms (Pose with Mat3X): 18ms If I add the following function to the Pose class the code is running as fast, but I would like to have only one transform operator and does not need to implement two.
Can you help me to understand what I have made wrong?
Thank you for your help. |
Moderator
|
This is because for every calls to pose(p.col(i)) the compiler has to create a Mat3X object (which is allocated on the heap, so there is a costly malloc hidden there) and copy p.col(i) into this Mat3X object. Same for the returned value. The fix is as simple as witting a single generic template function, in c++14:
This will return an expression, so be careful with:
See: https://eigen.tuxfamily.org/dox/TopicPitfalls.html If you want to return the computed result (i.e., a Matrix) then write
|
Registered Member
|
Thank you very much.
Your detailed answer (modern cxx14 and the classic one) is appreciated. I will choose the template solution for the moment and will try to learn how to better use Eigen from the TopicPitfalls doc webpage! Before: $ ./main For loop (Pose with Vec3): 292ms (Pose with Mat3X): 18ms After $ ./main For loop (Pose with Vec3): 5ms // Clearly better! (Pose with Mat3X): 18ms I wonder if you have any tool to advise to make a runtime or static analysis that allow to find such not optimal return error type? |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]