Re: I have a problem with expression templates

Gunter Winkler <[email protected]>
Newsgroups gmane.comp.lib.boost.ublas
Message-ID <[email protected]>
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


_______________________________________________
ublas mailing list
[email protected]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.