Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ boost ublas + units dimension constraints

I am seeking advice on design/general idea on how to force matrix dimension constraints on ublas matrix/vector possibly using boost units.

For example, let matrix A have dimensions of time x force (for example)

// does not have dimensions, time x force and force x time are not distinguished.
matrix<double> A;

//something like?
dimension<time, force, matrix<double> > A;
dimension<force, time, matrix<double> > B = trans(A);

// or maybe custom layouts, although ensuring dimension becomes harder between matrixes?
matrix<double, dimension<time, force> > A;

have you done something like this or do you have some good idea about how to organize such constraints? I am looking more for syntax/semantics suggestion rather than implementation.

I have gone through ublas archives, there are some discussion, but nothing concrete.

Thank you

like image 735
Anycorn Avatar asked Dec 07 '25 10:12

Anycorn


1 Answers

Check out this nice Boost tutorial which introduces dimensional analysis capability using template-metaprogramming:

http://www.boost.org/doc/libs/1_35_0/libs/mpl/doc/tutorial/representing-dimensions.html

This will require you to create a whole set of template specializations for every dimension you want to use in your app, but the result is worth it -- it won't allow you to make mistakes or add ambiguity in dimensions.

like image 193
Andrei Sosnin Avatar answered Dec 09 '25 22:12

Andrei Sosnin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!