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

feat: added fft2 #23638

Closed
wants to merge 9 commits into from
Closed
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
29 changes: 29 additions & 0 deletions ivy/functional/frontends/paddle/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ 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": ("complex64", "complex128")},
"paddle",
)
@to_ivy_arrays_and_back
def fft2(x, s=None, axes=(-2, -1), norm="backward", name=None):
# Check if s is provided
if s is not None:
# If s is provided, zero-pad the input tensor x along the specified axes
for ax, length in zip(axes, s):
x = ivy.pad(
x,
[
(0, max(0, length - x.shape[ax])) if i == ax else (0, 0)
for i in range(x.ndim)
],
)

# Apply FFT along the first axis
fft_first_axis = fft(x, n=s[0] if s else None, axis=axes[0], norm=norm)

# Apply FFT along the second axis
fft_second_axis = fft(
fft_first_axis, n=s[1] if s else None, axis=axes[1], norm=norm
)

return fft_second_axis


@with_supported_dtypes(
{
"2.5.1 and below": (
Expand Down
42 changes: 42 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,48 @@ def test_paddle_fft(
)


@handle_frontend_test(
fn_tree="paddle.fft.fft2",
dtype_x_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("valid"),
min_value=-10,
max_value=10,
min_num_dims=2, # Since fft2 is for 2D FFT
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),
),
norm=st.sampled_from(["backward", "ortho", "forward"]),
)
def test_paddle_fft2(
dtype_x_axis,
s,
norm,
frontend,
backend_fw,
test_flags,
fn_tree,
):
input_dtypes, x, axes = 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,
)


@handle_frontend_test(
fn_tree="paddle.fft.fftshift",
dtype_x_axis=helpers.dtype_values_axis(
Expand Down
Loading