From e53b9270fd994d45ca2b9d407233c1b25466af94 Mon Sep 17 00:00:00 2001 From: AwkNinja <61329893+AwkNinja@users.noreply.github.com> Date: Thu, 27 Jul 2023 23:55:12 +0500 Subject: [PATCH 1/6] removed commented code --- ivy/functional/frontends/paddle/fft.py | 7 +++++ .../test_frontends/test_paddle/test_fft.py | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index ddf7eff9b6fbb..08a35f96d64da 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -100,3 +100,10 @@ def irfft(x, n=None, axis=-1.0, norm="backward", name=None): if ivy.isreal(x): time_domain = ivy.real(time_domain) return time_domain + + +@with_unsupported_dtypes({"2.5.0 and below": ("float16",)}, "paddle") +@to_ivy_arrays_and_back +def rfft(x, n=None, axis=-1, norm="backward", name=None): + ret = ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, norm=norm) + return ivy.astype(ret, ret.dtype) 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 98a1b26d91a73..54515cd16428d 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 @@ -187,3 +187,33 @@ def test_paddle_ifftshift( x=x[0], axes=axes, ) + + +# rfft +@handle_frontend_test( + fn_tree="paddle.fft.rfft", + dtype_input_axis=helpers.dtype_values_axis( + available_dtypes=helpers.get_dtypes("float"), + shape=(2,), + min_axis=-1, + force_int_axis=True, + ), + norm=st.sampled_from(["backward", "ortho", "forward"]), + n=st.integers(min_value=2, max_value=10), +) +def test_paddle_rfft( + dtype_input_axis, norm, n, frontend, backend_fw, test_flags, fn_tree, on_device +): + input_dtype, x, axis = dtype_input_axis + helpers.test_frontend_function( + input_dtypes=input_dtype, + frontend=frontend, + backend_to_test=backend_fw, + test_flags=test_flags, + fn_tree=fn_tree, + on_device=on_device, + x=x[0], + n=n, + axis=axis, + norm=norm, + ) From 0d47ad876db2f6a86305e5d4c1a8c45b1e712913 Mon Sep 17 00:00:00 2001 From: AwkNinja <61329893+AwkNinja@users.noreply.github.com> Date: Sat, 26 Aug 2023 12:10:25 +0500 Subject: [PATCH 2/6] added the case so `n` can also be `None` and refined the dtype and axis setup to accommodate valid data types, adjustable axis --- ivy/functional/frontends/paddle/fft.py | 2 +- .../test_frontends/test_paddle/test_fft.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index 08a35f96d64da..ec0f64ebce16c 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -102,7 +102,7 @@ def irfft(x, n=None, axis=-1.0, norm="backward", name=None): return time_domain -@with_unsupported_dtypes({"2.5.0 and below": ("float16",)}, "paddle") +@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") @to_ivy_arrays_and_back def rfft(x, n=None, axis=-1, norm="backward", name=None): ret = ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, 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 54515cd16428d..e29f61c1d427a 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 @@ -193,13 +193,19 @@ def test_paddle_ifftshift( @handle_frontend_test( fn_tree="paddle.fft.rfft", dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("float"), - shape=(2,), - min_axis=-1, + available_dtypes=helpers.get_dtypes("valid"), + min_num_dims=1, + min_dim_size=2, + shape=helpers.get_shape(min_num_dims=1, + max_num_dims=2, + min_dim_size=2, + max_dim_size=4,), force_int_axis=True, + valid_axis=True, + allow_neg_axes=True, ), norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=10), + n=st.integers(min_value=2, max_value=10) | st.none(), ) def test_paddle_rfft( dtype_input_axis, norm, n, frontend, backend_fw, test_flags, fn_tree, on_device From 0fea2c4f90df9fdcd51e68addb070c82e10a131d Mon Sep 17 00:00:00 2001 From: AwkNinja <61329893+AwkNinja@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:34:13 +0500 Subject: [PATCH 3/6] Fix lint --- .../test_ivy/test_frontends/test_paddle/test_fft.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 e29f61c1d427a..f555a2035b46a 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 @@ -196,10 +196,12 @@ def test_paddle_ifftshift( available_dtypes=helpers.get_dtypes("valid"), min_num_dims=1, min_dim_size=2, - shape=helpers.get_shape(min_num_dims=1, - max_num_dims=2, - min_dim_size=2, - max_dim_size=4,), + shape=helpers.get_shape( + min_num_dims=1, + max_num_dims=2, + min_dim_size=2, + max_dim_size=4, + ), force_int_axis=True, valid_axis=True, allow_neg_axes=True, From 4c30bc1162cb9f9b526a4db565f37270a4caa799 Mon Sep 17 00:00:00 2001 From: AwkNinja <61329893+AwkNinja@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:50:14 +0500 Subject: [PATCH 4/6] fix lint --- .../test_frontends/test_paddle/test_fft.py | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) 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 954340b9c9ebb..834f5998340a2 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 @@ -180,44 +180,6 @@ def test_paddle_ifftshift( ) -# rfft -@handle_frontend_test( - fn_tree="paddle.fft.rfft", - dtype_input_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("valid"), - min_num_dims=1, - min_dim_size=2, - shape=helpers.get_shape( - min_num_dims=1, - max_num_dims=2, - min_dim_size=2, - max_dim_size=4, - ), - force_int_axis=True, - valid_axis=True, - allow_neg_axes=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), - n=st.integers(min_value=2, max_value=10) | st.none(), -) -def test_paddle_rfft( - dtype_input_axis, norm, n, frontend, backend_fw, test_flags, fn_tree, on_device -): - input_dtype, x, axis = dtype_input_axis - helpers.test_frontend_function( - input_dtypes=input_dtype, - frontend=frontend, - backend_to_test=backend_fw, - test_flags=test_flags, - fn_tree=fn_tree, - on_device=on_device, - x=x[0], - n=n, - axis=axis, - norm=norm, - ) - - @handle_frontend_test( fn_tree="paddle.fft.irfft", dtype_x_axis=helpers.dtype_values_axis( @@ -258,3 +220,41 @@ def test_paddle_irfft( valid_axis=True, force_int_axis=True, ) + + +# rfft +@handle_frontend_test( + fn_tree="paddle.fft.rfft", + dtype_input_axis=helpers.dtype_values_axis( + available_dtypes=helpers.get_dtypes("valid"), + min_num_dims=1, + min_dim_size=2, + shape=helpers.get_shape( + min_num_dims=1, + max_num_dims=2, + min_dim_size=2, + max_dim_size=4, + ), + force_int_axis=True, + valid_axis=True, + allow_neg_axes=True, + ), + norm=st.sampled_from(["backward", "ortho", "forward"]), + n=st.integers(min_value=2, max_value=10) | st.none(), +) +def test_paddle_rfft( + dtype_input_axis, norm, n, frontend, backend_fw, test_flags, fn_tree, on_device +): + input_dtype, x, axis = dtype_input_axis + helpers.test_frontend_function( + input_dtypes=input_dtype, + frontend=frontend, + backend_to_test=backend_fw, + test_flags=test_flags, + fn_tree=fn_tree, + on_device=on_device, + x=x[0], + n=n, + axis=axis, + norm=norm, + ) From 463b0af5ec4f2cf68a5d2ddb85bd5f46f5526077 Mon Sep 17 00:00:00 2001 From: AwkNinja <61329893+AwkNinja@users.noreply.github.com> Date: Fri, 22 Sep 2023 23:41:14 +0500 Subject: [PATCH 5/6] added safety factor for `numpy` tests as they were failing sometimes due to slight value differences, added conversion from `float` to `complex` as `tensorflow` backend for `fft` doesn't support `float` --- .../tensorflow/experimental/layers.py | 9 ++- ivy/functional/frontends/paddle/fft.py | 13 ++-- .../test_frontends/test_paddle/test_fft.py | 77 ++++++++++--------- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/ivy/functional/backends/tensorflow/experimental/layers.py b/ivy/functional/backends/tensorflow/experimental/layers.py index bf8af1655a9da..ee63b80fd9a56 100644 --- a/ivy/functional/backends/tensorflow/experimental/layers.py +++ b/ivy/functional/backends/tensorflow/experimental/layers.py @@ -648,7 +648,9 @@ def _ifft_norm( raise ivy.utils.exceptions.IvyError(f"Unrecognized normalization mode {norm}") -@with_supported_dtypes({"2.13.0 and below": ("complex",)}, backend_version) +@with_supported_dtypes( + {"2.13.0 and below": ("complex", "float32", "float64")}, backend_version +) def fft( x: Union[tf.Tensor, tf.Variable], dim: int, @@ -658,6 +660,11 @@ def fft( n: Union[int, Tuple[int]] = None, out: Optional[Union[tf.Tensor, tf.Variable]] = None, ) -> Union[tf.Tensor, tf.Variable]: + # ToDo: Remove conversion from float to complex when casting mode is working + if x.dtype == "float32": + x = tf.cast(x, tf.complex64) + elif x.dtype == "float64": + x = tf.cast(x, tf.complex128) if not isinstance(dim, int): raise ivy.utils.exceptions.IvyError( f"Expecting instead of {type(dim)}" diff --git a/ivy/functional/frontends/paddle/fft.py b/ivy/functional/frontends/paddle/fft.py index a041e368dad26..727faee0591a3 100644 --- a/ivy/functional/frontends/paddle/fft.py +++ b/ivy/functional/frontends/paddle/fft.py @@ -145,13 +145,6 @@ def irfft(x, n=None, axis=-1.0, norm="backward", name=None): return time_domain -@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") -@to_ivy_arrays_and_back -def rfft(x, n=None, axis=-1, norm="backward", name=None): - ret = ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, norm=norm) - return ivy.astype(ret, ret.dtype) - - @with_supported_dtypes( {"2.5.1 and below": ("complex64", "complex128")}, "paddle", @@ -204,6 +197,12 @@ def irfftn(x, s=None, axes=None, norm="backward", name=None): return result_t +@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") +@to_ivy_arrays_and_back +def rfft(x, n=None, axis=-1, norm="backward", name=None): + return ivy.dft(x, axis=axis, inverse=False, onesided=True, dft_length=n, norm=norm) + + @to_ivy_arrays_and_back def rfftfreq(n, d=1.0, dtype=None, name=None): dtype = ivy.default_dtype() 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 9250c4f75ddc1..c66102da900d4 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 @@ -265,6 +265,43 @@ def test_paddle_irfft( ) +@handle_frontend_test( + fn_tree="paddle.fft.irfftn", + dtype_x_axis=helpers.dtype_values_axis( + available_dtypes=helpers.get_dtypes("complex"), + min_value=-10, + max_value=10, + min_num_dims=1, + max_num_dims=5, + min_dim_size=2, + max_dim_size=5, + valid_axis=True, + force_int_axis=True, + ), + norm=st.sampled_from(["backward", "ortho", "forward"]), +) +def test_paddle_irfftn( + dtype_x_axis, + norm, + frontend, + test_flags, + fn_tree, + backend_fw, +): + 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=None, + axes=None, + norm=norm, + ) + + # rfft @handle_frontend_test( fn_tree="paddle.fft.rfft", @@ -278,6 +315,9 @@ def test_paddle_irfft( min_dim_size=2, max_dim_size=4, ), + large_abs_safety_factor=10, + small_abs_safety_factor=10, + safety_factor_scale="log", force_int_axis=True, valid_axis=True, allow_neg_axes=True, @@ -302,43 +342,6 @@ def test_paddle_rfft( norm=norm, ) - -@handle_frontend_test( - fn_tree="paddle.fft.irfftn", - dtype_x_axis=helpers.dtype_values_axis( - available_dtypes=helpers.get_dtypes("complex"), - min_value=-10, - max_value=10, - min_num_dims=1, - max_num_dims=5, - min_dim_size=2, - max_dim_size=5, - valid_axis=True, - force_int_axis=True, - ), - norm=st.sampled_from(["backward", "ortho", "forward"]), -) -def test_paddle_irfftn( - dtype_x_axis, - norm, - frontend, - test_flags, - fn_tree, - backend_fw, -): - 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=None, - axes=None, - norm=norm, - ) - @handle_frontend_test( fn_tree="paddle.fft.rfftfreq", From 9abd870bfc347af57eb31d9a9f17c0e9272ca60c Mon Sep 17 00:00:00 2001 From: AwkNinja <61329893+AwkNinja@users.noreply.github.com> Date: Thu, 28 Sep 2023 09:13:07 +0500 Subject: [PATCH 6/6] updated safety factor --- ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e33090349b561..f4793b6908dca 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 @@ -367,8 +367,8 @@ def test_paddle_irfftn( min_dim_size=2, max_dim_size=4, ), - large_abs_safety_factor=10, - small_abs_safety_factor=10, + large_abs_safety_factor=12, + small_abs_safety_factor=12, safety_factor_scale="log", force_int_axis=True, valid_axis=True,