Boost logo

Ublas :

From: Nico Galoppo (nico_at_[hidden])
Date: 2006-10-13 10:02:46


Gunter Winkler wrote:
>> 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().
>

Doh! Sorry, I don't know why I didn't try that first. I assumed it wouldn't
work, probably because I had issues with that in the past, where I was actually
acessing b's data, where you obviously have to evaluate the expression. Your
suggestion worked perfectly though, thanks.

BTW, if I understand the concept of expression templates, I assume that this
will not construct a negated temporary of b. Is that correct?

> vector_expression<V> is the base type of any ublas vector-like type. (See
> Barton-Nackman-Trick 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)

Thanks, that makes sense! My knowledge of ET and CRTP is far from complete, but
I understand what you mean.

> 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).

That's what I was trying to do, right? Anyways, it's a good comment, and I've
started doing so since a while.

Why do the return types have to be vectors/matrices in most cases? Isn't that
potentially expensive (many data copies) ? Is it a bad thing to try to write
functions that return vector/matrix expressions?

> 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) ...

Why is this necessary? vector_range is a model of vector_expression, so why
wouldn't the first example work?

Thanks for all your comments!

--nico

-- 
nico galoppo von borries     |  address: 119 fidelity st., carrboro
comp. graphics phd. student  |           north carolina, 27510 USA
UNC, chapel hill             |  phone: +1 (919) 962-1898 (office)
                              |         +1 (919) 942-4388 (home)
                              |  email: nico at cs dot unc dot edu
                              |  homepage: http://www.ngaloppo.org