Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-10-11 05:28:51


"Matt Calabrese" wrote

> Expression reorginization can optimize an overall expression quite a bit,
> which is why I decided to make it a part of the library. As a simple
> example, take the following expression after analysis:
>
> meters1 + feet1 + meters2 + feet2
>
> Without expression rearrangement, a conversion could potentially take place
> at every operations. For instance, without rearrangement, the following
> logic could occur (obviously it would all be implicit, I am using just made
> up functions for clarity here):
>
> convert_to_feet( convert_to_meters( ( convert_to_feet( meters1 ) + feet1 ) )
> + meters2 ) + feet2
>
> However, with expression rearrangement, we can group like terms:
>
> feet1 + feet2 + convert_to_feet( meters1 + meters2 )

The example works for addition but what about multiplication and division? Is
the example realistic?
FWIW pqs assumes/("prods") that all calculations would actually be done in SI
units. (The whole idea behind SI is to use the so-called "coherent" units and
phase out the others). In this scenario the conversion to-from "incoherent"
units would only occur for user input/output.

OTOH
meters result = millimeters1 + meters2;

In the above pqs would convert the intermediate result to millimeters under the
rule that millimeters is the most fine grained unit. I guess that improvements
could be made with expression templates. OTOH will the rules regarding the
result of an operation be simple to understand? Maybe that doesnt matter. BTW
Are there not subtleties with temporaries using ET that users need to know
about?

[cut]

> Implementation-wise, I am using MPL maps to represent classifications and
> unit types, unlike Andy Little's if I remember correctly, providing more
> compile-time efficient type comparisons.

I used a home brewed version. It would be interesting to see if mpl::map is
faster, but I think it will be slower because mine wasnt actually very generic
;-) . However the use of compile time double will have a major detrimental
impact on compile times unfortunately. I dont know what one can do about that.

> I also provide a variety of simple
> ways of creating new unit types and classification types using compile-time
> metafunctions and variadic template argument lists.

One problem in pqs was explaining how to add new types and units. If this can be
simplified that would be great.

regards
Andy Little


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk