def test_real_non_PD_matrix(self): mat = np.array([[1, 2], [3, 4]]) with pytest.raises(ValueError): is_PD(mat) mat_PD = nearest_PD(mat) assert is_PD(mat_PD) assert np.allclose( mat_PD, np.array([[1.31461828, 2.32186616], [2.32186616, 4.10085767]]))
def test_real_PD_matrix(self): mat = np.eye(3) assert is_PD(mat) assert np.allclose(nearest_PD(mat), mat)
def test_non_square_matrix(self): mat = np.array([[1, 2, 3], [4, 5, 6]]) with pytest.raises(ShapeError): is_PD(mat)
def test_non_Hermitian_matrix(self): mat = np.array([[1, 2], [3, 4]]) with pytest.raises(ValueError): is_PD(mat)
def test_vector(self): vec = np.array([7, 8, 9]) with pytest.raises(ShapeError): is_PD(vec)
def test_complex_PD_matrix(self): mat = np.array([[4, 1.5 + 1j], [1.5 - 1j, 3]]) assert is_PD(mat)
def test_real_non_PD_matrix(self): mat = np.array([[1, 2.5], [2.5, 4]]) assert not is_PD(mat)
def test_real_PD_matrix(self): mat = np.eye(3) assert is_PD(mat)
def test_complex_non_PD_matrix(self): mat = np.array([[4, 2 + 1j], [1 + 3j, 3]]) mat_PD = nearest_PD(mat) assert is_PD(mat_PD) assert np.allclose( mat_PD, np.array([[4.0 + 0.j, 1.5 - 1.j], [1.5 + 1.j, 3.0 + 0.j]]))