def test_sort_eig_order(self): """ Test if eigenvalue sorting has the correct sorting """ gyration_tensor = Gyration._gyration_tensor(cluster, None) eig_val, eig_vec = np.linalg.eig(gyration_tensor) eig_val, eig_vec = Gyration._sort_eig(eig_val, eig_vec, reverse=False) assert eig_val[2] >= eig_val[1] assert eig_val[1] >= eig_val[0]
def test_sort_eig_reverse(self): """ Test if eigenvalue sorting has the correct sorting in reverse """ gyration_tensor = Gyration._gyration_tensor(cluster, None) eig_val, eig_vec = np.linalg.eig(gyration_tensor) eig_val, eig_vec = Gyration._sort_eig(eig_val, eig_vec, reverse=True) assert eig_val[2] <= eig_val[1] assert eig_val[1] <= eig_val[0]
def test_sort_eig_transformation(self): """ Test if eigenvalue sorting results in the correct sorting via A*evec_i = eval_i*evec_i """ gyration_tensor = Gyration._gyration_tensor(cluster, None) eig_val, eig_vec = np.linalg.eig(gyration_tensor) eig_val, eig_vec = Gyration._sort_eig(eig_val, eig_vec, reverse=False) for i in range(3): t1 = np.matmul(gyration_tensor, eig_vec[:, i]) t2 = eig_val[i] * eig_vec[:, i] assert t1 == approx(t2)