Boost logo

Ublas :

Subject: Re: [ublas] Questions about prod(prod(A,B),C)
From: ublas_at_[hidden]
Date: 2008-11-27 07:06:24


Thank you to Peter and Gunter for their replies.

I have a couple of follow up questions if I may...

Q1:

> // Is there a better way to pretty-print a matrix for debugging?
> You may wrtie your own manipulator, e.g. to get octave like syntax.

Yes, Matlab/octave-like output is what I am aiming for. Do you mean
something like this the prettyprint(...) function that I have now
written (see attached .cpp file)?

Q2:

> // Why does this next line fail?
> //std::cout<< "vecs4 * A4 = "<< prod<matrix<std::complex<double>, column_major>>(vecs4,A4)<< std::endl;
> std::cout<< "vecs4 * A4 = "<< prod<matrix<std::complex<double>, column_major>>(herm(vecs4),A4)<< std::endl;

> what is the compiler output?

I'm confused by this. I don't want to calculate vecs4^\dagger A4, but
just the straight matrix product. Is that not possible??

Here is the compiler output:

3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(122) : error
C2668: 'boost::numeric::ublas::prod' : ambiguous call to overloaded function
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4868): could
be 'M boost::numeric::ublas::prod<cmat,C,C>(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E> &)'
3> with
3> [
3> M=cmat,
3>
C=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>
3> ]
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4809): or
       'boost::numeric::ublas::matrix_matrix_binary<E1,E2,F>
boost::numeric::ublas::prod<C,C>(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E> &)'
3> with
3> [
3>
E1=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E2=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
F=boost::numeric::ublas::matrix_matrix_prod<boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,std::complex<double>>,
3>
C=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>
3> ]
3> while trying to match the argument list '(cmat, cmat)'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2668: 'boost::numeric::ublas::prod' : ambiguous call to overloaded function
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4868): could
be 'M boost::numeric::ublas::prod<cmat,C,C>(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E> &)'
3> with
3> [
3> M=cmat,
3>
C=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>
3> ]
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4809): or
       'boost::numeric::ublas::matrix_matrix_binary<E1,E2,F>
boost::numeric::ublas::prod<C,C>(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E> &)'
3> with
3> [
3>
E1=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E2=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
F=boost::numeric::ublas::matrix_matrix_prod<boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,std::complex<double>>,
3>
C=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>
3> ]
3> while trying to match the argument list '(cmat, cmat)'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780: 'M &boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E2> &,const
boost::numeric::ublas::matrix_expression<E2> &,M &)' : expects 3
arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4850)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780:
'matrix_matrix_binary_traits<E1::value_type,E1,E2::value_type,E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E2>
&,boost::numeric::ublas::unknown_storage_tag,boost::numeric::ublas::unknown_orientation_tag)'
: expects 4 arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4795)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780: 'V &boost::numeric::ublas::prod(const
boost::numeric::ublas::vector_expression<E2> &,const
boost::numeric::ublas::matrix_expression<E2> &,V &)' : expects 3
arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4145)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780:
'matrix_vector_binary2_traits<E1::value_type,E1,E2::value_type,E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::vector_expression<E> &,const
boost::numeric::ublas::matrix_expression<E2>
&,boost::numeric::ublas::unknown_storage_tag,boost::numeric::ublas::column_major_tag)'
: expects 4 arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4090)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780: 'V &boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E2> &,const
boost::numeric::ublas::vector_expression<E> &,V &)' : expects 3
arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(3755)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780:
'matrix_vector_binary1_traits<E1::value_type,E1,E2::value_type,E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::vector_expression<E2>
&,boost::numeric::ublas::unknown_storage_tag,boost::numeric::ublas::row_major_tag)'
: expects 4 arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(3700)
: see declaration of 'boost::numeric::ublas::prod'

> // Why can I not do prod(prod(...)) like in this next line?
> It fails on purpose, as it would be ~ dim^4, instead ~dim^3 plus a temporary matrix.
> You have to specify the result type of the inner prod.

> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_UBLAS
> (Controlling the complexity of nested products)

I had been reading this site already, hence my trying the syntax
prod(prod<...>(A,B),C) above.

I can now get this to work

std::cout << "vecs4 * A4 * vecs4 = " << prod(prod<cmat>(vecs4,A4),vecs4)
<< std::endl;

but not this one:

std::cout << "vecs4 * A4 * vecs4 = " << prod(cmat(prod(vecs4,A4)),vecs4)
<< std::endl;

When it fails, the output is:

3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2668: 'boost::numeric::ublas::prod' : ambiguous call to overloaded function
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4868): could
be 'M boost::numeric::ublas::prod<cmat,C,C>(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E> &)'
3> with
3> [
3> M=cmat,
3>
C=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>
3> ]
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4809): or
       'boost::numeric::ublas::matrix_matrix_binary<E1,E2,F>
boost::numeric::ublas::prod<C,C>(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E> &)'
3> with
3> [
3>
E1=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E2=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
F=boost::numeric::ublas::matrix_matrix_prod<boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,std::complex<double>>,
3>
C=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>,
3>
E=boost::numeric::ublas::matrix<std::complex<double>,boost::numeric::ublas::column_major>
3> ]
3> while trying to match the argument list '(cmat, cmat)'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780: 'M &boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E2> &,const
boost::numeric::ublas::matrix_expression<E2> &,M &)' : expects 3
arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4850)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780:
'matrix_matrix_binary_traits<E1::value_type,E1,E2::value_type,E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::matrix_expression<E2>
&,boost::numeric::ublas::unknown_storage_tag,boost::numeric::ublas::unknown_orientation_tag)'
: expects 4 arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4795)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780: 'V &boost::numeric::ublas::prod(const
boost::numeric::ublas::vector_expression<E2> &,const
boost::numeric::ublas::matrix_expression<E2> &,V &)' : expects 3
arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4145)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780:
'matrix_vector_binary2_traits<E1::value_type,E1,E2::value_type,E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::vector_expression<E> &,const
boost::numeric::ublas::matrix_expression<E2>
&,boost::numeric::ublas::unknown_storage_tag,boost::numeric::ublas::column_major_tag)'
: expects 4 arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(4090)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780: 'V &boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E2> &,const
boost::numeric::ublas::vector_expression<E> &,V &)' : expects 3
arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(3755)
: see declaration of 'boost::numeric::ublas::prod'
3>c:\users\crodgers\documents\visual studio
2008\projects\boostexample1\boostexample1\test_prod.cpp(128) : error
C2780:
'matrix_vector_binary1_traits<E1::value_type,E1,E2::value_type,E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E> &,const
boost::numeric::ublas::vector_expression<E2>
&,boost::numeric::ublas::unknown_storage_tag,boost::numeric::ublas::row_major_tag)'
: expects 4 arguments - 2 provided
3> c:\program files
(x86)\boost\boost_1_36_0\boost\numeric\ublas\matrix_expression.hpp(3700)
: see declaration of 'boost::numeric::ublas::prod'

I attach a copy of my latest test program.

Many thanks again,

Chris.

-- 
Dr Chris Rodgers MChem DPhil
Junior Research Fellow of Merton College, Oxford and
Oxford Centre for Clinical Magnetic Resonance Research
christopher.rodgers_at_[hidden] ~ 01865 221321