views:

45

answers:

1

hello.

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

+1  A: 

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.

deemoowoor