Optimisation of matrix multiplication
Hi all, I have a matrix multiplication that I'd like to optimize. I have a matrix `a` (dtype=complex) with shape (N, M, 2, 2). I'd like to do the following multiplication: a[:, 0] @ a[:, 1] @ ... @ a[:, M-1] where the first dimension, N, is element wise (and hopefully vectorisable) and M>=2. So for each row do M-1 matrix multiplications of 2x2 matrices. The output should have shape (N, 2, 2). What would be the best way of going about this? -- _____________________________________ Dr. Andrew Nelson _____________________________________
On 30 January 2018 at 17:22, Andrew Nelson <andyfaff@gmail.com> wrote:
Hi all, I have a matrix multiplication that I'd like to optimize.
I have a matrix `a` (dtype=complex) with shape (N, M, 2, 2). I'd like to do the following multiplication:
a[:, 0] @ a[:, 1] @ ... @ a[:, M-1]
where the first dimension, N, is element wise (and hopefully vectorisable) and M>=2. So for each row do M-1 matrix multiplications of 2x2 matrices. The output should have shape (N, 2, 2).
What would be the best way of going about this?
I should add that at the moment I have 4 (N, M) arrays and am doing the matrix multiplication in a for loop over `range(0, M)`, in an unrolled fashion for each of the 4 elements.
participants (1)
-
Andrew Nelson