Boost logo

Ublas :

Subject: Re: [ublas] Slicing
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-11-27 15:44:33


Am Donnerstag, 27. November 2008 17:23 schrieb Markus Weimer:
> Hi Ralf and other knowledgeables,
>
> thanks for your hint. This seems to work, but not in my case. I want
> to set some elements of a row of a matrix based on the multiplication
> of a one matrix with a subset of the columns of another one. Sounds a
>
> bit complicated and it probably is:
> > ublas::row(G, i) = ublas::row(ublas::prod(GF, X), j);
>

This should exactly give what you desire: compute only the j-th row of
GF*X and assign this to the i-th row of G

The expression "prod(GF,X)" does not mean "compute GF*X" - it is only an
expression template. The real computation is done during the assignment
for exactly the elements that are assigned. (This is a good example how
expression templates provide the effect of lazy computation.)

btw.

noalias( ublas::row(G, i) ) = ublas::row(ublas::prod(GF, X), j);

is slightly more efficient and for best performance GF should be row
major and X should be column major.

mfg
Gunter