Boost logo

Ublas :

Subject: Re: [ublas] fixed size vector in boost::numeric::ublas?
From: Markus Grabner (grabner_at_[hidden])
Date: 2010-08-02 14:00:56

Nasos Iliopoulos wrote:

> 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.
I slightly modified it to better fit into the existing ublas framework and
also added a fixed_vector template using the fixed_array (similar to
bounded_vector using bounded_array). A patch against revision 64531 is

> 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.
Indeed, I wasn't able to make gcc-4.5 unroll the loop in a simple vector
addition. However, this is an issue which affects the existing vector
implementations as well and should IMO be dealt with separately.

> 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.
As I said above, fixed_vector was an easy exercise. However, a fixed_matrix
is much more complicated (I will give some thoughts on this in a separate
message to keep this one to the point). Still I believe if fixed_vector is
easy and fixed_matrix is hard, then fixed_vector could be a useful addition
to boost even if fixed_matrix is not yet available. Do you agree with this?

As for the unit tests: I would certainly like to write unit tests for
fixed_vector, but when running "bjam" in, I get several
compilation errors. Is gcc-4.5 supposed to work with these tests, or shall
the tests be launched differently?

> 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.
I prefer an exception to be thrown on an attempt to resize a fixed_vector to
some different size (I'll give some more comments to the following posts).

> Nice work Markus and I hope this will make it in soon!
Thanks :-)

        Kind regards,

Markus Grabner
Institute for Computer Graphics and Vision
Graz University of Technology, Inffeldgasse 16a/II, 8010 Graz, Austria