Skip to content

Commit

Permalink
Removed missing functions from __all__ in _scipy_fft_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-pavlyk committed Mar 9, 2023
1 parent 015aab9 commit c0004cc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 21 deletions.
61 changes: 42 additions & 19 deletions mkl_fft/_scipy_fft_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from . import _float_utils
import mkl

from numpy.core import (array, asarray, shape, conjugate, take, sqrt, prod)
from os import cpu_count as os_cpu_count
import warnings
from numpy.core import (take, sqrt, prod)
import contextvars
import operator


__doc__ = """
Expand Down Expand Up @@ -64,15 +64,44 @@ def get_max_threads_count(self):
return self.max_threads_count


_hardware_counts = _cpu_max_threads_count()
class _workers_data:
def __init__(self, workers=None):
if workers:
self.workers_ = workers
else:
self.workers_ = _cpu_max_threads_count().get_cpu_count()
self.workers_ = operator.index(self.workers_)

@property
def workers(self):
return self.workers_

@workers.setter
def workers(self, workers_val):
self.workerks_ = operator.index(workers_val)


_workers_global_settings = contextvars.ContextVar('scipy_backend_workers', default=_workers_data())


def get_workers():
"Gets the number of workers used by mkl_fft by default"
return _workers_global_settings.get().workers


def set_workers(n_workers):
"Set the value of workers used by default, returns the previous value"
nw = operator.index(n_workers)
wd = _workers_global_settings.get()
saved_nw = wd.workers
wd.workers = nw
_workers_global_settings.set(wd)
return saved_nw


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

__ua_domain__ = "numpy.scipy.fft"

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


def _tot_size(x, axes):
s = x.shape
if axes is None:
return x.size
return prod([s[ai] for ai in axes])


def _workers_to_num_threads(w):
"""Handle conversion of workers to a positive number of threads in the
same way as scipy.fft.helpers._workers.
"""
if w is None:
return _hardware_counts.get_cpu_count()
_w = int(w)
return _workers_global_settings.get().workers
_w = operator.index(w)
if (_w == 0):
raise ValueError("Number of workers must be nonzero")
if (_w < 0):
_w += _hardware_counts.get_cpu_count() + 1
ub = _cpu_max_threads_count().get_cpu_count()
_w += ub + 1
if _w <= 0:
raise ValueError("workers value out of range; got {}, must not be"
" less than {}".format(w, -_hardware_counts.get_cpu_count()))
" less than {}".format(w, -ub))
return _w


Expand Down
4 changes: 2 additions & 2 deletions mkl_fft/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

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

from .._scipy_fft_backend import *

0 comments on commit c0004cc

Please sign in to comment.