def phi(A): """ Return lower triangle of A and halve the diagonal. """ B = A.tril() B = B - 0.5 * torch.diag(torch.diag(B)) return B