This is exactly what I was doing.
I didn’t write the code, I just translated it from numpy to torch.
I also realized the code was utterly redundant!
Btw, I’ve been able to vectorize it 
I just need to vectorize one last thing which, for now, I assumed being constant 
Thank you for the help, einsum was so cool to use