@@ -1055,6 +1055,53 @@ def test__check_sdp_from_eigen_returns_definiteness(w, is_definite):
1055
1055
assert _check_sdp_from_eigen (w ) == is_definite
1056
1056
1057
1057
1058
+ @pytest .mark .unit
1059
+ @pytest .mark .parametrize ('w, tol, is_definite' ,
1060
+ [(np .array ([5. , 3. ]), 2 , True ),
1061
+ (np .array ([5. , 1. ]), 2 , False ),
1062
+ (np .array ([5. , - 1. ]), 2 , False )])
1063
+ def test__check_sdp_from_eigen_tol_psd (w , tol , is_definite ):
1064
+ """Tests that _check_sdp_from_eigen, for PSD matrices, returns
1065
+ False if an eigenvalue is lower than tol"""
1066
+ assert _check_sdp_from_eigen (w , tol = tol ) == is_definite
1067
+
1068
+
1069
+ @pytest .mark .unit
1070
+ @pytest .mark .parametrize ('w, tol' ,
1071
+ [(np .array ([5. , - 3. ]), 2 ),
1072
+ (np .array ([1. , - 3. ]), 2 )])
1073
+ def test__check_sdp_from_eigen_tol_non_psd (w , tol ):
1074
+ """Tests that _check_sdp_from_eigen raises a NonPSDError
1075
+ when there is a negative value with abs value higher than tol"""
1076
+ with pytest .raises (NonPSDError ):
1077
+ _check_sdp_from_eigen (w , tol = tol )
1078
+
1079
+
1080
+ @pytest .mark .unit
1081
+ @pytest .mark .parametrize ('w, is_definite' ,
1082
+ [(np .array ([1e5 , 1e5 , 1e5 , 1e5 ,
1083
+ 1e5 , 1e5 , 1e-20 ]), False ),
1084
+ (np .array ([1e-10 , 1e-10 ]), True )])
1085
+ def test__check_sdp_from_eigen_tol_default_psd (w , is_definite ):
1086
+ """Tests that the default tol argument gives good results for edge cases
1087
+ like even if the determinant is high but clearly one eigenvalue is low,
1088
+ (undefinite so returns False) or when all eigenvalues are low (definite so
1089
+ returns True)"""
1090
+ assert _check_sdp_from_eigen (w , tol = None ) == is_definite
1091
+
1092
+
1093
+ @pytest .mark .unit
1094
+ @pytest .mark .parametrize ('w' ,
1095
+ [np .array ([1. , - 1. ]),
1096
+ np .array ([- 1e-10 , 1e-10 ])])
1097
+ def test__check_sdp_from_eigen_tol_default_non_psd (w ):
1098
+ """Tests that the default tol argument is good for raising
1099
+ NonPSDError, e.g. that when a value is clearly relatively
1100
+ negative it raises such an error"""
1101
+ with pytest .raises (NonPSDError ):
1102
+ _check_sdp_from_eigen (w , tol = None )
1103
+
1104
+
1058
1105
def test__check_n_components ():
1059
1106
"""Checks that n_components returns what is expected
1060
1107
(including the errors)"""
0 commit comments