Skip to content

Commit

Permalink
stft
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadhammad-tech authored Oct 24, 2023
1 parent dc44ffa commit 32c4626
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ivy/functional/frontends/paddle/signal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import ivy
from ivy.functional.frontends.tensorflow.func_wrapper import (
to_ivy_arrays_and_back,
)
from ivy.func_wrapper import with_supported_dtypes


# stft
@with_supported_dtypes(
{
"2.5.1 and below": (
"complex64",
"complex128",
)
},
"paddle",
)
@to_ivy_arrays_and_back
def stft(
x,
n_fft,
hop_length=None,
win_length=None,
window=None,
center=True,
pad_mode="reflect",
normalized=False,
onesided=True,
name=None,
):
x = ivy.asarray(x)
return ivy.stft(
x,
n_fft,
hop_length=hop_length,
win_length=win_length,
window=window,
center=center,
pad_mode=pad_mode,
normalized=normalized,
onesided=onesided,
name=name,
)
69 changes: 69 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_signal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# global
from hypothesis import strategies as st

# local
import ivy_tests.test_ivy.helpers as helpers
from ivy_tests.test_ivy.helpers import handle_frontend_test


# --- Helpers --- #
# --------------- #


@st.composite
def _valid_stft(draw):
dtype, x = draw(
helpers.dtype_and_values(
available_dtypes=["float32", "float64"],
max_value=65280,
min_value=-65280,
min_num_dims=1,
min_dim_size=2,
shared_dtype=True,
)
)
n_fft = draw(helpers.ints(min_value=16, max_value=100))
hop_length = draw(helpers.ints(min_value=1, max_value=50))

return dtype, x, n_fft, hop_length


# --- Main --- #
# ------------ #


# Updated test function
@handle_frontend_test(
fn_tree="paddle.signal.stft",
dtype_x_and_args=_valid_stft(),
test_with_out=st.just(False),
)
def test_paddle_stft(
*,
dtype_x_and_args,
frontend,
test_flags,
fn_tree,
backend_fw,
on_device,
):
input_dtype, x, n_fft, hop_length = dtype_x_and_args
helpers.test_frontend_function(
input_dtypes=input_dtype,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
x=x,
n_fft=n_fft,
hop_length=hop_length,
win_length=None,
window=None,
center=True,
pad_mode="reflect",
normalized=False,
onesided=True,
atol=1e-02,
rtol=1e-02,
)

0 comments on commit 32c4626

Please sign in to comment.