Sorry, how would I do it as it is written? This is implemented with python lists which are really slow. I want to make this as fast as possible to reduce training time.
It probably should also be noted that this code is from the forward method of a costum layer, while running the model on a gpu.