Boost logo

Ublas :

Subject: Re: [ublas] Problem with nested products
From: Andrea Cassioli (cassioliandre_at_[hidden])
Date: 2010-12-20 12:33:30


Hi,
I was just looking at the same thing few days ago! For what I have
understood, prod() returns a temporary object for which does not
exsist a corresponding prod, so the composition prod(matrix,
prod(matrix,matrix)) is allowed.

Clearly one can use a vector instead, but it is not always the case.
It is a functionality that should be implemented.

Interestingly, forcing a noalias on the result of the inner prod, i.e.

  ublas::matrix<double> result_direct = ublas::prod(B, ublas::noalias(
ublas::prod(A,B) ));

the compiler says:

 error: no matching function for call to
‘prod(boost::numeric::ublas::matrix<double>&,
boost::numeric::ublas::noalias_proxy<const
boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<double>,
boost::numeric::ublas::matrix<double>,
boost::numeric::ublas::matrix_matrix_prod<boost::numeric::ublas::matrix<double>,
boost::numeric::ublas::matrix<double>, double> > >)’

that is much clearer. The first prod returns a matrix_matrix_binary
operation, for which there are no available conversion for any of the
prod versions.

Andrea

On 12/20/10, Umut Tabak <u.tabak_at_[hidden]> wrote:
> On 12/20/2010 05:55 PM, Umut Tabak wrote:
>>>
>>
>> Compiles fine here, which version are you using?
>>
>
> Sorry for the stupid reply, see this one
>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/vector.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> namespace ublas = boost::numeric::ublas;
>
> // Take a matrix A and a row vector B
> //void UBlasStuff(ublas::matrix<double> A,ublas::matrix<double> B) {
> void UBlasStuff(ublas::matrix<double> A,ublas::vector<double> B) {
> // ublas::matrix<double> BTrans = ublas::trans(B);
> //
> // // the next two lines work
> // ublas::matrix<double> intermediate_result = ublas::prod(B,A);
> // ublas::matrix<double> result = ublas::prod(intermediate_result,BTrans);
>
> // the next two lines do not compile if uncommented
> // ublas::matrix<double> result_direct =
>
> double result_direct =
> ublas::inner_prod(B,ublas::prod(A,B));
>
> }
>
> int main(int argc,char** argv) {
> ublas::matrix<double> A(3,3); // uninitialized since we're looking for a
> //ublas::matrix<double> B(1,3); // compilation error, not a runtime error
> ublas::vector<double> B(3); // compilation error, not a runtime error
> UBlasStuff(A,B);
> return 0;
> }
>
>
> --
> - Hope is a good thing, maybe the best of things
> and no good thing ever dies...
> The Shawshank Redemption, replique of Tim Robbins
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: cassioliandre_at_[hidden]
>

-- 
Andrea Cassioli