Unverified Commit ab50909d authored by S Harish's avatar S Harish Committed by GitHub
Browse files

Remove F.complex_norm and T.ComplexNorm (#1942)

parent 7e5f8021
...@@ -71,17 +71,6 @@ resample ...@@ -71,17 +71,6 @@ resample
.. autofunction:: resample .. autofunction:: resample
:hidden:`Complex Utility`
~~~~~~~~~~~~~~~~~~~~~~~~~
Utilities for pseudo complex tensor. This is not for the native complex dtype, such as `cfloat64`, but for tensors with real-value type and have extra dimension at the end for real and imaginary parts.
complex_norm
------------
.. autofunction:: complex_norm
:hidden:`Filtering` :hidden:`Filtering`
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
......
...@@ -88,16 +88,6 @@ Transforms are common audio transforms. They can be chained together using :clas ...@@ -88,16 +88,6 @@ Transforms are common audio transforms. They can be chained together using :clas
.. automethod:: forward .. automethod:: forward
:hidden:`Complex Utility`
~~~~~~~~~~~~~~~~~~~~~~~~~
:hidden:`ComplexNorm`
---------------------
.. autoclass:: ComplexNorm
.. automethod:: forward
:hidden:`Feature Extractions` :hidden:`Feature Extractions`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
...@@ -319,16 +319,6 @@ class Functional(TestBaseMixin): ...@@ -319,16 +319,6 @@ class Functional(TestBaseMixin):
f"No values were close to the limit. Did it over-clamp?\n{decibels}" f"No values were close to the limit. Did it over-clamp?\n{decibels}"
) )
@parameterized.expand(
list(itertools.product([(1, 2, 1025, 400, 2), (1025, 400, 2)], [1, 2, 0.7]))
)
def test_complex_norm(self, shape, power):
torch.random.manual_seed(42)
complex_tensor = torch.randn(*shape, dtype=self.dtype, device=self.device)
expected_norm_tensor = complex_tensor.pow(2).sum(-1).pow(power / 2)
norm_tensor = F.complex_norm(complex_tensor, power)
self.assertEqual(norm_tensor, expected_norm_tensor, atol=1e-5, rtol=1e-5)
@parameterized.expand( @parameterized.expand(
list(itertools.product([(2, 1025, 400), (1, 201, 100)], [100], [0., 30.], [1, 2])) list(itertools.product([(2, 1025, 400), (1, 201, 100)], [100], [0., 30.], [1, 2]))
) )
......
...@@ -223,14 +223,6 @@ class Functional(TempDirMixin, TestBaseMixin): ...@@ -223,14 +223,6 @@ class Functional(TempDirMixin, TestBaseMixin):
tensor = torch.rand((1, 10)) tensor = torch.rand((1, 10))
self._assert_consistency(func, tensor) self._assert_consistency(func, tensor)
def test_complex_norm(self):
def func(tensor):
power = 2.
return F.complex_norm(tensor, power)
tensor = torch.randn(1, 2, 1025, 400, 2)
self._assert_consistency(func, tensor)
def test_mask_along_axis(self): def test_mask_along_axis(self):
def func(tensor): def func(tensor):
mask_param = 100 mask_param = 100
......
...@@ -86,10 +86,6 @@ class Transforms(TestBaseMixin): ...@@ -86,10 +86,6 @@ class Transforms(TestBaseMixin):
tensor = common_utils.get_whitenoise(sample_rate=sr1) tensor = common_utils.get_whitenoise(sample_rate=sr1)
self._assert_consistency(T.Resample(sr1, sr2), tensor) self._assert_consistency(T.Resample(sr1, sr2), tensor)
def test_ComplexNorm(self):
tensor = torch.rand((1, 2, 201, 2))
self._assert_consistency(T.ComplexNorm(), tensor)
def test_MuLawEncoding(self): def test_MuLawEncoding(self):
tensor = common_utils.get_whitenoise() tensor = common_utils.get_whitenoise()
self._assert_consistency(T.MuLawEncoding(), tensor) self._assert_consistency(T.MuLawEncoding(), tensor)
......
from .functional import ( from .functional import (
amplitude_to_DB, amplitude_to_DB,
complex_norm,
compute_deltas, compute_deltas,
compute_kaldi_pitch, compute_kaldi_pitch,
create_dct, create_dct,
...@@ -52,7 +51,6 @@ from .filtering import ( ...@@ -52,7 +51,6 @@ from .filtering import (
__all__ = [ __all__ = [
'amplitude_to_DB', 'amplitude_to_DB',
'complex_norm',
'compute_deltas', 'compute_deltas',
'compute_kaldi_pitch', 'compute_kaldi_pitch',
'create_dct', 'create_dct',
......
...@@ -28,7 +28,6 @@ __all__ = [ ...@@ -28,7 +28,6 @@ __all__ = [
"DB_to_amplitude", "DB_to_amplitude",
"mu_law_encoding", "mu_law_encoding",
"mu_law_decoding", "mu_law_decoding",
"complex_norm",
"phase_vocoder", "phase_vocoder",
'mask_along_axis', 'mask_along_axis',
'mask_along_axis_iid', 'mask_along_axis_iid',
...@@ -722,32 +721,6 @@ def mu_law_decoding( ...@@ -722,32 +721,6 @@ def mu_law_decoding(
return x return x
@_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 "
"for more details about torchaudio's plan to migrate to native complex type.",
version="0.11",
)
def complex_norm(
complex_tensor: Tensor,
power: float = 1.0
) -> Tensor:
r"""Compute the norm of complex tensor input.
Args:
complex_tensor (Tensor): Tensor shape of `(..., complex=2)`
power (float, optional): Power of the norm. (Default: `1.0`).
Returns:
Tensor: Power of the normed input tensor. Shape of `(..., )`
"""
# Replace by torch.norm once issue is fixed
# https://github.com/pytorch/pytorch/issues/34279
return complex_tensor.pow(2.).sum(-1).pow(0.5 * power)
def phase_vocoder( def phase_vocoder(
complex_specgrams: Tensor, complex_specgrams: Tensor,
rate: float, rate: float,
......
...@@ -26,7 +26,6 @@ __all__ = [ ...@@ -26,7 +26,6 @@ __all__ = [
'MuLawEncoding', 'MuLawEncoding',
'MuLawDecoding', 'MuLawDecoding',
'Resample', 'Resample',
'ComplexNorm',
'TimeStretch', 'TimeStretch',
'Fade', 'Fade',
'FrequencyMasking', 'FrequencyMasking',
...@@ -900,42 +899,6 @@ class Resample(torch.nn.Module): ...@@ -900,42 +899,6 @@ class Resample(torch.nn.Module):
self.kernel, self.width) self.kernel, self.width)
class ComplexNorm(torch.nn.Module):
r"""Compute the norm of complex tensor input.
Args:
power (float, optional): Power of the norm. (Default: to ``1.0``)
Example
>>> complex_tensor = ... # Tensor shape of (…, complex=2)
>>> transform = transforms.ComplexNorm(power=2)
>>> complex_norm = transform(complex_tensor)
"""
__constants__ = ['power']
def __init__(self, power: float = 1.0) -> None:
warnings.warn(
'torchaudio.transforms.ComplexNorm has been deprecated '
'and will be removed from future release.'
'Please convert the input Tensor to complex type with `torch.view_as_complex` then '
'use `torch.abs` and `torch.angle`. '
'Please refer to https://github.com/pytorch/audio/issues/1337 '
"for more details about torchaudio's plan to migrate to native complex type."
)
super(ComplexNorm, self).__init__()
self.power = power
def forward(self, complex_tensor: Tensor) -> Tensor:
r"""
Args:
complex_tensor (Tensor): Tensor shape of `(..., complex=2)`.
Returns:
Tensor: norm of the input tensor, shape of `(..., )`.
"""
return F.complex_norm(complex_tensor, self.power)
class ComputeDeltas(torch.nn.Module): class ComputeDeltas(torch.nn.Module):
r"""Compute delta coefficients of a tensor, usually a spectrogram. r"""Compute delta coefficients of a tensor, usually a spectrogram.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment