@@ -1253,12 +1253,12 @@ def read(self, n_bytes):
12531253def test__ftype4scaled_finite_warningfilters ():
12541254 # This test checks our ability to properly manage the thread-unsafe
12551255 # 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
12591258 # 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+
12621262 go = threading .Event ()
12631263 stop = threading .Event ()
12641264 err = []
@@ -1269,21 +1269,29 @@ def run(self):
12691269 go .set ()
12701270 while not stop .is_set ():
12711271 warnings .filters [:] = []
1272- time .sleep (0.01 )
1272+ time .sleep (0 )
12731273 class CheckScaling (threading .Thread ):
12741274 def run (self ):
12751275 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
12811287 stop .set ()
1288+
12821289 thread_a = CheckScaling ()
12831290 thread_b = MakeTotalDestroy ()
12841291 thread_a .start ()
12851292 thread_b .start ()
12861293 thread_a .join ()
12871294 thread_b .join ()
1295+
12881296 if err :
12891297 raise err [0 ]
0 commit comments