Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,6 @@ def _test_script_module(self, tensor, f, *args):

self.assertTrue(torch.allclose(jit_out, py_out))

def test_torchscript_pad_trim(self):
@torch.jit.script
def jit_method(tensor, max_len, fill_value):
# type: (Tensor, int, float) -> Tensor
return F.pad_trim(tensor, max_len, fill_value)

tensor = torch.rand((1, 10))
max_len = 5
fill_value = 3.

jit_out = jit_method(tensor, max_len, fill_value)
py_out = F.pad_trim(tensor, max_len, fill_value)

self.assertTrue(torch.allclose(jit_out, py_out))

@unittest.skipIf(not RUN_CUDA, "no CUDA")
def test_scriptmodule_pad_trim(self):
tensor = torch.rand((1, 10), device="cuda")
max_len = 5

self._test_script_module(tensor, transforms.PadTrim, max_len)

def test_torchscript_spectrogram(self):
@torch.jit.script
def jit_method(sig, pad, window, n_fft, hop, ws, power, normalize):
Expand Down
14 changes: 0 additions & 14 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ def scale(self, waveform, factor=float(2**31)):
waveform = waveform.to(torch.get_default_dtype())
return waveform / factor

def test_pad_trim(self):

waveform = self.waveform.clone()
length_orig = waveform.size(1)
length_new = int(length_orig * 1.2)

result = transforms.PadTrim(max_len=length_new)(waveform)
self.assertEqual(result.size(1), length_new)

length_new = int(length_orig * 0.8)

result = transforms.PadTrim(max_len=length_new)(waveform)
self.assertEqual(result.size(1), length_new)

def test_mu_law_companding(self):

quantization_channels = 256
Expand Down
23 changes: 0 additions & 23 deletions torchaudio/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


__all__ = [
'pad_trim',
'istft',
'spectrogram',
'create_fb_matrix',
Expand All @@ -18,28 +17,6 @@
]


@torch.jit.script
def pad_trim(waveform, max_len, fill_value):
# type: (Tensor, int, float) -> Tensor
r"""Pad/trim a 2D tensor

Args:
waveform (torch.Tensor): Tensor of audio of size (c, n)
max_len (int): Length to which the waveform will be padded
fill_value (float): Value to fill in

Returns:
torch.Tensor: Padded/trimmed tensor
"""
n = waveform.size(1)
if max_len > n:
# TODO add "with torch.no_grad():" back when JIT supports it
waveform = torch.nn.functional.pad(waveform, (0, max_len - n), 'constant', fill_value)
else:
waveform = waveform[:, :max_len]
return waveform


# TODO: remove this once https://github.com/pytorch/pytorch/issues/21478 gets solved
@torch.jit.ignore
def _stft(waveform, n_fft, hop_length, win_length, window, center, pad_mode, normalized, onesided):
Expand Down
26 changes: 0 additions & 26 deletions torchaudio/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@
from .compliance import kaldi


class PadTrim(torch.jit.ScriptModule):
r"""Pad/Trim a 2D tensor

Args:
max_len (int): Length to which the waveform will be padded
fill_value (float): Value to fill in
"""
__constants__ = ['max_len', 'fill_value']

def __init__(self, max_len, fill_value=0.):
super(PadTrim, self).__init__()
self.max_len = max_len
self.fill_value = fill_value

@torch.jit.script_method
def forward(self, waveform):
r"""
Args:
waveform (torch.Tensor): Tensor of audio of size (c, n)

Returns:
Tensor: Tensor of size (c, `max_len`)
"""
return F.pad_trim(waveform, self.max_len, self.fill_value)


class Spectrogram(torch.jit.ScriptModule):
r"""Create a spectrogram from a audio signal

Expand Down