From e9c338c115843f77db49ff985c60aad281d22fd9 Mon Sep 17 00:00:00 2001 From: p1utoze <1ds21ai001@dsce.edu.in> Date: Sun, 3 Sep 2023 12:44:54 +0530 Subject: [PATCH 1/3] Added fftfreq() paddle frontend function in paddle.fft --- ivy/functional/frontends/paddle/fft.py | 24 +++++++++++++++ .../test_frontends/test_paddle/test_fft.py | 30 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index bd40f59060eb..6dcaa053a281 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -16,6 +16,30 @@ def fft(x, n=None, axis=-1.0, norm="backward", name=None): return ivy.astype(ret, x.dtype) +@with_supported_dtypes( + { + "2.5.1 and below": ( + "int32", + "int64", + "float32", + "float64", + ) + }, + "paddle", +) +@to_ivy_arrays_and_back +def fftfreq(n, d=1.0, dtype=None, name=None): + if d * n == 0: + raise ValueError("d or n should not be 0.") + + val = 1.0 / (n * d) + pos_max = (n + 1) // 2 + neg_max = n // 2 + indices = ivy.arange(-neg_max, pos_max, dtype=dtype) + indices = ivy.roll(indices, -neg_max) + return ivy.multiply(indices, val) + + @with_supported_dtypes( { "2.5.1 and below": ( diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py index e136ea66d720..24fa6dde556c 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py @@ -46,6 +46,36 @@ def test_paddle_fft( ) +@handle_frontend_test( + fn_tree="paddle.fft.fftfreq", + n=st.integers(min_value=2, max_value=100), + sample_space=st.integers(min_value=1, max_value=10), + dtypes=helpers.get_dtypes("integer"), +) +def test_paddle_fftfreq( + n, + sample_space, + dtypes, + frontend, + test_flags, + fn_tree, + on_device, + backend_fw, +): + d = 1 / sample_space + helpers.test_frontend_function( + input_dtypes=dtypes, + backend_to_test=backend_fw, + frontend=frontend, + test_flags=test_flags, + fn_tree=fn_tree, + on_device=on_device, + test_values=True, + n=n, + d=d, + ) + + @handle_frontend_test( fn_tree="paddle.fft.fftshift", dtype_x_axis=helpers.dtype_values_axis( From d0d1582f2b207b21387d237e649e9f7e5485e869 Mon Sep 17 00:00:00 2001 From: p1utoze <1ds21ai001@dsce.edu.in> Date: Thu, 14 Sep 2023 15:38:41 +0530 Subject: [PATCH 2/3] Update paddle.fftfreq function and passes tests cases --- ivy/functional/frontends/paddle/fft.py | 1 + .../test_ivy/test_frontends/test_paddle/test_fft.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index 7c35e502a5da..eca3ca9887c7 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -32,6 +32,7 @@ def fftfreq(n, d=1.0, dtype=None, name=None): if d * n == 0: raise ValueError("d or n should not be 0.") + dtype = ivy.default_dtype() val = 1.0 / (n * d) pos_max = (n + 1) // 2 neg_max = n // 2 diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py index 882ac8d91143..40c5249cefb0 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py @@ -48,13 +48,13 @@ def test_paddle_fft( @handle_frontend_test( fn_tree="paddle.fft.fftfreq", - n=st.integers(min_value=2, max_value=100), - sample_space=st.integers(min_value=1, max_value=10), - dtypes=helpers.get_dtypes("integer"), + n=st.integers(min_value=1, max_value=1000), + sample_rate=st.integers(min_value=1, max_value=20), + dtypes=helpers.get_dtypes("valid"), ) def test_paddle_fftfreq( n, - sample_space, + sample_rate, dtypes, frontend, test_flags, @@ -62,7 +62,7 @@ def test_paddle_fftfreq( on_device, backend_fw, ): - d = 1 / sample_space + d = 1 / sample_rate helpers.test_frontend_function( input_dtypes=dtypes, backend_to_test=backend_fw, From 2bb3d2b936c21d0dbe60e0844eb9578dfb96f887 Mon Sep 17 00:00:00 2001 From: p1utoze <1ds21ai001@dsce.edu.in> Date: Wed, 27 Sep 2023 08:40:35 +0530 Subject: [PATCH 3/3] Update paddle.fftfreq to check dtype --- ivy/functional/frontends/paddle/fft.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index 1c6c5b0e7773..0cad62e60db5 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -32,7 +32,8 @@ def fftfreq(n, d=1.0, dtype=None, name=None): if d * n == 0: raise ValueError("d or n should not be 0.") - dtype = ivy.default_dtype() + if dtype is None: + dtype = ivy.default_dtype() val = 1.0 / (n * d) pos_max = (n + 1) // 2 neg_max = n // 2