
Ublas : 
Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 20100723 08:23:23
All,
The fixed array is a good idea and I think this should be considered to be included in ublas. This would allow for small size vectors and matrices to work in near optimal state (i.e. something like defining a struct vec3d {double data[3]};
I also implemented (among other people as I can see) this in the past and it should be somewhere in the list, but if Markus wants to take the task to integrate it into uBlas, I find his implementation sufficient.
A nice exercise (although I don't know if this is efficient anymore given the cpus and compilers we have), is to implement some basic loop unrolling algorithms through template metaprogramming to achieve some faster basic operations, like tvmet does. This would need some further study, because the compilers can nowadays unroll the loops when they detect const arguments and therefore getting uBlas to do the unrolling may gain nothing.
Furthermore in order for this addition to be complete, fixed_vector and fixed_matrix classes should be implemented, that would be similar to bounded_vector and bounded_matrix (without the size member variables). IMHO If this is done (and given a few unit tests), the implementation would be at an excellent stage to be included into uBlas.
If I remember well from my implelentation the major decision that has to be made relates to the resize(..) member function. Since the fixed types cannot resize it would seem obvious that those functions should not be implemented at all, but I think uBlas is using it in some algorithms, so either the algorithms need to be specialized, or the the fixed type resize function needs to be implements as an empty function. I think the first option is the best.
Nice work Markus and I hope this will make it in soon!
Best
Nasos
From: david.bellot_at_[hidden]
Date: Fri, 23 Jul 2010 09:25:18 +0200
To: ublas_at_[hidden]
Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
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 _________________________________________________________________ The New Busy is not the too busy. Combine all your email accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:enUS:WM_HMP:042010_4