
Ublas : 
From: Gunter Winkler (guwi17_at_[hidden])
Date: 20061013 01:57:11
On Friday 13 October 2006 00:59, Nico Galoppo wrote:
> // !! needs negative sign here!
> //ublas::vector_expression<V> minus_b =  b;
> bone>get_core().save_solution(ublas::subrange(  b(), c, c+6));
Why do you use (b)() and not just (b)? The latter is the vector_expression?
If you have difficulties to define the correct overload of subrange(), then
you can directly try to use project().
> I have some efficiency concerns on that last line. If all the data in b()
> is going to be multiplied by 1.0 and stored in a temporary variable at
> each iteration in the for loop, then this is going to be ugly.
>
> I tried the uncommenting the line secondtolast line and replacing b() by
> minus_b, but the compiler didn't like that:
>
> d:\dev\hybrid\hybrid\articulated\character_baraff.h(179) : error C2440:
> 'initializing' : cannot convert from
> 'boost::numeric::ublas::vector_unary<E,F>' to
> 'boost::numeric::ublas::vector_expression<E>'
vector_expression<V> is the base type of any ublas vectorlike type. (See
BartonNackmanTrick or CRTP,
http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern )
Thus creating an intance of vector_expression<X> is not useful. You have to
create an instance of the correct type. For (b) it is:
vector_unary< V, scalar_minus<V> > (see vector_expression.hpp)
In general I would not recommend to explicitly use instances of ublas
expressions, first because the construction of types is compicated and may
change and second because ublas expression are designed to be short living
proxies that may become invalid after one use.
I'd like to add another general comment: If you write functions using ublas
classes, it is better to define them for vector_expressions and
matrix_expression instead of vector and matrix (return types should be
vectors and matrices is most cases).
template <class VECTOR, class MATRIS>
VECTOR do_something(const VECTOR& x, const MATRIX& m) ...
should be defined as
template <class VECTOR, class MATRIS>
VECTOR do_something(const vector_expression<VECTOR>& x, const
matrix_expression<MATRIX>& m) ...
and if you have to operate on subranges, you can even use
template <class VECTOR, class MATRIS>
VECTOR do_something(const vector_expression< vector_range<VECTOR> >& x, const
matrix_expression<MATRIX>& m) ...
mfg
Gunter