Skip to content

Commit

Permalink
Add unit test for librosa stft
Browse files Browse the repository at this point in the history
- Add parity check with torch.stft and librosa.stft
  • Loading branch information
Masao-Someki committed Dec 18, 2022
1 parent 743821d commit 7931f2e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/espnet2/layers/test_stft.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ def test_inverse():
x_lengths = torch.IntTensor([400, 300])
raw, _ = layer.inverse(y, x_lengths)
raw, _ = layer.inverse(y)


def test_librosa_stft():
mkl_is_available = torch.backends.mkl.is_available()
if not mkl_is_available:
raise RuntimeError("MKL is not available.")

layer = Stft()
layer.eval()
x = torch.randn(2, 16000, device="cpu")
y_torch, _ = layer(x)
torch._C.has_mkl = False
y_librosa, _ = layer(x)
assert torch.allclose(y_torch, y_librosa, atol=7e-6)
torch._C.has_mkl = True

0 comments on commit 7931f2e

Please sign in to comment.