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

Add fftshift to Paddle Frontend #18287

Merged
merged 1 commit into from
Jul 6, 2023
Merged
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
30 changes: 30 additions & 0 deletions ivy/functional/frontends/paddle/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@
def fft(x, n=None, axis=-1.0, norm="backward", name=None):
ret = ivy.fft(ivy.astype(x, "complex128"), axis, norm=norm, n=n)
return ivy.astype(ret, x.dtype)


@with_supported_dtypes(
{
"2.5.0 and below": (
"int32",
"int64",
"float32",
"float64",
"complex64",
"complex128",
)
},
"paddle",
)
@to_ivy_arrays_and_back
def fftshift(x, axes=None, name=None):
shape = x.shape

if axes is None:
axes = tuple(range(x.ndim))
shifts = [(dim // 2) for dim in shape]
elif isinstance(axes, int):
shifts = shape[axes] // 2
else:
shifts = ivy.concat([shape[ax] // 2 for ax in axes])

roll = ivy.roll(x, shifts, axis=axes)

return roll
25 changes: 25 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_paddle_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,28 @@ def test_paddle_fft(
axis=axis,
norm=norm,
)


@handle_frontend_test(
fn_tree="paddle.fft.fftshift",
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,
),
)
def test_paddle_fttshift(dtype_x_axis, frontend, test_flags, fn_tree, on_device):
input_dtype, x, axes = dtype_x_axis
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
test_values=True,
x=x[0],
axes=axes,
)