From e76235fafcfac343d65df36b15eb12d594d532d3 Mon Sep 17 00:00:00 2001 From: Kilvny <108346469+Kilvny@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:10:50 +0300 Subject: [PATCH 1/5] feat: implement rfftn to Paddle Frontend (#23484) --- ivy/functional/frontends/paddle/fft.py | 26 ++++++++++ .../test_frontends/test_paddle/test_fft.py | 49 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index 91b0f243feed8..813fa31f81232 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -152,3 +152,29 @@ def rfftfreq(n, d=1.0, dtype=None, name=None): pos_max = n // 2 + 1 indices = ivy.arange(0, pos_max, dtype=dtype) return indices * val + + +@with_supported_dtypes( + {"2.5.1 and below": ("complex64", "complex128")}, + "paddle", +) +@to_ivy_arrays_and_back +def rfftn(x, s=None, axes=None, norm="backward", name=None): + """Compute the N-dimensional discrete Fourier Transform over any number of axes in + an M-dimensional real array by means of the Fast Fourier Transform (FFT).""" + if s is None: + s = x.shape + + # Apply rfft along the last axis + rfft_result = ivy.rfftn(x, s=s, axes=axes, norm=norm, out=name) + + if axes is None: + # If axes is not specified, transform all axes except the last one. + axes = tuple(range(x.ndim - 1)) + + # Apply fft on the specified axes for N-dimensional FFT + fftn_result = rfft_result + for axis in axes: + fftn_result = ivy.fft(fftn_result, axis=axis, norm=norm) + + return fftn_result 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 e5a37ba5c904e..3cf67e5580d51 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 @@ -285,3 +285,52 @@ def test_paddle_rfftfreq( n=n, d=d, ) + + +@handle_frontend_test( + fn_tree="paddle.fft.rfftn", + dtype_x_axis=helpers.dtype_values_axis( + available_dtypes=helpers.get_dtypes("valid"), + min_value=-10, + max_value=10, + min_num_dims=1, + valid_axis=True, + force_int_axis=True, + ), + s=st.one_of( + st.tuples( + st.integers(min_value=2, max_value=10), + st.integers(min_value=2, max_value=10), + ), + st.just(None), + ), + axes=st.one_of( + st.lists( + st.integers(min_value=0, max_value=2), min_size=1, max_size=3, unique=True + ), + st.just(None), + ), + norm=st.sampled_from(["backward", "ortho", "forward"]), +) +def test_paddle_rfftn( + dtype_x_axis, + s, + axes, + norm, + frontend, + backend_fw, + test_flags, + fn_tree, +): + input_dtypes, x, axis = dtype_x_axis + helpers.test_frontend_function( + input_dtypes=input_dtypes, + backend_to_test=backend_fw, + frontend=frontend, + test_flags=test_flags, + fn_tree=fn_tree, + x=x[0], + s=s, + axes=axes, + norm=norm, + ) From f1ce57128a5b9a294e1916ebe485db567dbf3f35 Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Sun, 26 Nov 2023 13:29:05 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 80b2748704f38..b63b448588c72 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 @@ -568,7 +568,6 @@ def test_paddle_rfftfreq( ) - @handle_frontend_test( fn_tree="paddle.fft.rfftn", dtype_x_axis=helpers.dtype_values_axis( @@ -617,6 +616,7 @@ def test_paddle_rfftn( norm=norm, ) + # Use the custom strategy for s and axes axes_strategy = sequence_of_two_integers() s_strategy = sequence_of_two_integers() From 4f34c79af61a17c6fa7fefdb99a20237170d9325 Mon Sep 17 00:00:00 2001 From: Kilvny <108346469+Kilvny@users.noreply.github.com> Date: Sun, 26 Nov 2023 16:09:55 +0200 Subject: [PATCH 3/5] feat: implement rfftn to Paddle Frontend (#23484) (Update fft.py) --- ivy/functional/frontends/paddle/fft.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index d35bf3833cc4b..c6da5911e0b20 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -340,7 +340,14 @@ def rfftfreq(n, d=1.0, dtype=None, name=None): @with_supported_dtypes( - {"2.5.1 and below": ("complex64", "complex128")}, + { + "2.5.2 and below": ( + "int32", + "int64", + "float32", + "float64", + ) + }, "paddle", ) @to_ivy_arrays_and_back From 1e6c9a3209a2a4bde0b28a695e985e2401c72359 Mon Sep 17 00:00:00 2001 From: NripeshN Date: Mon, 4 Dec 2023 12:51:04 +0400 Subject: [PATCH 4/5] Refactor rfftn function in Paddle frontend --- ivy/functional/frontends/paddle/fft.py | 18 +------- .../test_frontends/test_paddle/test_fft.py | 43 ++++--------------- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index 52a80fb557543..c25b9d9a3aed3 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -374,19 +374,5 @@ def rfftfreq(n, d=1.0, dtype=None, name=None): def rfftn(x, s=None, axes=None, norm="backward", name=None): """Compute the N-dimensional discrete Fourier Transform over any number of axes in an M-dimensional real array by means of the Fast Fourier Transform (FFT).""" - if s is None: - s = x.shape - - # Apply rfft along the last axis - rfft_result = ivy.rfftn(x, s=s, axes=axes, norm=norm, out=name) - - if axes is None: - # If axes is not specified, transform all axes except the last one. - axes = tuple(range(x.ndim - 1)) - - # Apply fft on the specified axes for N-dimensional FFT - fftn_result = rfft_result - for axis in axes: - fftn_result = ivy.fft(fftn_result, axis=axis, norm=norm) - - return fftn_result + x = ivy.asarray(x, dtype=ivy.complex128) + return ivy.rfftn(x, s=s, axes=axes, norm=norm) 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 18500cca0e479..f509e2a803327 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 @@ -6,6 +6,7 @@ from ivy_tests.test_ivy.helpers import handle_frontend_test from ivy_tests.test_ivy.test_functional.test_experimental.test_nn.test_layers import ( _x_and_ifftn, + _x_and_rfftn, ) @@ -614,47 +615,19 @@ def test_paddle_rfftfreq( @handle_frontend_test( fn_tree="paddle.fft.rfftn", - dtype_x_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("valid"), - min_value=-10, - max_value=10, - min_num_dims=1, - valid_axis=True, - force_int_axis=True, - ), - s=st.one_of( - st.tuples( - st.integers(min_value=2, max_value=10), - st.integers(min_value=2, max_value=10), - ), - st.just(None), - ), - axes=st.one_of( - st.lists( - st.integers(min_value=0, max_value=2), min_size=1, max_size=3, unique=True - ), - st.just(None), - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), + dtype_and_x=_x_and_rfftn(), ) -def test_paddle_rfftn( - dtype_x_axis, - s, - axes, - norm, - frontend, - backend_fw, - test_flags, - fn_tree, -): - input_dtypes, x, axis = dtype_x_axis +def test_paddle_rfftn(dtype_and_x, frontend, backend_fw, test_flags, fn_tree, on_device): + dtype, x, s, axes, norm = dtype_and_x helpers.test_frontend_function( - input_dtypes=input_dtypes, + input_dtypes=dtype, backend_to_test=backend_fw, frontend=frontend, test_flags=test_flags, fn_tree=fn_tree, - x=x[0], + on_device=on_device, + test_values=True, + x=x, s=s, axes=axes, norm=norm, From c5d41269a7baa9b1950f596846ccab9ffd32c1a5 Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Mon, 4 Dec 2023 08:52:04 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 f509e2a803327..ba54bb0ac3c01 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 @@ -617,7 +617,9 @@ def test_paddle_rfftfreq( fn_tree="paddle.fft.rfftn", dtype_and_x=_x_and_rfftn(), ) -def test_paddle_rfftn(dtype_and_x, frontend, backend_fw, test_flags, fn_tree, on_device): +def test_paddle_rfftn( + dtype_and_x, frontend, backend_fw, test_flags, fn_tree, on_device +): dtype, x, s, axes, norm = dtype_and_x helpers.test_frontend_function( input_dtypes=dtype,