|
Ublas : |
Subject: Re: [ublas] When I can not use two prec_prod's?
From: Peng Yu (pengyu.ut_at_[hidden])
Date: 2008-10-20 12:49:14
On Mon, Oct 20, 2008 at 11:05 AM, Maik Beckmann
<beckmann.maik_at_[hidden]> wrote:
> 2008/10/20 Peng Yu <pengyu.ut_at_[hidden]>:
>> On Sun, Oct 19, 2008 at 11:54 AM, Maik Beckmann
>> <beckmann.maik_at_[hidden]> wrote:
>>>
>>> The problem is the nested prec_cond call. This
>>> {{{
>>> #include <boost/numeric/ublas/matrix.hpp>
>>> #include <boost/numeric/ublas/io.hpp>
>>>
>>> int main () {
>>> typedef boost::numeric::ublas::matrix<double> mx_type;
>>> mx_type m(2, 2);
>>>
>>> m(0, 0) = 1;
>>> m(1, 0) = 2;
>>> m(0, 1) = 3;
>>> m(1, 1) = 4;
>>>
>>> std::cout << prec_prod(m, mx_type(prec_prod(m, m))) << std::endl;
>>> }
>>> }}}
>>> works, since mx_type(prec_prod(m, m)) forces the matrix expression
>>> returned by prec_prod(m, m) to be evaluated to mx_type, which in turn
>>> causes E2::complexity == 0.
>>
>> I don't understand why the result of the inner prec_prod has to be
>> type casted. Can't ublas be designed such that this type case is not
>> necessary? Or it is deliberately designed to be of this way?
>
> It's not a type cast, it's type construction to create a temporary
> matrix<double>. This line
> {{{
> std::cout << prec_prod(m, mx_type(prec_prod(m, m))) << std::endl;
> }}}
> has the same meaning as
> {{{
> mx_type tmp = prec_prod(m, m);
> std::cout << prec_prod(m, tmp) << std::endl;
> }}}
>
> I don't know the ublas code in detail, thus I cannot answer the question why
> {{{
> std::cout << inner_prod(v, prec_prod(m, v)) << std::endl;
> }}}
> compiles, right now, and I don't like to start wild guessing.
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?
Thanks,
Peng