|
Ublas : |
Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
From: Riccardo Rossi (rrossi_at_[hidden])
Date: 2010-07-23 04:02:10
We have implemented a fixed size array with no overhead in storage
if you are interested you can find it at the address
http://kratos.cimne.upc.es/trac/browser/kratos/kratos/containers/array_1d.h
in case you consider it interesting we could easily release it under the
boost license
Riccardo
-- On Fri, 2010-07-23 at 09:25 +0200, David Bellot 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: http://www.icg.tugraz.at/Members/grabner > > _______________________________________________ > ublas mailing list > ublas_at_[hidden] > http://lists.boost.org/mailman/listinfo.cgi/ublas > Sent to: david.bellot_at_[hidden] > > > > -- > David Bellot, PhD > david.bellot_at_[hidden] > http://david.bellot.free.fr > > _______________________________________________ > ublas mailing list > ublas_at_[hidden] > http://lists.boost.org/mailman/listinfo.cgi/ublas > Sent to: rrossi_at_[hidden]