@@ -86,10 +86,64 @@ def test_allclose_validation():
86
86
dpt .allclose (x , False )
87
87
88
88
89
- def test_all_close_promotion ():
89
+ def test_allclose_type_promotion ():
90
90
get_queue_or_skip ()
91
91
92
92
x1 = dpt .ones (10 , dtype = "i4" )
93
93
x2 = dpt .ones (10 , dtype = "i8" )
94
94
95
95
assert dpt .allclose (x1 , x2 )
96
+
97
+
98
+ def test_allclose_tolerance ():
99
+ get_queue_or_skip ()
100
+
101
+ x = dpt .zeros (10 , dtype = "f4" )
102
+ atol = 1e-5
103
+ y = dpt .full_like (x , atol )
104
+ assert dpt .allclose (x , y , atol = atol , rtol = 0 )
105
+
106
+ # about 8e-6
107
+ tol = float .fromhex ("0x1.0p-17" )
108
+ x = dpt .ones (10 , dtype = "f4" )
109
+ y = x - tol
110
+ assert dpt .allclose (x , y , atol = 0 , rtol = tol )
111
+
112
+
113
+ def test_allclose_real_fp_early_exists ():
114
+ get_queue_or_skip ()
115
+
116
+ x1 = dpt .asarray ([0.0 , dpt .inf , - dpt .inf ], dtype = "f4" )
117
+ x2 = dpt .asarray ([dpt .inf , 0.0 , - dpt .inf ], dtype = "f4" )
118
+
119
+ # early exists, inf positions are different
120
+ assert not dpt .allclose (x1 , x2 )
121
+
122
+ x2 = dpt .asarray ([0.0 , - dpt .inf , dpt .inf ], dtype = "f4" )
123
+
124
+ # early exists, inf positions are the same, but signs differ
125
+ assert not dpt .allclose (x1 , x2 )
126
+
127
+
128
+ def test_allclose_complex_fp_early_exists ():
129
+ get_queue_or_skip ()
130
+
131
+ x1 = dpt .asarray ([0.0 , dpt .inf , - dpt .inf ], dtype = "c8" )
132
+ x2 = dpt .asarray ([dpt .inf , 0.0 , - dpt .inf ], dtype = "c8" )
133
+
134
+ # early exists, inf positions of real parts are different
135
+ assert not dpt .allclose (x1 , x2 )
136
+
137
+ x2 = dpt .asarray ([0.0 , - dpt .inf , dpt .inf ], dtype = "c8" )
138
+
139
+ # early exists, inf positions of real parts are the same, but signs differ
140
+ assert not dpt .allclose (x1 , x2 )
141
+
142
+ x1 = dpt .asarray ([0.0 , dpt .inf * 1j , - dpt .inf * 1j ], dtype = "c8" )
143
+ x2 = dpt .asarray ([dpt .inf * 1j , 0.0 , - dpt .inf * 1j ], dtype = "c8" )
144
+
145
+ # early exists, inf positions of imag parts are different
146
+ assert not dpt .allclose (x1 , x2 )
147
+
148
+ x2 = dpt .asarray ([0.0 , - dpt .inf * 1j , dpt .inf * 1j ], dtype = "c8" )
149
+ assert not dpt .allclose (x1 , x2 )
0 commit comments