Skip to content

Commit 59be03d

Browse files
authored
Enable pre-commit pylint check in fft module (#1860)
1 parent 410cb1b commit 59be03d

File tree

3 files changed

+82
-18
lines changed

3 files changed

+82
-18
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ repos:
100100
"--disable=redefined-builtin",
101101
"--disable=unused-wildcard-import"
102102
]
103-
files: '^dpnp/(dpnp_iface.*|linalg)'
103+
files: '^dpnp/(dpnp_iface.*|fft|linalg)'

dpnp/fft/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@
2424
# THE POSSIBILITY OF SUCH DAMAGE.
2525
# *****************************************************************************
2626

27+
"""
28+
``dpnp.fft``
29+
===========================
30+
Discrete Fourier Transform.
31+
32+
Fourier analysis is fundamentally a method for expressing a function as a sum
33+
of periodic components, and for recovering the function from those components.
34+
When both the function and its Fourier transform are replaced with discretized
35+
counterparts, it is called the discrete Fourier transform (DFT). The DFT has
36+
become a mainstay of numerical computing in part because of a very fast
37+
algorithm for computing it, called the Fast Fourier Transform (FFT), which was
38+
known to Gauss (1805) and was brought to light in its current form by Cooley
39+
and Tukey.
40+
41+
Because the discrete Fourier transform separates its input into components
42+
that contribute at discrete frequencies, it has a great number of applications
43+
in digital signal processing, e.g., for filtering, and in this context the
44+
discretized input to the transform is customarily referred to as a *signal*,
45+
which exists in the *time domain*. The output is called a *spectrum* or
46+
*transform* and exists in the *frequency domain*.
47+
48+
"""
49+
2750
from dpnp.fft.dpnp_iface_fft import *
2851
from dpnp.fft.dpnp_iface_fft import __all__ as __all__fft
2952

dpnp/fft/dpnp_iface_fft.py

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,23 @@
3939
4040
"""
4141

42+
# pylint: disable=invalid-name
4243

4344
from enum import Enum
4445

4546
import numpy
4647

4748
import dpnp
48-
from dpnp.dpnp_utils import *
49-
from dpnp.fft.dpnp_algo_fft import *
49+
50+
# pylint: disable=no-name-in-module
51+
from dpnp.dpnp_utils import (
52+
call_origin,
53+
checker_throw_axis_error,
54+
)
55+
from dpnp.fft.dpnp_algo_fft import (
56+
dpnp_fft,
57+
dpnp_rfft,
58+
)
5059

5160
__all__ = [
5261
"fft",
@@ -70,12 +79,16 @@
7079
]
7180

7281

82+
# TODO: remove pylint disable, once new implementation is ready
83+
# pylint: disable=missing-class-docstring
7384
class Norm(Enum):
7485
backward = 0
7586
forward = 1
7687
ortho = 2
7788

7889

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

105120
x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
@@ -205,12 +220,12 @@ def fftn(x, s=None, axes=None, norm=None):
205220
x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
206221
if x_desc:
207222
if s is None:
208-
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
223+
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
209224
else:
210225
boundaries = s
211226

212227
if axes is None:
213-
axes_param = tuple([i for i in range(x_desc.ndim)])
228+
axes_param = list(range(x_desc.ndim))
214229
else:
215230
axes_param = axes
216231

@@ -256,6 +271,8 @@ def fftshift(x, axes=None):
256271
"""
257272

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

