Computing expectations of an array, suggestions for speed improvements
I have a (N0, N1, N2, N3) Matrix V and a (N1, N1) Matrix M. N1 is typically around 30-50, N0xN1xN2xN3 is around 1 000 000. I want a new Matrix EV, for which the i0, i1, i2, i3 entry is given by
My current code to achieve that is:
I have to perform this operation many times, and it is the absolute bottleneck of my code. I wonder if there’s any potential for a speed improvement of my code. I appriciate suggestions!
Thus, we are avoiding any intermediate arrays for a memory efficient solution.
(1) Starting code that involved extending dimensions :
Please notice that we have used
(2) Next up, we have :
Thus, we are summing along
(3) Finally :
For this porting of