using uBLAS with quantity<> (C++TMP)
Hi, the book "C++ Template Metaprogramming" by Abrahams and Gurtovoy describes a dimensional analyis framework that enables compile-time checking of physical units. For example dividing a length quantity by a time quantity results in a speed quantity. Now it's tempting to use boost uBLAS with these quantities: A position in space can be expressed as a vector of length quantities etc. But there's one problem: "// uBLAS assumes a common return type for all binary arithmetic operators" (traits.hpp, line 42, boost release 1.33) The promote_traits class relies on this when computing the following: static const std::size_t size = sizeof ( type_deduction_detail::test< typename base_type::x_type , typename base_type::y_type >(x + y) // Use x+y to stand of all the arithmetic actions ); This fails for most quantity operations since dividing a length by a length results in a different type than adding them. As a result Visual C++ 7.1 complains about not being able to deduce template arguments. Is there a way to fix this? I'm not that familiar with the internals of uBLAS, I don't even know the purpose of promote_traits. Malte
"Malte Clasen" wrote
Now it's tempting to use boost uBLAS with these quantities: A position in space can be expressed as a vector of length quantities etc. But there's one problem:
"// uBLAS assumes a common return type for all binary arithmetic operators" (traits.hpp, line 42, boost release 1.33)
The promote_traits class relies on this when computing the following:
(FWIW Boost.Typeof could be tried here instead of promote_traits)
static const std::size_t size = sizeof ( type_deduction_detail::test< typename base_type::x_type , typename base_type::y_type >(x + y) // Use x+y to stand of all the arithmetic actions );
I died some experiments on matrices with my quantities library pqs. http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html I dont believe a simple use in UBLAS is possible because the members of a quantity<> matrix arent all the same type. Here for example are a couple of types representing homogeneous vectors and transformation matrices for 2D transforms. PQ == the physical-quantity parameter type ( eg length::m) K/PQ == the 'reciprocal' of the type ( eg reciprocal_length::div_m ( } N == numeric type ( eg double) rc_matrix<PQ>( // 2D transformation matrix laid out in row/column format //using a tuple of tuples N, N, K/PQ, N, N, K/PQ, PQ, PQ, N ); row_vector<PQ>( // 2D vertex in homogeneous coordinates implicit //conversion to/from x,y vertex<PQ>. N, N, K/PQ ); However I an pretty sure that UBLAS isnt laid out this way! regards Andy Little
participants (2)
-
Andy Little
-
Malte Clasen