This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using Eigen with static dimensional analysis libraries

Tags: None
(comma "," separated)
User avatar
enisbayramoglu
Registered Member
Posts
4
Karma
0
Hi, is it possible to use Eigen with static dimensional analysis libraries such as boost::units? As you've probably already imagined at this point, the problem is that the following should hold for such a use case:
Code: Select all
Matrix<energy,3,3> m = Matrix<distance,3,3>() *Matrix<force,3,3>();

Obviously, assuming that distance*force returns energy in the library.

Is it possible to modify Eigen to provide this functionality? To my understanding, operations between matrices of different scalar types are deliberately avoided, so, are there any back doors? If not, is this a planned feature?

I think this feature will be requested more and more often as the user defined literals of C++11 gets more support from compilers. I believe, people will suddenly be crazy about dimensional analysis. Nowadays, when I define a function like
Code: Select all
double datan2_dt(double y, double dy_dt, double x, double dx_dt)

I feel as insecure as using void pointers!!!

Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
With the devel branch, you might try to define:
Code: Select all
namespace Eigen { namespace internal {
  template<> struct scalar_product_traits<distance,force>
  {
  enum { Defined = 1 };
  typedef energy ReturnType;
};
}}

of course this is limited to products, scalar*matrix is not supported (you can workaround using Constant and a cwiseProduct), and this rely on internal API that is subject to change and improve to finally propose a stable public API for that use cases.
User avatar
enisbayramoglu
Registered Member
Posts
4
Karma
0
Thanks a lot, I'm glad to learn that this is a planned feature, it makes Eigen more valuable. Thanks for Eigen overall!!!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]