File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change 9
9
pytest .skip (allow_module_level = True , reason = "no threading support in wasm" )
10
10
11
11
12
- def test_parallel_errstate_creation ():
12
+ def run_threaded (func , iters , pass_count = False ):
13
+ with concurrent .futures .ThreadPoolExecutor (max_workers = 8 ) as tpe :
14
+ if pass_count :
15
+ futures = [tpe .submit (func , i ) for i in range (iters )]
16
+ else :
17
+ futures = [tpe .submit (func ) for _ in range (iters )]
18
+ for f in futures :
19
+ f .result ()
20
+
21
+
22
+ def test_parallel_randomstate_creation ():
13
23
# if the coercion cache is enabled and not thread-safe, creating
14
24
# RandomState instances simultaneously leads to a data race
15
25
def func (seed ):
16
26
np .random .RandomState (seed )
17
27
18
- with concurrent .futures .ThreadPoolExecutor (max_workers = 8 ) as tpe :
19
- futures = [tpe .submit (func , i ) for i in range (500 )]
20
- for f in futures :
21
- f .result ()
28
+ run_threaded (func , 500 , pass_count = True )
29
+
30
+ def test_parallel_ufunc_execution ():
31
+ # if the loop data cache or dispatch cache are not thread-safe
32
+ # computing ufuncs simultaneously in multiple threads leads
33
+ # to a data race
34
+ def func ():
35
+ arr = np .random .random ((25 ,))
36
+ np .isnan (arr )
37
+
38
+ run_threaded (func , 500 )
You can’t perform that action at this time.
0 commit comments