File tree 2 files changed +12
-7
lines changed
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 32
32
import contextlib
33
33
import contextvars
34
34
import operator
35
- import os
36
35
from numbers import Number
37
36
38
37
import mkl
@@ -101,7 +100,8 @@ def _workers_to_num_threads(w):
101
100
if _w == 0 :
102
101
raise ValueError ("Number of workers must not be zero" )
103
102
if _w < 0 :
104
- _cpu_count = os .cpu_count ()
103
+ # SciPy uses os.cpu_count()
104
+ _cpu_count = mkl .get_max_threads () # pylint: disable=no-member
105
105
_w += _cpu_count + 1
106
106
if _w <= 0 :
107
107
raise ValueError (
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
@@ -80,22 +81,26 @@ def test_invalid_workers(x):
80
81
81
82
82
83
def test_set_get_workers ():
83
- cpus = os .cpu_count ()
84
+ # cpus = os.cpu_count()
85
+ threads = mkl .get_max_threads () # pylint: disable=no-member
86
+ # cpus and threads are usually the same but in CI, cpus = 4 and threads = 2
87
+ # SciPy uses `os.cpu_count()` to get the number of workers, while
88
+ # `mkl_fft.interfaces.scipy_fft` uses `mkl.get_max_threads()`
84
89
85
90
# default value is max number of threads unlike stock SciPy
86
- assert fft .get_workers () == cpus
91
+ assert fft .get_workers () == threads
87
92
with fft .set_workers (4 ):
88
93
assert fft .get_workers () == 4
89
94
90
95
with fft .set_workers (- 1 ):
91
- assert fft .get_workers () == cpus
96
+ assert fft .get_workers () == threads
92
97
93
98
assert fft .get_workers () == 4
94
99
95
100
# default value is max number of threads unlike stock SciPy
96
- assert fft .get_workers () == cpus
101
+ assert fft .get_workers () == threads
97
102
98
- with fft .set_workers (- cpus ):
103
+ with fft .set_workers (- threads ):
99
104
assert fft .get_workers () == 1
100
105
101
106
You can’t perform that action at this time.
0 commit comments