Fix torch.istft length mismatch and window runtime error (#63469)
authorZhaoheng Ni <zni@fb.com>
Thu, 2 Sep 2021 15:59:53 +0000 (08:59 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 2 Sep 2021 16:31:47 +0000 (09:31 -0700)
commit2c258d91cc1dc11c338e97d6970ac77a4f8978ec
tree859c474849536ae5638e1098eed236297e2ad8a7
parent616fd9219da18bcfe69da8b0c3a96dd2c6298066
Fix torch.istft length mismatch and window runtime error (#63469)

Summary:
The PR fixes two issues:
- See https://github.com/pytorch/pytorch/issues/62747 and https://github.com/pytorch/audio/issues/1409. The length mismatch when the given ``length`` parameter is longer than expected. Add padding logic in consistent with librosa.
- See https://github.com/pytorch/pytorch/issues/62323. The current implementations checks if the min value of window_envelop.abs() is greater than zero.  In librosa they normalize the signal on non-zero values by indexing. Like
```
approx_nonzero_indices = ifft_window_sum > util.tiny(ifft_window_sum)
y[approx_nonzero_indices] /= ifft_window_sum[approx_nonzero_indices]
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/63469

Reviewed By: fmassa

Differential Revision: D30695827

Pulled By: nateanl

fbshipit-source-id: d034e53f0d65b3fd1dbd150c9c5acf3faf25a164
aten/src/ATen/native/SpectralOps.cpp
test/test_spectral_ops.py
torch/functional.py