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

Enforce flake8 E841 and E821 (#504)

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