|
Ublas : |
Subject: Re: [ublas] When I can not use two prec_prod's?
From: Peng Yu (pengyu.ut_at_[hidden])
Date: 2008-10-20 17:59:57
On Mon, Oct 20, 2008 at 4:54 PM, Gunter Winkler <guwi17_at_[hidden]> wrote:
> Am Montag, 20. Oktober 2008 18:49 schrieb Peng Yu:
>
>> Can somebody who has more knowledge of ublas details ask the question
>> why
>>
>> std::cout << inner_prod(v, prec_prod(m, v)) << std::endl;
>>
>> would compile, but why a temporary need to have to make
>>
>> std::cout << prec_prod(m, mx_type(prec_prod(m, m))) << std::endl;
>>
>> compile?
>
> It is because prod(A, prod(B, C)) has a much bigger complexity than
> expected. The reason is that the matrix element (j,k) of prod(B,C) is
> computed on the fly whenever it is needed for the product whit A. The
> result would be that prod(B, C) is computed n^2 times. In order to
> prevent such runtime "surprise" we added a static assertion which
> causes a compiler error. (Unfortunately the message is not as clear as
> needed. However we have to wait for a compiler that supports static
> assertions to improve this.)
>
> If you compute an inner product of a vector and a matrix-vector-product
> then you have to compute each element of prod(m,v) exactly once.
prec_prod(m, mx_type(prec_prod(m, m)))
Since we always need such temporary, can it be generated without
writing 'mx_type' explicitly, so that the syntax can be cleaner.
Thanks,
Peng