Skip to content

Commit ccc0f46

Browse files
committed
Ignore return_complex when returning real-valued tensor in spectrogram. (#1551)
1 parent d33ae6f commit ccc0f46

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

torchaudio/functional/functional.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def spectrogram(
7373
onesided (bool, optional): controls whether to return half of results to
7474
avoid redundancy. Default: ``True``
7575
return_complex (bool, optional):
76-
``return_complex = True``, this function returns the resulting Tensor in
77-
complex dtype, otherwise it returns the resulting Tensor in real dtype with extra
78-
dimension for real and imaginary parts. (see ``torch.view_as_real``).
79-
When ``power`` is provided, the value must be False, as the resulting
80-
Tensor represents real-valued power.
76+
Indicates whether the resulting complex-valued Tensor should be represented with
77+
native complex dtype, such as `torch.cfloat` and `torch.cdouble`, or real dtype
78+
mimicking complex value with an extra dimension for real and imaginary parts.
79+
This argument is only effective when ``power=None``.
80+
See also ``torch.view_as_real``.
8181
8282
Returns:
8383
Tensor: Dimension (..., freq, time), freq is
@@ -92,11 +92,6 @@ def spectrogram(
9292
"for more details about torchaudio's plan to migrate to native complex type."
9393
)
9494

95-
if power is not None and return_complex:
96-
raise ValueError(
97-
'When `power` is provided, the return value is real-valued. '
98-
'Therefore, `return_complex` must be False.')
99-
10095
if pad > 0:
10196
# TODO add "with torch.no_grad():" back when JIT supports it
10297
waveform = torch.nn.functional.pad(waveform, (pad, pad), "constant")

torchaudio/transforms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ class Spectrogram(torch.nn.Module):
6060
onesided (bool, optional): controls whether to return half of results to
6161
avoid redundancy Default: ``True``
6262
return_complex (bool, optional):
63-
``return_complex = True``, this function returns the resulting Tensor in
64-
complex dtype, otherwise it returns the resulting Tensor in real dtype with extra
65-
dimension for real and imaginary parts. (see ``torch.view_as_real``).
66-
When ``power`` is provided, the value must be False, as the resulting
67-
Tensor represents real-valued power.
63+
Indicates whether the resulting complex-valued Tensor should be represented with
64+
native complex dtype, such as `torch.cfloat` and `torch.cdouble`, or real dtype
65+
mimicking complex value with an extra dimension for real and imaginary parts.
66+
This argument is only effective when ``power=None``.
67+
See also ``torch.view_as_real``.
6868
"""
6969
__constants__ = ['n_fft', 'win_length', 'hop_length', 'pad', 'power', 'normalized']
7070

0 commit comments

Comments
 (0)