Boost logo

Ublas :

From: Vardan Akopian (vakopian_at_[hidden])
Date: 2005-06-24 15:43:01


On 6/24/05, Gunter Winkler <guwi17_at_[hidden]> wrote:
> On Friday 24 June 2005 00:13, Vardan Akopian wrote:
> > Am I correct that the workaround of assigning to a dense matrix first
> > (as in my sample code) has an additional cost of copying the whole
> > data (in other words A is not lazily evaluated)? Is there a better
> > workaround to avoid that cost?
>
> Yes.
>
> > > diagonal_matrix<double> z(sz), x(sz);
> > > matrix<double> y(sz, sz);
> > > matrix<double> B = prod(z, x - y);
>
> y -= x;
> B = prod(z, -y);
> y += x;
>
> {
> // for the experienced user:
> y .minus_assign( x );
> B .assign( z, -y );
> y .plus_assign( x );
> }
>

Agreed in general, but it's not possible, if x and y are immutable
(e.g. const ref.'s), and this is my case. Any solution for this case?

-Vardan