Boost logo

Ublas :

From: Vardan Akopian (vakopian_at_[hidden])
Date: 2006-11-20 15:39:56


Hi Gunter,

What is the reason that matrix_expression is not non-copyable? I know
it's not assignable, but why not make it non-copyable? That would
prevent passing by value, and thus the wrong initialize() function
below.

Thanks.
-Vardan

On 11/20/06, Gunter Winkler <guwi17_at_[hidden]> wrote:
> On Sunday 19 November 2006 00:13, Manoj Rajagopalan wrote:
>
> > template<typename E>
> > void initialize(matrix_expression<E> A,
> > typename E::value_type const& value)
> > {
> > ...
> > }
>
> Dealing with matrix expression directly is tricky, because of the CRTP usage.
>
> 1) You always have to use references to a matrix_expression as function
> parameter, because the (default) copy constructor of matrix_expression does
> not copy anything. (matrix_expression has no member variables and thus its
> size is zero!)
>
> template<typename E>
> void initialize(matrix_expression<E>& A,
> typename E::value_type const& value)
> {
> E& A_ref = A(); // this is the "official" way (just hiding the cast)
> A_ref = scalar_matrix<typename E::value_type>(A_ref.size1(), A_ref.size2(),
> value);
> }
>
> 2) Sometimes you have to explicitly create instances (because you need
> something to refer to and you can't have a direct instance of a
> matrix_expression<X>)
>
> matrix_range< matrix<int> > sub_A(A,range(1,3),range(1,3));
> initialize(sub_A, 8);
>
> In short:
> Never instantiate matrix_expression because it contains no data.
> Longer:
> matrix_expression exists only because you need some common type
> for all expressions. The price you pay is to use references everywhere.
>
> mfg
> Gunter
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
>
>
>