Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pre-commit pylint check in fft module #1860

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ repos:
"--disable=redefined-builtin",
"--disable=unused-wildcard-import"
]
files: '^dpnp/(dpnp_iface.*|linalg)'
files: '^dpnp/(dpnp_iface.*|fft|linalg)'
23 changes: 23 additions & 0 deletions dpnp/fft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

"""
``dpnp.fft``
===========================
Discrete Fourier Transform.

Fourier analysis is fundamentally a method for expressing a function as a sum
of periodic components, and for recovering the function from those components.
When both the function and its Fourier transform are replaced with discretized
counterparts, it is called the discrete Fourier transform (DFT). The DFT has
become a mainstay of numerical computing in part because of a very fast
algorithm for computing it, called the Fast Fourier Transform (FFT), which was
known to Gauss (1805) and was brought to light in its current form by Cooley
and Tukey.

Because the discrete Fourier transform separates its input into components
that contribute at discrete frequencies, it has a great number of applications
in digital signal processing, e.g., for filtering, and in this context the
discretized input to the transform is customarily referred to as a *signal*,
which exists in the *time domain*. The output is called a *spectrum* or
*transform* and exists in the *frequency domain*.

"""

from dpnp.fft.dpnp_iface_fft import *
from dpnp.fft.dpnp_iface_fft import __all__ as __all__fft

Expand Down
75 changes: 58 additions & 17 deletions dpnp/fft/dpnp_iface_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@

"""

# pylint: disable=invalid-name

from enum import Enum

import numpy

import dpnp
from dpnp.dpnp_utils import *
from dpnp.fft.dpnp_algo_fft import *

# pylint: disable=no-name-in-module
from dpnp.dpnp_utils import (
call_origin,
checker_throw_axis_error,
)
from dpnp.fft.dpnp_algo_fft import (
dpnp_fft,
dpnp_rfft,
)

__all__ = [
"fft",
Expand All @@ -70,12 +79,16 @@
]


# TODO: remove pylint disable, once new implementation is ready
# pylint: disable=missing-class-docstring
class Norm(Enum):
backward = 0
forward = 1
ortho = 2


# TODO: remove pylint disable, once new implementation is ready
# pylint: disable=missing-function-docstring
def get_validated_norm(norm):
if norm is None or norm == "backward":
return Norm.backward
Expand All @@ -98,8 +111,10 @@ def fft(x, n=None, axis=-1, norm=None):
Parameter `axis` is supported with its default value.
Only `dpnp.float64`, `dpnp.float32`, `dpnp.int64`, `dpnp.int32`,
`dpnp.complex128`, `dpnp.complex64` data types are supported.
The `dpnp.bool` data type is not supported and will raise a `TypeError` exception.
The `dpnp.bool` data type is not supported and will raise a `TypeError`
exception.
Otherwise the function will be executed sequentially on CPU.

"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
Expand Down Expand Up @@ -205,12 +220,12 @@ def fftn(x, s=None, axes=None, norm=None):
x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
if x_desc:
if s is None:
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
else:
boundaries = s

if axes is None:
axes_param = tuple([i for i in range(x_desc.ndim)])
axes_param = list(range(x_desc.ndim))
else:
axes_param = axes

Expand Down Expand Up @@ -256,6 +271,8 @@ def fftshift(x, axes=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
norm_ = Norm.backward

Expand All @@ -267,6 +284,9 @@ def fftshift(x, axes=None):
if x_desc.size < 1:
pass # let fallback to handle exception
else:
input_boundarie = x_desc.shape[axis_param]
output_boundarie = input_boundarie

return dpnp_fft(
x_desc,
input_boundarie,
Expand All @@ -281,7 +301,8 @@ def fftshift(x, axes=None):

def hfft(x, n=None, axis=-1, norm=None):
"""
Compute the one-dimensional discrete Fourier Transform of a signal that has Hermitian symmetry.
Compute the one-dimensional discrete Fourier Transform of a signal that has
Hermitian symmetry.

For full documentation refer to :obj:`numpy.fft.hfft`.

