Boost logo

Ublas :

Subject: [ublas] A regression and a few ublas modifications for consideration
From: Jesse Perla (jesseperla_at_[hidden])
Date: 2010-02-19 11:14:03

The following are based on boost version 1.42 code. Sorry, I am not competent
enough to create patches to the trunk, but the changes are pretty small.

0) A while back we had discussed adding overload resolution to the matrix/vector
expressions involving scalars in order to implement operator*, etc.
The solution was to add an enable_if see line 2942ish of matrix_expression.hpp

The code committed to 1.42 was to test with:
enable_if< is_convertible<T1, typename E2::value_type >

But this ended up breaking an auto-differentiation library I was using...
Templated AD libraries will often have their own, arithmetic type which will
record operations of the type * a double, etc. for a matrix multiplication by
a scalar, etc. But you can't convert between them!

My quick fix was to change the enable_if to the following:
typename enable_if< is_arithmetic<T1>
Of course, this could get fancier and ensure that operator *(T1, value_type)
exists, but I don't think it is essential.

...I think that this is an important since arithmetic operations between
the types do not imply convertibility

1) While vector<> has an explicit on its constructor with the size,
bounded_vector does not. See line 551 of vector.hpp or so
I added an explicit and it solved some awful problems with automatic casting

2) While vector<> has a constructor that takes a size and then a value to
initialize with, bounded_vector does not. I added in the following constructor
for this operation and for consistency:

bounded_vector (size_type size, const value_type &value):
                vector_type (size)
{std::fill(begin(), end(), value);}