0

I have two matrices A, B with the same dimension. I want to perform element-wise matrix multiplication. So, I iterate two for loops and perform element-wise multiplication.

for (int i = 0; i < length; i++){ 
    for(int j = 0; j < width; j++){ 
        ans[i][j] = A[i][j] * B[i][j] ;
    }
}

but this is slow if the matrix size is huge (million elements or more). Is there any way to improve or speedup this process? How to do this?

  • look for different algorithms or try other languages. since your code snippet is small, give rust language a try and see if it's any faster for your needs. [here is a benchmark](https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust.html) – mamady Oct 03 '21 at 07:20
  • No matter what language I use. I want to know is there any better approach to perform element wise multiplication than the one mentioned above. – Mohibur_Cou Oct 03 '21 at 11:42
  • Does this answer your question? [Fast integer matrix multiplication with bit-twiddling hacks](https://stackoverflow.com/questions/37098856/fast-integer-matrix-multiplication-with-bit-twiddling-hacks) – Joe Oct 28 '21 at 10:31

0 Answers0