Element wise multiplication between matrices in BLAS?

北慕城南 提交于 2019-12-04 04:42:02

问题


Im starting to use BLAS functions in c++ (specifically intel MKL) to create faster versions of some of my old Matlab code.

Its been working out well so far, but I cant figure out how to perform elementwise multiplication on 2 matrices (A .* B in Matlab).

I know gemv does something similar between a matrix and a vector, so should I just break one of my matrices into vectprs and call gemv repeatedly? I think this would work, but I feel like there should be aomething built in for this operation.



回答1:


Use the Hadamard product. In MKL it's v?MUL. E.g. for doubles:

vdMul( n, a, b, y );

in Matlab notation it performs:

y[1:n] = a[1:n] .* b[1:n]

In your case you can treat matrices as vectors.



来源:https://stackoverflow.com/questions/23794763/element-wise-multiplication-between-matrices-in-blas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!