Boost logo

Ublas :

From: Vardan Akopian (vakopian_at_[hidden])
Date: 2005-06-24 16:00:25


On 6/24/05, Gunter Winkler <guwi17_at_[hidden]> wrote:
> On Friday 24 June 2005 10:47, Gunter Winkler wrote:
> > > > diagonal_matrix<double> z(sz), x(sz);
> > > > matrix<double> y(sz, sz);
> > > > matrix<double> B = prod(z, x - y);
>
> Just another remark:
>
> I would strongly discourage the use of the expression
> matrix<double> B = prod(z, x - y);
>
> because the computation is _very_ slow. (The banded iterators produce a big
> overhead on a dense matrix.)
>
> gcc-3.3 times:
> $ ./diag 1000
> fill: 0.03
> temp 0.39
> direct 16.62
> sum 0.43
> diff = 0 0
>
> gcc-3.4 times:
> $ ./diag 1000
> fill: 0.02
> temp 0.25
> direct 10.67
> sum 0.33
> diff = 0 0
>

Wow, I would have never thought... This makes me think we really need
some documentation, so people know the cost of some random and inocent
expressions they may wonna use. I guess this also answers my question,
about what workaround to use for immutable matrices (answer: the temp
way, or at least the sum). I'm actually using this for small size
matrices (sz <=6), but in a big loop. I'll try to time the 3
possibilities and report back.

-Vardan