implement diag