
Ublas : 
Subject: Re: [ublas] question regarding elementwise matrix product
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 20090528 16:19:08
Hi Kaveh,
Kaveh Kohan schrieb:
> Hi Kim,
>
> Thank you for your reply.
> I am sorry if my questions sounds naive. I ran into a problem
> compiling this program. Do I need to have a specific version of
> phoenix or spirit to compile this program. Since in my system,
> phoenix.hpp is located in "boost/spirit/phoenix.hpp", I changed your
> program to the following:
This is not a good idea, because including only phoenix.hpp is not
enough in your boost version.
( I use 1.39.)
> symmetric_matrix<double,lower> m(3, 3), n(3,3), u(3,3);
> generate(arg1, lambda[val(1.0)] )(m.data());
the plain data of your matrix is stored in the unbounded_array. Using
the member data() you have access to this vector. Since you have another
version of boost, i suggest you to change the above code to
std::fill(m.data().begin(), m.data().end,1.0 ); This will have the same
effect.
> generate(arg1, lambda[val(2.0)] )(n.data());
>
> transform(arg1,n.data().begin(),u.data().begin(),lambda[arg1/arg2])(m.data());
Using transform you can perform an element wise division. In blas there
is already an element_wise division called element_div.
Here is the complete code:
# include <boost/numeric/ublas/symmetric.hpp>
# include <boost/numeric/ublas/matrix_expression.hpp>
# include <boost/numeric/ublas/io.hpp>
# include <vector>
# include <algorithm>
using namespace boost::numeric::ublas;
int main () {
symmetric_matrix<double,lower> m(3, 3), n(3,3), u(3,3);
std::fill(m.data().begin(), m.data().end(),1.0 );
std::fill(n.data().begin(), n.data().end(),2.0 );
u=element_div(m,n);
std::cout << u << std::endl;
}
>
> Plus can you explain a little what it does because notationwise, it
> is very confusing for me. Definitely ignorance frommy side but I would
> appreciate if you describe it a little bit.
>
> Thanks,
> Kaveh
>
> 
> **