diff --git a/test/torchaudio_unittest/complex_librosa_compatibility_test.py b/test/torchaudio_unittest/complex_librosa_compatibility_test.py index 7fc44f0e4b..67ca6ca722 100644 --- a/test/torchaudio_unittest/complex_librosa_compatibility_test.py +++ b/test/torchaudio_unittest/complex_librosa_compatibility_test.py @@ -17,9 +17,9 @@ import scipy import pytest - from torchaudio_unittest import common_utils + @unittest.skipIf(not LIBROSA_AVAILABLE, "Librosa not available") class TestFunctional(common_utils.TorchaudioTestCase): """Test suite for functions in `functional` module.""" @@ -35,7 +35,8 @@ def test_phase_vocoder(self, rate): # result in bottom right values of the stretched sectrogram to not # match with librosa. - phase_advance = torch.linspace(0, np.pi * hop_length, complex_specgrams.shape[-2], dtype=torch.double)[..., None] + phase_advance = torch.linspace(0, np.pi * hop_length, + complex_specgrams.shape[-2], dtype=torch.double)[..., None] complex_specgrams_stretch = F.phase_vocoder(complex_specgrams, rate=rate, phase_advance=phase_advance) @@ -50,7 +51,7 @@ def test_phase_vocoder(self, rate): index = [0] + [slice(None)] * 2 mono_complex_specgram = complex_specgrams[index].numpy() expected_complex_stretch = librosa.phase_vocoder(mono_complex_specgram, - rate=rate, - hop_length=hop_length) + rate=rate, + hop_length=hop_length) self.assertEqual(complex_specgrams_stretch[index], torch.from_numpy(expected_complex_stretch)) diff --git a/torchaudio/functional.py b/torchaudio/functional.py index 246d18e157..4ac71befa0 100644 --- a/torchaudio/functional.py +++ b/torchaudio/functional.py @@ -490,9 +490,9 @@ def phase_vocoder( >>> x.shape # with 231 == ceil(300 / 1.3) torch.Size([2, 1025, 231]) """ - USE_COMPLEX = complex_specgrams.is_complex() + use_complex = complex_specgrams.is_complex() shape = complex_specgrams.size() - if USE_COMPLEX: + if use_complex: # pack batch complex_specgrams = complex_specgrams.reshape([-1] + list(shape[-2:])) time_steps = torch.arange(0, @@ -546,7 +546,7 @@ def phase_vocoder( real_stretch = mag * torch.cos(phase_acc) imag_stretch = mag * torch.sin(phase_acc) - if USE_COMPLEX: + if use_complex: complex_specgrams_stretch = torch.view_as_complex(torch.stack([real_stretch, imag_stretch], dim=-1)) # unpack batch diff --git a/torchaudio/transforms.py b/torchaudio/transforms.py index bf5d9efc14..fd90abde91 100644 --- a/torchaudio/transforms.py +++ b/torchaudio/transforms.py @@ -693,8 +693,8 @@ def forward(self, complex_specgrams: Tensor, overriding_rate: Optional[float] = Returns: Tensor: Stretched complex spectrogram of dimension (..., freq, ceil(time/rate), complex=2). """ - USE_COMPLEX = complex_specgrams.is_complex() - if not USE_COMPLEX: + use_complex = complex_specgrams.is_complex() + if not use_complex: assert complex_specgrams.size(-1) == 2, "complex_specgrams \ should be a complex tensor, shape (..., complex=2)"