@@ -267,6 +284,9 @@ def fftshift(x, axes=None):
267284
if x_desc.size < 1:
268285
pass # let fallback to handle exception
269286
else:
287+
input_boundarie = x_desc.shape[axis_param]
288+
output_boundarie = input_boundarie
289+
270290
return dpnp_fft(
271291
x_desc,
272292
input_boundarie,
@@ -281,7 +301,8 @@ def fftshift(x, axes=None):
281301

282302
def hfft(x, n=None, axis=-1, norm=None):
283303
"""
284-
Compute the one-dimensional discrete Fourier Transform of a signal that has Hermitian symmetry.
304+
Compute the one-dimensional discrete Fourier Transform of a signal that has
305+
Hermitian symmetry.
285306
286307
For full documentation refer to :obj:`numpy.fft.hfft`.
287308
@@ -296,6 +317,8 @@ def hfft(x, n=None, axis=-1, norm=None):
296317
"""
297318

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

@@ -342,7 +365,8 @@ def ifft(x, n=None, axis=-1, norm=None):
342365
Parameter `axis` is supported with its default value.
343366
Only `dpnp.float64`, `dpnp.float32`, `dpnp.int64`, `dpnp.int32`,,
344367
`dpnp.complex128`, `dpnp.complex64` data types are supported.
345-
The `dpnp.bool` data type is not supported and will raise a `TypeError` exception.
368+
The `dpnp.bool` data type is not supported and will raise a `TypeError`
369+
exception.
346370
Otherwise the function will be executed sequentially on CPU.
347371
348372
"""
@@ -430,6 +454,8 @@ def ifftshift(x, axes=None):
430454
"""
431455

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

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

480506
x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
507+
# TODO: enable implementation
508+
# pylint: disable=condition-evals-to-constant
481509
if x_desc and 0:
482510
if s is None:
483-
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
511+
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
484512
else:
485513
boundaries = s
486514

487515
if axes is None:
488-
axes_param = tuple([i for i in range(x_desc.ndim)])
516+
axes_param = list(range(x_desc.ndim))
489517
else:
490518
axes_param = axes
491519

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

523551
def ihfft(x, n=None, axis=-1, norm=None):
524552
"""
525-
Compute inverse one-dimensional discrete Fourier Transform of a signal that has Hermitian symmetry.
553+
Compute inverse one-dimensional discrete Fourier Transform of a signal that
554+
has Hermitian symmetry.
526555
527556
For full documentation refer to :obj:`numpy.fft.ihfft`.
528557
@@ -537,6 +566,8 @@ def ihfft(x, n=None, axis=-1, norm=None):
537566
"""
538567

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

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

576607
def irfft(x, n=None, axis=-1, norm=None):
577608
"""
578-
Compute the one-dimensional inverse discrete Fourier Transform for real input.
609+
Compute the one-dimensional inverse discrete Fourier Transform for real
610+
input.
579611
580612
For full documentation refer to :obj:`numpy.fft.irfft`.
581613
@@ -590,6 +622,8 @@ def irfft(x, n=None, axis=-1, norm=None):
590622
"""
591623

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

@@ -622,7 +656,8 @@ def irfft(x, n=None, axis=-1, norm=None):
622656
True,
623657
norm_.value,
624658
).get_pyobj()
625-
# TODO tmp = utils.create_output_array(result_shape, result_c_type, out)
659+
# TODO:
660+
# tmp = utils.create_output_array(result_shape, result_c_type, out)
626661
# tmp = dparray(result.shape, dtype=dpnp.float64)
627662
# for it in range(tmp.size):
628663
# tmp[it] = result[it].real
@@ -678,14 +713,16 @@ def irfftn(x, s=None, axes=None, norm=None):
678713
"""
679714

680715
x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
716+
# TODO: enable implementation
717+
# pylint: disable=condition-evals-to-constant
681718
if x_desc and 0:
682719
if s is None:
683-
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
720+
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
684721
else:
685722
boundaries = s
686723

687724
if axes is None:
688-
axes_param = tuple([i for i in range(x_desc.ndim)])
725+
axes_param = list(range(x_desc.ndim))
689726
else:
690727
axes_param = axes
691728

@@ -732,8 +769,10 @@ def rfft(x, n=None, axis=-1, norm=None):
732769
Parameter `norm` is unsupported.
733770
Only `dpnp.float64`, `dpnp.float32`, `dpnp.int64`, `dpnp.int32`,
734771
`dpnp.complex128` data types are supported.
735-
The `dpnp.bool` data type is not supported and will raise a `TypeError` exception.
772+
The `dpnp.bool` data type is not supported and will raise a `TypeError`
773+
exception.
736774
Otherwise the function will be executed sequentially on CPU.
775+
737776
"""
738777

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

846885
x_desc = dpnp.get_dpnp_descriptor(x, copy_when_nondefault_queue=False)
886+
# TODO: enable implementation
887+
# pylint: disable=condition-evals-to-constant
847888
if x_desc and 0:
848889
if s is None:
849-
boundaries = tuple([x_desc.shape[i] for i in range(x_desc.ndim)])
890+
boundaries = tuple(x_desc.shape[i] for i in range(x_desc.ndim))
850891
else:
851892
boundaries = s
852893

853894
if axes is None:
854-
axes_param = tuple([i for i in range(x_desc.ndim)])
895+
axes_param = list(range(x_desc.ndim))
855896
else:
856897
axes_param = axes
857898

0 commit comments

Comments
 (0)