From e6642b330895ac43ec7696eb1485053c5c074ee6 Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Fri, 9 Apr 2021 20:52:25 +0000 Subject: [PATCH 1/3] Add deprecation warnings to functions for complex --- torchaudio/functional/functional.py | 39 +++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py index 19b940caa8..44d64d44cc 100644 --- a/torchaudio/functional/functional.py +++ b/torchaudio/functional/functional.py @@ -7,7 +7,7 @@ import torch from torch import Tensor -from torchaudio._internal import module_utils as _mod_utils +from torchaudio._internal import module_utils as _mod_utils, deprecated import torchaudio __all__ = [ @@ -84,6 +84,14 @@ def spectrogram( ``n_fft // 2 + 1`` and ``n_fft`` is the number of Fourier bins, and time is the number of window hops (n_frame). """ + if power is None and not return_complex: + warnings.warn( + "The use of pseudo complex type in spectrogram is now deprecated." + "Please migrate to native complex type by providing `return_complex=True`. " + "Please refer to https://github.com/pytorch/audio/issues/1337 " + "for more details about the torchaudio's plan to migrate to native complex type." + ) + if power is not None and return_complex: raise ValueError( 'When `power` is provided, the return value is real-valued. ' @@ -525,6 +533,12 @@ def mu_law_decoding( return x +@deprecated( + "Please convert the input Tensor to complex type with `torch.view_as_complex` then " + "use `torch.abs`. " + "Please refer to https://github.com/pytorch/audio/issues/1337 " + "for more details about the torchaudio's plan to migrate to native complex type." +) def complex_norm( complex_tensor: Tensor, power: float = 1.0 @@ -544,6 +558,12 @@ def complex_norm( return complex_tensor.pow(2.).sum(-1).pow(0.5 * power) +@deprecated( + "Please convert the input Tensor to complex type with `torch.view_as_complex` then " + "use `torch.angle`. " + "Please refer to https://github.com/pytorch/audio/issues/1337 " + "for more details about the torchaudio's plan to migrate to native complex type." +) def angle( complex_tensor: Tensor ) -> Tensor: @@ -621,10 +641,19 @@ def phase_vocoder( if rate == 1.0: return complex_specgrams - if not complex_specgrams.is_complex() and complex_specgrams.size(-1) != 2: - raise ValueError( - "complex_specgrams must be either native complex tensors or " - "real valued tensors with shape (..., 2)") + if not complex_specgrams.is_complex(): + warnings.warn( + "The use of pseudo complex type in `torchaudio.functional.phase_vocoder` and " + "`torchaudio.transforms.TimeStretch` is now deprecated." + "Please migrate to native complex type by converting the input tensor with " + "`torch.view_as_complex`. " + "Please refer to https://github.com/pytorch/audio/issues/1337 " + "for more details about the torchaudio's plan to migrate to native complex type." + ) + if complex_specgrams.size(-1) != 2: + raise ValueError( + "complex_specgrams must be either native complex tensors or " + "real valued tensors with shape (..., 2)") is_complex = complex_specgrams.is_complex() From 37a94afa7192339e1cb7974404978fa4f0dfa1ef Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Mon, 12 Apr 2021 11:10:53 -0700 Subject: [PATCH 2/3] Remove the --- torchaudio/functional/functional.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py index 44d64d44cc..093932e1fc 100644 --- a/torchaudio/functional/functional.py +++ b/torchaudio/functional/functional.py @@ -89,7 +89,7 @@ def spectrogram( "The use of pseudo complex type in spectrogram is now deprecated." "Please migrate to native complex type by providing `return_complex=True`. " "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about the torchaudio's plan to migrate to native complex type." + "for more details about torchaudio's plan to migrate to native complex type." ) if power is not None and return_complex: @@ -537,7 +537,7 @@ def mu_law_decoding( "Please convert the input Tensor to complex type with `torch.view_as_complex` then " "use `torch.abs`. " "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about the torchaudio's plan to migrate to native complex type." + "for more details about torchaudio's plan to migrate to native complex type." ) def complex_norm( complex_tensor: Tensor, @@ -562,7 +562,7 @@ def complex_norm( "Please convert the input Tensor to complex type with `torch.view_as_complex` then " "use `torch.angle`. " "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about the torchaudio's plan to migrate to native complex type." + "for more details about torchaudio's plan to migrate to native complex type." ) def angle( complex_tensor: Tensor @@ -648,7 +648,7 @@ def phase_vocoder( "Please migrate to native complex type by converting the input tensor with " "`torch.view_as_complex`. " "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about the torchaudio's plan to migrate to native complex type." + "for more details about torchaudio's plan to migrate to native complex type." ) if complex_specgrams.size(-1) != 2: raise ValueError( From ffdccfb1ed90cc10302c0e1517d6cd147d874dcb Mon Sep 17 00:00:00 2001 From: moto <855818+mthrok@users.noreply.github.com> Date: Tue, 13 Apr 2021 14:33:36 +0000 Subject: [PATCH 3/3] Fix import --- torchaudio/functional/functional.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py index 093932e1fc..9d23a2cace 100644 --- a/torchaudio/functional/functional.py +++ b/torchaudio/functional/functional.py @@ -7,7 +7,7 @@ import torch from torch import Tensor -from torchaudio._internal import module_utils as _mod_utils, deprecated +from torchaudio._internal import module_utils as _mod_utils import torchaudio __all__ = [ @@ -533,7 +533,7 @@ def mu_law_decoding( return x -@deprecated( +@_mod_utils.deprecated( "Please convert the input Tensor to complex type with `torch.view_as_complex` then " "use `torch.abs`. " "Please refer to https://github.com/pytorch/audio/issues/1337 " @@ -558,7 +558,7 @@ def complex_norm( return complex_tensor.pow(2.).sum(-1).pow(0.5 * power) -@deprecated( +@_mod_utils.deprecated( "Please convert the input Tensor to complex type with `torch.view_as_complex` then " "use `torch.angle`. " "Please refer to https://github.com/pytorch/audio/issues/1337 "