fast_diag function

Fast computation of diag(y %% M %% t(y))