artivis / manif

A small C++11 header-only library for Lie theory.
https://artivis.github.io/manif
MIT License
1.52k stars 246 forks source link

Aliasing in manif. #144

Open markusgft opened 4 years ago

markusgft commented 4 years ago

Dear all, I am wondering whether manif should adopt the (anti) aliasing helper functions native to Eigen. In particular, I believe that Eigens .eval() and .noalias() could be relevant and attractive for manif. For instance, in my applications, this helps to greatly reduce the number of temporary expressions and therefore increases speed!

artivis commented 4 years ago

Hi @markusgft, What do you mean by:

in my applications, this helps to greatly reduce the number of temporary expressions and therefore increases speed!

I assume you mean using those on plain Eigen types since manif does not provide these functionalities.
Altho interesting, I'm afraid this won't happen anytime soon. Indeed, Eigen has many tricks up its sleeves and one of them is the use of 'expressions template'. You may have previously noticed that, e.g., calling the function my_eigen_matrix.inverse() does not actually return a type Eigen::Matrix but rather an Eigen::Inverse< XprType > expression. It is a temporary object that holds the computation of the inverse function and only performs it when Eigen::Inverse< XprType >::eval is called (either by the user or Eigen e.g. on assignment). The .noalias is a different story but relies on the same mechanism.

No need to say that manif does not employ expression template. And the reason is simply that it is a fairly complicated technique that I don't fully master. I have a local branch on which I started this effort, but it is partial and does not actually addresses the points you are raising. Furthermore it requires a deep redesign of the library.

Also, note that we are using noalias() internally.

To summarize, I'd love to get there, but currently I can't.

markusgft commented 4 years ago

Thanks for your comments and insights! I believe that this would be automatically resolved in case that #142 gets as far as to introducing direct inheritance of the tangent-vector types from the Eigen::Matrix class!

artivis commented 4 years ago

I believe that this would be automatically resolved in case that #142 gets as far as to introducing direct inheritance of the tangent-vector types from the Eigen::Matrix class!

Well, only for tangents and only partially ^^.

markusgft commented 4 years ago

Sure, only partially! Of course I base my judgement on the limited scope of my application - but within that application, the solution proposed in the other thread would resolve a great many of my issues. Thanks again, and keep up the great work!

joansola commented 4 years ago

Well, only for tangents and only partially ^^.

Since most of the calculus performed by solvers and optimizers is done in the tangent space (that is, all state errors, perturbations, increments, optimal steps, residuals, Jacobians, and covariances are in the tangent space), this "only" means that most of the problems are solved by letting the tangent inherit from Matrix<T,size,1> I'd say.

To insist on this argument, the tangent space is THE vector space, and therefore the place where vectorial calculus is done, hence the place where Eigen shines.