Optimised some of the tensor operations.