@@ -1253,12 +1253,12 @@ def read(self, n_bytes):
1253
1253
def test__ftype4scaled_finite_warningfilters ():
1254
1254
# This test checks our ability to properly manage the thread-unsafe
1255
1255
# warnings filter list.
1256
- # 32MiB reliably produces the error on my machine; use 128 for safety
1257
- shape = (1024 , 1024 , 32 )
1258
- tst_arr = np .zeros (shape , dtype = np .float32 )
1256
+
1257
+ # _ftype4scaled_finite always operates on one-or-two element arrays
1259
1258
# Ensure that an overflow will happen for < float64
1260
- tst_arr [0 , 0 , 0 ] = np .finfo (np .float32 ).max
1261
- tst_arr [- 1 , - 1 , - 1 ] = np .finfo (np .float32 ).min
1259
+ finfo = np .finfo (np .float32 )
1260
+ tst_arr = np .array ((finfo .min , finfo .max ), dtype = np .float32 )
1261
+
1262
1262
go = threading .Event ()
1263
1263
stop = threading .Event ()
1264
1264
err = []
@@ -1269,21 +1269,29 @@ def run(self):
1269
1269
go .set ()
1270
1270
while not stop .is_set ():
1271
1271
warnings .filters [:] = []
1272
- time .sleep (0.01 )
1272
+ time .sleep (0 )
1273
1273
class CheckScaling (threading .Thread ):
1274
1274
def run (self ):
1275
1275
go .wait ()
1276
- try :
1277
- # Use float16 to ensure two failures and increase time in function
1278
- _ftype4scaled_finite (tst_arr , 2.0 , 1.0 , default = np .float16 )
1279
- except Exception as e :
1280
- err .append (e )
1276
+ # Give ourselves a few bites at the apple
1277
+ # 200 loops through the function takes ~10ms
1278
+ # The highest number of iterations I've seen before hitting interference
1279
+ # is 131, with 99% under 30, so this should be reasonably reliable.
1280
+ for i in range (200 ):
1281
+ try :
1282
+ # Use float16 to ensure two failures and increase time in function
1283
+ _ftype4scaled_finite (tst_arr , 2.0 , 1.0 , default = np .float16 )
1284
+ except Exception as e :
1285
+ err .append (e )
1286
+ break
1281
1287
stop .set ()
1288
+
1282
1289
thread_a = CheckScaling ()
1283
1290
thread_b = MakeTotalDestroy ()
1284
1291
thread_a .start ()
1285
1292
thread_b .start ()
1286
1293
thread_a .join ()
1287
1294
thread_b .join ()
1295
+
1288
1296
if err :
1289
1297
raise err [0 ]
0 commit comments