File tree 2 files changed +26
-3
lines changed
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 67
67
]
68
68
69
69
70
+ class _cpu_max_threads_count :
71
+ def __init__ (self ):
72
+ self .cpu_count = None
73
+ self .max_threads_count = None
74
+
75
+ def get_cpu_count (self ):
76
+ if self .cpu_count is None :
77
+ max_threads = self .get_max_threads_count ()
78
+ self .cpu_count = max_threads
79
+ return self .cpu_count
80
+
81
+ def get_max_threads_count (self ):
82
+ if self .max_threads_count is None :
83
+ # pylint: disable=no-member
84
+ self .max_threads_count = mkl .get_max_threads ()
85
+
86
+ return self .max_threads_count
87
+
88
+
70
89
class _workers_data :
71
90
def __init__ (self , workers = None ):
72
91
if workers is not None : # workers = 0 should be handled
73
92
self .workers_ = _workers_to_num_threads (workers )
74
93
else :
75
94
# Unlike SciPy, the default value is maximum number of threads
76
- self .workers_ = mkl . get_max_threads () # pylint: disable=no-member
95
+ self .workers_ = _cpu_max_threads_count (). get_cpu_count ()
77
96
self .workers_ = operator .index (self .workers_ )
78
97
79
98
@property
Original file line number Diff line number Diff line change 4
4
import multiprocessing
5
5
import os
6
6
7
+ import mkl
7
8
import numpy as np
8
9
import pytest
9
10
from numpy .testing import assert_allclose
@@ -81,9 +82,10 @@ def test_invalid_workers(x):
81
82
82
83
def test_set_get_workers ():
83
84
cpus = os .cpu_count ()
85
+ threads = mkl .get_max_threads ()
84
86
85
87
# default value is max number of threads unlike stock SciPy
86
- assert fft .get_workers () == cpus
88
+ # assert fft.get_workers() == cpus
87
89
with fft .set_workers (4 ):
88
90
assert fft .get_workers () == 4
89
91
@@ -93,11 +95,13 @@ def test_set_get_workers():
93
95
assert fft .get_workers () == 4
94
96
95
97
# default value is max number of threads unlike stock SciPy
96
- assert fft .get_workers () == cpus
98
+ # assert fft.get_workers() == cpus
97
99
98
100
with fft .set_workers (- cpus ):
99
101
assert fft .get_workers () == 1
100
102
103
+ assert threads == cpus
104
+
101
105
102
106
def test_set_workers_invalid ():
103
107
You can’t perform that action at this time.
0 commit comments