Boost logo

Boost :

From: Jason Hise (chaos_at_[hidden])
Date: 2006-03-25 15:36:34


Andy Little wrote:

>I've had a quick look. It looks like a very classical matrix library. There are
>some issues
>
>#include <entropy/linear_algebra.hpp>
>
>using entropy::vector;
>int main()
>{
> vector<double,2> v1(1.,2.,3.);
>}
>
>This causes the program to crash when run, so I presume some compile time
>asserts would be mandatorry.
>
>
I am aware of this problem. If submitted to boost I would probably use
the boost preprocessor and mpl's enable_if to make only the constructor
whose number of arguments matched be available in the class. The reason
that such measures are not in place now is that I wanted to keep library
dependencies low and the code tidy.

>Overall though it looks very clean. In fact its almost the exact opposite of my
>own geometry library in the vault.
>
>This brings me to a problem I have been wrestling with:
>
>As author of pqs physical quantities library I am pretty much required to
>implement a geometry library so that it can use physical quantities as
>value_types, but I dont feel it reasonable that I should impose that on
>everybody.
>
>The fact that my library allows use of physical quantities as
>value_types has repurcussions in terms of the interface (no operator[]) and the implementation (Look at the comparative zip file sizes).
>
>
What exactly does using physical quantities entail? Is the problem that
performing matrix multiplication results in the types of the physical
quantities becoming mangled, and if so couldn't you just make matrices
use untyped units while allowing the vectors to keep their types? For
instance (note that I am using row vectors and assuming the meta
function remove_units has been implemented):

template < typename VecType, std::size_t Size >
vector < VecType, Size > & operator *= (
    const vector < VecType, Size > & v,
    const matrix < remove_units < VecType >::type, Size, Size > & mat )
{
    vector < VecType, Size > prev ( *this );

    for ( std::size_t c = 0; c < Size; ++c )
    {
        this->data[c] = 0;

        for ( std::size_t r = 0; r < Size; ++r )
        {
            // type times a scalar results in the same type
            // type + type results in the same type
            this->data[c] += prev->data[r] * mat[r][c];
        }
    }

    return *this;
}

-Jason


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