Expand All @@ -296,6 +317,8 @@ def hfft(x, n=None, axis=-1, norm=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
norm_ = get_validated_norm(norm)

Expand Down Expand Up @@ -342,7 +365,8 @@ def ifft(x, n=None, axis=-1, norm=None):
Parameter `axis` is supported with its default value.
Only `dpnp.float64`, `dpnp.float32`, `dpnp.int64`, `dpnp.int32`,,
`dpnp.complex128`, `dpnp.complex64` data types are supported.
The `dpnp.bool` data type is not supported and will raise a `TypeError` exception.
The `dpnp.bool` data type is not supported and will raise a `TypeError`
exception.
Otherwise the function will be executed sequentially on CPU.

"""
Expand Down Expand Up @@ -430,6 +454,8 @@ def ifftshift(x, axes=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
norm_ = Norm.backward

Expand Down Expand Up @@ -478,14 +504,16 @@ def ifftn(x, s=None, axes=None, norm=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
if s is None:
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
else:
boundaries = s

if axes is None:
axes_param = tuple([i for i in range(x_desc.ndim)])
axes_param = list(range(x_desc.ndim))
else:
axes_param = axes

Expand Down Expand Up @@ -522,7 +550,8 @@ def ifftn(x, s=None, axes=None, norm=None):

def ihfft(x, n=None, axis=-1, norm=None):
"""
Compute inverse one-dimensional discrete Fourier Transform of a signal that has Hermitian symmetry.
Compute inverse one-dimensional discrete Fourier Transform of a signal that
has Hermitian symmetry.

For full documentation refer to :obj:`numpy.fft.ihfft`.

Expand All @@ -537,6 +566,8 @@ def ihfft(x, n=None, axis=-1, norm=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
norm_ = get_validated_norm(norm)

Expand Down Expand Up @@ -575,7 +606,8 @@ def ihfft(x, n=None, axis=-1, norm=None):

def irfft(x, n=None, axis=-1, norm=None):
"""
Compute the one-dimensional inverse discrete Fourier Transform for real input.
Compute the one-dimensional inverse discrete Fourier Transform for real
input.

For full documentation refer to :obj:`numpy.fft.irfft`.

Expand All @@ -590,6 +622,8 @@ def irfft(x, n=None, axis=-1, norm=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
norm_ = get_validated_norm(norm)

Expand Down Expand Up @@ -622,7 +656,8 @@ def irfft(x, n=None, axis=-1, norm=None):
True,
norm_.value,
).get_pyobj()
# TODO tmp = utils.create_output_array(result_shape, result_c_type, out)
# TODO:
# tmp = utils.create_output_array(result_shape, result_c_type, out)
# tmp = dparray(result.shape, dtype=dpnp.float64)
# for it in range(tmp.size):
# tmp[it] = result[it].real
Expand Down Expand Up @@ -678,14 +713,16 @@ def irfftn(x, s=None, axes=None, norm=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
if s is None:
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
else:
boundaries = s

if axes is None:
axes_param = tuple([i for i in range(x_desc.ndim)])
axes_param = list(range(x_desc.ndim))
else:
axes_param = axes

Expand Down Expand Up @@ -732,8 +769,10 @@ def rfft(x, n=None, axis=-1, norm=None):
Parameter `norm` is unsupported.
Only `dpnp.float64`, `dpnp.float32`, `dpnp.int64`, `dpnp.int32`,
`dpnp.complex128` data types are supported.
The `dpnp.bool` data type is not supported and will raise a `TypeError` exception.
The `dpnp.bool` data type is not supported and will raise a `TypeError`
exception.
Otherwise the function will be executed sequentially on CPU.

"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
Expand Down Expand Up @@ -844,14 +883,16 @@ def rfftn(x, s=None, axes=None, norm=None):
"""

x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
# TODO: enable implementation
# pylint: disable=condition-evals-to-constant
if x_desc and 0:
if s is None:
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
else:
boundaries = s

if axes is None:
axes_param = tuple([i for i in range(x_desc.ndim)])
axes_param = list(range(x_desc.ndim))
else:
axes_param = axes

Expand Down
Loading