Skip to content

Commit c0004cc

Browse files
Removed missing functions from __all__ in _scipy_fft_backend
1 parent 015aab9 commit c0004cc

File tree

4 files changed

+98
-21
lines changed

4 files changed

+98
-21
lines changed

mkl_fft/_scipy_fft_backend.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
from . import _float_utils
2929
import mkl
3030

31-
from numpy.core import (array, asarray, shape, conjugate, take, sqrt, prod)
32-
from os import cpu_count as os_cpu_count
33-
import warnings
31+
from numpy.core import (take, sqrt, prod)
32+
import contextvars
33+
import operator
3434

3535

3636
__doc__ = """
@@ -64,15 +64,44 @@ def get_max_threads_count(self):
6464
return self.max_threads_count
6565

6666

67-
_hardware_counts = _cpu_max_threads_count()
67+
class _workers_data:
68+
def __init__(self, workers=None):
69+
if workers:
70+
self.workers_ = workers
71+
else:
72+
self.workers_ = _cpu_max_threads_count().get_cpu_count()
73+
self.workers_ = operator.index(self.workers_)
74+
75+
@property
76+
def workers(self):
77+
return self.workers_
78+
79+
@workers.setter
80+
def workers(self, workers_val):
81+
self.workerks_ = operator.index(workers_val)
82+
83+
84+
_workers_global_settings = contextvars.ContextVar('scipy_backend_workers', default=_workers_data())
85+
86+
87+
def get_workers():
88+
"Gets the number of workers used by mkl_fft by default"
89+
return _workers_global_settings.get().workers
90+
91+
92+
def set_workers(n_workers):
93+
"Set the value of workers used by default, returns the previous value"
94+
nw = operator.index(n_workers)
95+
wd = _workers_global_settings.get()
96+
saved_nw = wd.workers
97+
wd.workers = nw
98+
_workers_global_settings.set(wd)
99+
return saved_nw
68100

69101

70102
__all__ = ['fft', 'ifft', 'fft2', 'ifft2', 'fftn', 'ifftn',
71103
'rfft', 'irfft', 'rfft2', 'irfft2', 'rfftn', 'irfftn',
72-
'hfft', 'ihfft', 'hfft2', 'ihfft2', 'hfftn', 'ihfftn',
73-
'dct', 'idct', 'dst', 'idst', 'dctn', 'idctn', 'dstn', 'idstn',
74-
'fftshift', 'ifftshift', 'fftfreq', 'rfftfreq', 'get_workers',
75-
'set_workers', 'next_fast_len', 'DftiBackend']
104+
'get_workers', 'set_workers', 'DftiBackend']
76105

77106
__ua_domain__ = "numpy.scipy.fft"
78107

@@ -114,27 +143,21 @@ def _cook_nd_args(a, s=None, axes=None, invreal=0):
114143
return s, axes
115144

116145

117-
def _tot_size(x, axes):
118-
s = x.shape
119-
if axes is None:
120-
return x.size
121-
return prod([s[ai] for ai in axes])
122-
123-
124146
def _workers_to_num_threads(w):
125147
"""Handle conversion of workers to a positive number of threads in the
126148
same way as scipy.fft.helpers._workers.
127149
"""
128150
if w is None:
129-
return _hardware_counts.get_cpu_count()
130-
_w = int(w)
151+
return _workers_global_settings.get().workers
152+
_w = operator.index(w)
131153
if (_w == 0):
132154
raise ValueError("Number of workers must be nonzero")
133155
if (_w < 0):
134-
_w += _hardware_counts.get_cpu_count() + 1
156+
ub = _cpu_max_threads_count().get_cpu_count()
157+
_w += ub + 1
135158
if _w <= 0:
136159
raise ValueError("workers value out of range; got {}, must not be"
137-
" less than {}".format(w, -_hardware_counts.get_cpu_count()))
160+
" less than {}".format(w, -ub))
138161
return _w
139162

140163

mkl_fft/interfaces/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2424
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

26-
from .. import _numpy_fft as numpy_fft
27-
from .. import _scipy_fft_backend as scipy_fft
26+
from . import numpy_fft
27+
from . import scipy_fft

mkl_fft/interfaces/numpy_fft.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2017-2023, Intel Corporation
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of Intel Corporation nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
from .._numpy_fft import *

mkl_fft/interfaces/scipy_fft.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2017-2023, Intel Corporation
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of Intel Corporation nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
from .._scipy_fft_backend import *

0 commit comments

Comments
 (0)