mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Update stft tests to support latest librosa (#72833)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/72833 Closes #72550 The latest version of librosa breaks backward compatibility in two ways: - Everything except the input tensor is now keyword-only - `pad_mode` now defaults to `'constant'` for zero-padding https://librosa.org/doc/latest/generated/librosa.stft.html This changes the test to match the old behaior even when using the new library and updates the documentation to explicitly say that `torch.stft` doesn't exactly follow the librosa API. This was always true (`torch.stft` it has new arguments, a different default window and supports complex input), but it can't hurt to be explicit. Test Plan: Imported from OSS Reviewed By: ngimel Differential Revision: D34386897 Pulled By: mruberry fbshipit-source-id: 6adc23f48fcb368dacf70602e9197726d6b7e0c1 (cherry picked from commit b5c5ed41963022c9f26467279ed098fb905fa00a)
This commit is contained in:
committed by
PyTorch MergeBot
parent
1ef244e003
commit
0947521268
@ -879,9 +879,16 @@ class TestFFT(TestCase):
|
||||
input_1d = x.dim() == 1
|
||||
if input_1d:
|
||||
x = x.view(1, -1)
|
||||
|
||||
# NOTE: librosa 0.9 changed default pad_mode to 'constant' (zero padding)
|
||||
# however, we use the pre-0.9 default ('reflect')
|
||||
pad_mode = 'reflect'
|
||||
|
||||
result = []
|
||||
for xi in x:
|
||||
ri = librosa.stft(xi.cpu().numpy(), n_fft, hop_length, win_length, window, center=center)
|
||||
ri = librosa.stft(xi.cpu().numpy(), n_fft=n_fft, hop_length=hop_length,
|
||||
win_length=win_length, window=window, center=center,
|
||||
pad_mode=pad_mode)
|
||||
result.append(torch.from_numpy(np.stack([ri.real, ri.imag], -1)))
|
||||
result = torch.stack(result, 0)
|
||||
if input_1d:
|
||||
|
@ -586,7 +586,8 @@ def stft(input: Tensor, n_fft: int, hop_length: Optional[int] = None,
|
||||
|
||||
The STFT computes the Fourier transform of short overlapping windows of the
|
||||
input. This giving frequency components of the signal as they change over
|
||||
time. The interface of this function is modeled after the librosa_ stft function.
|
||||
time. The interface of this function is modeled after (but *not* a drop-in
|
||||
replacement for) librosa_ stft function.
|
||||
|
||||
.. _librosa: https://librosa.org/doc/latest/generated/librosa.stft.html
|
||||
|
||||
|
Reference in New Issue
Block a user