Reputation: 4436
I'm starting to use BLAS functions in c++ (specifically Intel MKL) to create faster versions of some of my old Matlab code.
It's been working out well so far, but I can't 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 vectors and call gemv repeatedly? I think this would work, but I feel like there should be something built in for this operation.
Upvotes: 5
Views: 3885
Reputation: 1528
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.
Upvotes: 3