Skip to content

Commit

Permalink
Added fftfreq() paddle frontend function in paddle.fft
Browse files Browse the repository at this point in the history
  • Loading branch information
p1utoze committed Sep 3, 2023
1 parent 113a15a commit e9c338c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ivy/functional/frontends/paddle/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": (
Expand Down
30 changes: 30 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,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(
Expand Down

0 comments on commit e9c338c

Please sign in to comment.