Boost logo

Ublas :

Subject: Re: [ublas] Numeric traits for ublas bounded_vector and matrix
From: Jesse Perla (jesseperla_at_[hidden])
Date: 2010-02-19 10:36:33


Rutger ter Borg <rutger <at> terborg.net> writes:
> I guess you actually mean "has_static_size" or "is_fully_static" or
> something like that. You have those cases, like the matrix of the eigen
> library, which permit you to specify one static size (e.g., the row size),
> and one dynamic. If we're going to introduce a meta-function, it should
> handle all cases in a clean way somehow.

I didn't think of it, you are right. has_static_size is a better name and the
matrix ones should be has_static_row_size and has_static_column size.
is_fully_static might also be useful, but is gravy.

>
> This is incorrect. Static sizes != bounded sizes. The template argument used
> ublas::bounded_vector<double, 3> a( 1 );
> which is a vector of length 1, but with pre-allocated storage of 3.
Hmm.... I didn't think of that that.

>
> I don't see why you couldn't do static asserts / specialize algorithms on
> typename result_of::size_row< double[10][10] >::type == mpl::int_<10>

Cool. If this works with bounded matrices/vectors,
then I think we have a winner.

> Please let me know if you think something is not possible with the current
> bindings and/or if you need some kind of easy meta-function added for your
> enable_if stuff (or other magic).

I think the has_static_size, has_static_column_size, has_static_row_size would
be very useful for enable_if.

Here are a few others that I ended up having to write for various purposes,
I think some of them might be useful if done correctly. The naive
implementation I used is obvious in all cases.

//Changing value types
change_vector_value_type<ublas::vector<double>, int>::type
 == vector<int>
change_vector_value_type<ublas::bounded_vector<double, 3>, int>::type
 == bounded_vector<int, 3>

change_matrix_value_type<ublas::matrix<double>, int>::type
 == vector<int>

//Changing the sizes of bounded and dynamic vectors/matrices.
//These came up when I was implementing my generic polynomial class
//that needed to return a polynomial of 1 less degree for the derivative

adjust_vector_size<
  ublas::bounded_vector<double, 4>,
  1 //Adds 1 to the size... could be -1 to subtract
>::type == ublas::bounded_vector<double, 5>

adjust_vector_size<
  ublas::vector<double>,
  1 //Adds 1 to the size of the type, not the allocation
>::type == ublas::vector<double> //Same type!

... with equivalents for matrix resizings