Boost logo

Ublas :

Subject: Re: [ublas] question regarding elementwise matrix product
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 2009-05-26 15:17:45


Hi Kaveh,

hth:

# include <boost/numeric/ublas/symmetric.hpp>
# include <boost/numeric/ublas/io.hpp>
# include <boost/spirit/include/phoenix.hpp>

# include <vector>
# include <algorithm>

using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;
using namespace boost::numeric::ublas;

int main () {

    symmetric_matrix<double,lower> m(3, 3), n(3,3), u(3,3);
    generate(arg1, lambda[val(1.0)] )(m.data());
    generate(arg1, lambda[val(2.0)] )(n.data());
    
transform(arg1,n.data().begin(),u.data().begin(),lambda[arg1/arg2])(m.data());

    std::cout << u << std::endl;
}

Best regards,
Kim

Kaveh Kohan schrieb:
> Hi everybody,
>
> Would you please somebody tell me what is the most efficient way to do
> element-wise matrix multiplication or division? I guess using the
> iterator is the most efficient way but is there any cache issue or
> something like that? This kind of matrix product is Hadamard matrix
> product. Some blas vendors like sgi has optimized version of blas in
> which Hadamard product is implemented:
>
> http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/p_man/cat3/SCSL/DHAD.z
> <http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/p_man/cat3/SCSL/DHAD.z>
>
> I was wondering can ublas interface with those of course with some
> scarification on performance or it is not possible? If it is not
> possible what is the best approach to perform Hadamard product or
> element-wise matrix product.
>
>
> Regards,
> Kaveh
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>