Boost logo

Ublas :

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


Rutger ter Borg <rutger <at> terborg.net> writes:
> I guess you didn't check out for a while? bounded_matrix and bounded_vector
> have been in svn for a couple of weeks now.

Busted. Teach me right...

>
> bounded_matrices do not have static sizes, they have static strides -- or is
> this what you mean?

I think I mean sizes, but let me be more specific. Here are the metafunctions I
implemented (poorly and specifically for ublas):

is_bounded_vector< ublas::bounded_vector<double, 3> >::value == true
is_bounded_vector< const ublas::bounded_vector<double, 3>& >::value == true
is_bounded_vector< ublas::vector<double> >::value == false
is_bounded_vector< garbage_type >::value == false
is_bounded_matrix< ublas::bounded_matrix<double, 3, 3> >::value == true
is_bounded_matrix< ublas::matrix<double> >::value == false
is_bounded_matrix< garbage_type >::value == false

static_vector_size< ublas::bounded_vector<double, 3> >::value == 3
static_vector_size< const ublas::bounded_vector<double, 3>& >::value == 3
static_vector_size< ublas::bounded_vector<double, 3> >::value == 3
static_matrix_rows< ublas::bounded_matrix<int, 3, 2> >::value == 3
static_matrix_columns< ublas::bounded_matrix<int, 3, 2> >::value == 2

What I didn't implement but was considering was what should happen with
these metafunctions when the type isn't statically allocated. Why not
just have it fail? Because otherwise you may get into the messy world
of lazy template instantiation when getting traits from various types...

static_vector_size< ublas::vector<double> >::value ==
numeric_limits<std::size_t>::NaN?

static_matrix_rows< ublas::matrix<double> >::value == NaN?
static_matrix_columns< ublas::matrix<double> >::value == NaN?
static_matrix_rows< ublas::vector<double> >::value //This should fail

Why is this stuff useful? Besides static_asserts/enable_if, it also lets you
have specialized algorithms for stack allocated vectors.