Boost logo

Ublas :

Subject: Re: [ublas] question regarding elementwise matrix product
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 2009-05-28 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)] )(;
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(,,1.0 ); This will have the same
> generate(arg1, lambda[val(2.0)] )(;
> transform(arg1,,,lambda[arg1/arg2])(;
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(,,1.0 );
    std::fill(,,2.0 );
    std::cout << u << std::endl;
> Plus can you explain a little what it does because notation-wise, it
> is very confusing for me. Definitely ignorance frommy side but I would
> appreciate if you describe it a little bit.
> Thanks,
> Kaveh
> ------------------------------------------------------------------------
> **