Removing logging of matrices for a speedup
Speedup by summing differences in one go instead of iterating
Speedup by removing a matrix product
Speedup by reducing number of differences computed