Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-05-30 09:32:28


On Wednesday 30 May 2007 14:38, Albert Strasheim wrote:
> I would like to write:
>
> datamatrix -= meanvec;
> datamatrix /= varvec;
>
> and sometimes
>
> datarow -= meanvec;
> datarow /= varvec;
>
> Unless I am mistaken, one can't do this with uBLAS as-is?

You can do this by using outer products. You simply need a vector with all
elements equal to 1.

matrix A(5,2); vector b(5); scalar_vector e(2,1.0);
A += outer_prod(b, e); // add b to each column of A

element_prod(A, outer_prod(b,e)); // a(i,j) *= b(i)

> At some distant point in the
> future one might want to support broadcasting [1].

"Broadcasting" is simply computing outer products with all-one vectors.

mfg
Gunter

PS: please add you solution to the FAQ in

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Frequently_Asked_Questions_Using_UBLAS