Boost logo

Ublas :

Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
From: Andrea Cassioli (cassioliandre_at_[hidden])
Date: 2010-07-23 04:03:40

Hi guys,
I've played a little bit with the fixed_size array (which was missing
as far as I know in uBlas) and seems to be a very promising idea!
Looking around to address the issues you rise about the fixed_array
ctor, array items initialization does not seem an easy to solve
Some people propose to use #define expansion to recursively generate a
list of the type

array_type v[N]={value,value..}

But personally I do not think it is a crucial issues at the present time.

Good job guys!


On Fri, Jul 23, 2010 at 9:25 AM, David Bellot <david.bellot_at_[hidden]> wrote:
> Hi Markus,
> sounds a good idea. Let me investigate this. It's in fact on the todo list
> so it's very welcome.
> Cheers,
> David
> On Fri, Jul 23, 2010 at 00:16, Markus Grabner <grabner_at_[hidden]> wrote:
>>        Hi all!
>>    In boost::numeric::ublas, there exist different vector variants
>> (unbounded and bounded). All of them can be resized dynamically (up to a
>> maximum size defined at compile time in the case of the bounded vector).
>> Therefore the vector class (or the underlying storage array) have a size
>> member which indicates the current size of the vector.
>> However, it would be extremely useful to have a vector of fixed size,
>> i.e.,
>> one which can't be resized dynamically, but has its size statically
>> defined
>> at compile time. Such a vector does not require a size member and only
>> consumes N*sizeof(T) bytes of storage, where N is the (static) vector size
>> and T the value type. Many libraries dealing with geometric data (OpenGL
>> and
>> OpenInventor being prominent examples) store their data in compact arrays
>> in
>> their native data types, e.g., the values (x0,y0,z0,x1,y1,z1,x2,y2,z2)
>> stored in consecutive memory locations define three points in 3D space. By
>> means of a fixed size vector, the entire boost::numeric::ublas
>> functionality
>> could be applied to such arrays by a simple reinterpret_cast on each
>> element. This is not possible with the bounded or unbounded vectors since
>> the vector must be constructed before with its size member properly
>> initialized, and the actual vector data must therefore be copied
>> explicitly
>> before use.
>> I tried to create a fixed_array class to implement this proposal (see
>> attachment), it can be used, e.g., to create the equivalent of the
>> OpenInventor "SbVec3f" data type as follows:
>> typedef boost::numeric::ublas::vector<float,fixed_array<float,3> >
>> vec3d_t;
>> It is probably not the cleanest solution, and I skipped the serialization
>> stuff altogether, but it demonstrates an approach how this can be done.
>> Is such a feature already available in ublas and did I just miss it? If
>> not,
>> what do you think about adding it to improve boost's interoperability with
>> other libraries?
>>        Thanks & kind regards,
>>                Markus
>> --
>> Markus Grabner
>> Institute for Computer Graphics and Vision
>> Graz University of Technology, Inffeldgasse 16a/II, 8010 Graz, Austria
>> WWW:
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> Sent to: david.bellot_at_[hidden]
> --
> David Bellot, PhD
> david.bellot_at_[hidden]
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> Sent to: cassioliandre_at_[hidden]

Andrea Cassioli