Unverified Commit d1adb7f6 authored by moto's avatar moto Committed by GitHub
Browse files

Enforce flake8 E841 and E821 (#504)

parent 7ef1178e
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
ignore = E305,E402,E721,E741,F401,F403,F405,F821,F841,F999,W503,W504 ignore = E305,E402,E721,E741,F401,F403,F405,F999,W503,W504
exclude = build,docs/source,_ext exclude = build,docs/source,_ext
...@@ -64,7 +64,7 @@ def _test_batch(functional, tensor, *args, **kwargs): ...@@ -64,7 +64,7 @@ def _test_batch(functional, tensor, *args, **kwargs):
expected = expected.repeat(*ind) expected = expected.repeat(*ind)
torch.random.manual_seed(42) torch.random.manual_seed(42)
computed = functional(tensors.clone(), *args, **kwargs) _ = functional(tensors.clone(), *args, **kwargs)
class TestFunctional(unittest.TestCase): class TestFunctional(unittest.TestCase):
......
import os import os
import time
import unittest import unittest
import torch import torch
...@@ -450,17 +449,13 @@ class TestFunctionalFiltering(unittest.TestCase): ...@@ -450,17 +449,13 @@ class TestFunctionalFiltering(unittest.TestCase):
# SoX method # SoX method
E = torchaudio.sox_effects.SoxEffectsChain() E = torchaudio.sox_effects.SoxEffectsChain()
E.set_input_file(fn_sine) E.set_input_file(fn_sine)
_timing_sox = time.time()
E.append_effect_to_chain("biquad", [b0, b1, b2, a0, a1, a2]) E.append_effect_to_chain("biquad", [b0, b1, b2, a0, a1, a2])
waveform_sox_out, sr = E.sox_build_flow_effects() waveform_sox_out, _ = E.sox_build_flow_effects()
_timing_sox_run_time = time.time() - _timing_sox
_timing_lfilter_filtering = time.time() waveform, _ = torchaudio.load(fn_sine, normalization=True)
waveform, sample_rate = torchaudio.load(fn_sine, normalization=True)
waveform_lfilter_out = F.lfilter( waveform_lfilter_out = F.lfilter(
waveform, torch.tensor([a0, a1, a2]), torch.tensor([b0, b1, b2]) waveform, torch.tensor([a0, a1, a2]), torch.tensor([b0, b1, b2])
) )
_timing_lfilter_run_time = time.time() - _timing_lfilter_filtering
assert torch.allclose(waveform_sox_out, waveform_lfilter_out, atol=1e-4) assert torch.allclose(waveform_sox_out, waveform_lfilter_out, atol=1e-4)
_test_torchscript_functional( _test_torchscript_functional(
......
...@@ -257,7 +257,7 @@ class Test_SoxEffectsChain(unittest.TestCase): ...@@ -257,7 +257,7 @@ class Test_SoxEffectsChain(unittest.TestCase):
vol = torchaudio.transforms.Vol(gain, gain_type) vol = torchaudio.transforms.Vol(gain, gain_type)
z = vol(x_orig) z = vol(x_orig)
# check if effect worked # check if effect worked
self.assertTrue(x.allclose(vol(x_orig), rtol=1e-4, atol=1e-4)) self.assertTrue(x.allclose(z, rtol=1e-4, atol=1e-4))
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -212,7 +212,7 @@ class Tester(unittest.TestCase): ...@@ -212,7 +212,7 @@ class Tester(unittest.TestCase):
def test_compute_deltas_twochannel(self): def test_compute_deltas_twochannel(self):
specgram = torch.tensor([1., 2., 3., 4.]).repeat(1, 2, 1) specgram = torch.tensor([1., 2., 3., 4.]).repeat(1, 2, 1)
expected = torch.tensor([[[0.5, 1.0, 1.0, 0.5], _ = torch.tensor([[[0.5, 1.0, 1.0, 0.5],
[0.5, 1.0, 1.0, 0.5]]]) [0.5, 1.0, 1.0, 0.5]]])
transform = transforms.ComputeDeltas() transform = transforms.ComputeDeltas()
computed = transform(specgram) computed = transform(specgram)
......
...@@ -463,8 +463,6 @@ def create_fb_matrix( ...@@ -463,8 +463,6 @@ def create_fb_matrix(
# freq bins # freq bins
# Equivalent filterbank construction by Librosa # Equivalent filterbank construction by Librosa
all_freqs = torch.linspace(0, sample_rate // 2, n_freqs) all_freqs = torch.linspace(0, sample_rate // 2, n_freqs)
i_freqs = all_freqs.ge(f_min) & all_freqs.le(f_max)
freqs = all_freqs[i_freqs]
# calculate mel freq bins # calculate mel freq bins
# hertz to mel(f) is 2595. * math.log10(1. + (f / 700.)) # hertz to mel(f) is 2595. * math.log10(1. + (f / 700.))
...@@ -710,9 +708,6 @@ def lfilter( ...@@ -710,9 +708,6 @@ def lfilter(
Returns: Returns:
Tensor: Waveform with dimension of `(..., time)`. Output will be clipped to -1 to 1. Tensor: Waveform with dimension of `(..., time)`. Output will be clipped to -1 to 1.
""" """
dim = waveform.dim()
# pack batch # pack batch
shape = waveform.size() shape = waveform.size()
waveform = waveform.view(-1, shape[-1]) waveform = waveform.view(-1, shape[-1])
...@@ -820,12 +815,8 @@ def highpass_biquad( ...@@ -820,12 +815,8 @@ def highpass_biquad(
Returns: Returns:
Tensor: Waveform dimension of `(..., time)` Tensor: Waveform dimension of `(..., time)`
""" """
GAIN = 1.
w0 = 2 * math.pi * cutoff_freq / sample_rate w0 = 2 * math.pi * cutoff_freq / sample_rate
A = math.exp(GAIN / 40.0 * math.log(10))
alpha = math.sin(w0) / 2. / Q alpha = math.sin(w0) / 2. / Q
mult = _dB2Linear(max(GAIN, 0))
b0 = (1 + math.cos(w0)) / 2 b0 = (1 + math.cos(w0)) / 2
b1 = -1 - math.cos(w0) b1 = -1 - math.cos(w0)
...@@ -853,12 +844,8 @@ def lowpass_biquad( ...@@ -853,12 +844,8 @@ def lowpass_biquad(
Returns: Returns:
Tensor: Waveform of dimension of `(..., time)` Tensor: Waveform of dimension of `(..., time)`
""" """
GAIN = 1.
w0 = 2 * math.pi * cutoff_freq / sample_rate w0 = 2 * math.pi * cutoff_freq / sample_rate
A = math.exp(GAIN / 40.0 * math.log(10))
alpha = math.sin(w0) / 2 / Q alpha = math.sin(w0) / 2 / Q
mult = _dB2Linear(max(GAIN, 0))
b0 = (1 - math.cos(w0)) / 2 b0 = (1 - math.cos(w0)) / 2
b1 = 1 - math.cos(w0) b1 = 1 - math.cos(w0)
...@@ -1030,7 +1017,6 @@ def band_biquad( ...@@ -1030,7 +1017,6 @@ def band_biquad(
https://www.w3.org/2011/audio/audio-eq-cookbook.html#APF https://www.w3.org/2011/audio/audio-eq-cookbook.html#APF
""" """
w0 = 2 * math.pi * central_freq / sample_rate w0 = 2 * math.pi * central_freq / sample_rate
alpha = math.sin(w0) / 2 / Q
bw_Hz = central_freq / Q bw_Hz = central_freq / Q
a0 = 1. a0 = 1.
......
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