-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start using the Eigen objects in the public API #707
Comments
Since I'm not able to wait I tried with the All the tests pass without any problems. Thanks to the code I developed the following code compiles iDynTree::VectorFixSize<4> v1, v2;
v1 << 1, 2, 3, 4;
v2 << 5, 6, 7, 8;
iDynTree::VectorFixSize<4> v3 = 2 * v1 + v2; |
That is great @GiulioRomualdi ! Just to be clear, the C++17 requirement is sufficient to avoid all the Just to be aligned, the main reasons (in decreasing order of importance) I introduced the rule "no non-STL includes in public headers" back in 2015 were (an extensive design rationale can be found in #29):
Fast forward to 2020, the situation clearly improved:
I still some general doubts of the fact that Eigen ABI can be drastically changed from one compilation unit to another by simple preprocessor definitions (see flexible-collision-library/fcl#96 (comment)) but the benefits are clearly more relevant then the downsides. |
Actually I tried with |
Thanks @GiulioRomualdi for starting the discussion about this topic and @traversaro for providing the overview of the history, very useful. I agree that directly using Eigen in our public APIs simplifies quite a lot many operations, especially when the data structures come from other libraries (thanks to Eigen maps). My main concern is @traversaro's point 2. Particularly for what concerns Python, it would be great having also an eigen - numpy automatic conversion (another interesting project is stack-of-tasks/eigenpy, even though they use Boost Python). There are few differences in how eigen and numpy handle the vectors and many hidden caveats do exist. We should investigate how to do this conversion properly. |
Shall we schedule a meeting on this? |
Hello guys. I am not used to comment on iDynTree PRs, but this is a big change and, unfortunately, I feel obliged to leave a comment here. I will not comment on "breaking change / break API/ABI" as sometimes this is needed and if handled correctly you can mitigate the pain for lots of users. Maybe, if you can describe what issues do you currently have with iDynTree types, we can find a better way to handle this? |
Hi @francesco-romano, nice to hear from you! For instance, I would like to call the very same function with different types of objects (e.g. iDynTree, Eigen, CasADi...), since in iDynTree the linear algebra is not defined (you should use If you have time, we can discuss into more detail by using one of the many web conferencing services. I think that also @traversaro may be interested in this. |
Happy to have a chat offline about this. In general I think the real question is: why do you want to call the same function with different objects? If you are not in control of all the classes, I see this to be fragile. You can add |
As the need to have iDynTree objects that behave like Eigen object is not necessary anymore due to ami-iit/bipedal-locomotion-framework#63, I think we can close this issue and PR #709, what do you think @GiulioRomualdi ? |
Yes we can close it. |
I am pretty sure that all the iDynTree users know
Eigen
library. However, to be all aligned,Eigen
is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.iDynTree
widely usesEigen
to compute some operations. Thanks to theiDynTree::toEigen()
function many iDynTree objects can be mapped in anEigen::map
and they can be almost treated asEigen
objects #510.Using
Eigen
objects in the public API has been always discouraged because of thealignment
problem. The problem is well known in theEigen
community, indeed it is documented in the documentation. In a nutshell the following codecauses a segmentation fault when the Advanced Vector Extension (AVX) instructions set is used to compile the library/application. Indeed running the code with the AVX option (
-mavx
) leads to the following assertOn the other hand, having objects that inherit directly from
Eigen
could be really useful (for instance we do not need to calliDynTree::toEigen()
every time we need to compute an operation). Furthermore, we may avoid converting theiDynTree
objects toEigen
objects when we use other libraries (e.g.osqp-eigen
). Last but not least it may simplify the implementation of Templates function/classes where we require some basic algebraic operations (Please check ami-iit/bipedal-locomotion-framework#56).Checking on
Eigen
website, I realized that the alignment "limitation" is completely solved if the library is compiled in [c++17] mode only with a sufficiently recent compiler (e.g., gcc>=7, clang>=5, MSVC>=19.12).Ubuntu 18.04LTS
shipsgcc 7.5.0
, whileMSVC 19.12
is supported from VS2017, version 15.5.I also wrote a simple
snippet
for testing the feature. (Please find the code here). Calling the following command the code will run without any error.while
will generate a not working application.
What I am proposing is to start refactoring some core objects in
iDynTree
and inherit directly fromEigen
. I know that this is a huge change in iDynTree (e.g. we have to ask for C++) and it may break some already existing code, but I believe that handling correctly the transition phase (that may last several months), we can do it.@traversaro @robotology/iit-dynamic-interaction-control
The text was updated successfully, but these errors were encountered: