Added diag function for matrices.