idx_im = argwhere(iscomplex(w))
// check if all complex eigenvalues have conjugate pairs
if len(idx_im[::2, 0]) != len(idx_im[1::2, 0]):
raise ValueError("expected complex-conjugate pairs of eigenvalues")
// all eigenvalues to diagonal form
After Change
// get indices for each first pair of complex eigenvalues
complex_mask = iscomplex(w)
n_complex = complex_mask.sum(axis=-1)
idx_im = argwhere(complex_mask)
// check if all complex eigenvalues have conjugate pairs
if not (n_complex % 2 == 0).all():
raise ValueError("expected complex-conjugate pairs of eigenvalues")