Boost logo

Ublas :

Subject: Re: [ublas] I have a problem with expression templates
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2012-09-26 15:53:00


Hello,

Am 26.09.2012 19:59, schrieb Oswin Krause:
> Hi,
>
> it is a bad idea to nest calls to prod(), so ublas prevents it. Your
> workaround with the intermediate result is fine.
>
> Also, try ublas::prod(trans(A), ublas::prod<ublas::matrix<double> >(B,
> A))
Let me add some additional explanation:

The expression prod(A, B) does not mean "compute the product of A and
B". It means "remember to multiply A and B on demand". The actual
computation is deferred until next assignment.

What does that mean for a nested prod()?

prod(A, prod(C,D)) means that during computation of the final result
each element of B is computed (repeatedly on the fly) from the
expression prod(C,D). The "performance" would be a bad surprise. Thus
uBLAS explicitly forbids nested product expressions.

The solution is to use a temporary (as George said) or to define the
result type of prod as a real matrix instead of the default
matrix_expression (as Oswin suggested).

mfg
Gunter