<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 30 January 2018 at 17:22, Andrew Nelson <span dir="ltr"><<a href="mailto:andyfaff@gmail.com" target="_blank">andyfaff@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div>I have a matrix multiplication that I'd like to optimize.</div><div><br></div><div>I have a matrix `a` (dtype=complex) with shape (N, M, 2, 2). I'd like to do the following multiplication:</div><div><br></div><div>a[:, 0] @ a[:, 1] @ ... @ a[:, M-1]</div><div><br></div><div>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).</div><div><br></div><div>What would be the best way of going about this?</div></div></blockquote><div><br></div><div>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.</div></div>
</div></div>