Implement optimised function for square inner product matrix.