9
9
from common_utils import AudioBackendScope , BACKENDS , create_temp_assets_dir
10
10
11
11
12
- def _test_torchscript_functional (py_method , * args , ** kwargs ):
13
- jit_method = torch .jit .script (py_method )
14
-
15
- jit_out = jit_method (* args , ** kwargs )
16
- py_out = py_method (* args , ** kwargs )
17
-
18
- assert torch .allclose (jit_out , py_out )
19
-
20
-
21
12
class TestFunctionalFiltering (unittest .TestCase ):
22
13
test_dirpath , test_dir = create_temp_assets_dir ()
23
14
@@ -88,7 +79,6 @@ def _test_lfilter(self, waveform, device):
88
79
assert len (output_waveform .size ()) == 2
89
80
assert output_waveform .size (0 ) == waveform .size (0 )
90
81
assert output_waveform .size (1 ) == waveform .size (1 )
91
- _test_torchscript_functional (F .lfilter , waveform , a_coeffs , b_coeffs )
92
82
93
83
def test_lfilter (self ):
94
84
@@ -189,7 +179,6 @@ def test_lowpass(self):
189
179
output_waveform = F .lowpass_biquad (waveform , sample_rate , CUTOFF_FREQ )
190
180
191
181
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
192
- _test_torchscript_functional (F .lowpass_biquad , waveform , sample_rate , CUTOFF_FREQ )
193
182
194
183
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
195
184
@AudioBackendScope ("sox" )
@@ -211,7 +200,6 @@ def test_highpass(self):
211
200
212
201
# TBD - this fails at the 1e-4 level, debug why
213
202
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-3 )
214
- _test_torchscript_functional (F .highpass_biquad , waveform , sample_rate , CUTOFF_FREQ )
215
203
216
204
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
217
205
@AudioBackendScope ("sox" )
@@ -233,7 +221,6 @@ def test_allpass(self):
233
221
output_waveform = F .allpass_biquad (waveform , sample_rate , CENTRAL_FREQ , Q )
234
222
235
223
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
236
- _test_torchscript_functional (F .allpass_biquad , waveform , sample_rate , CENTRAL_FREQ , Q )
237
224
238
225
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
239
226
@AudioBackendScope ("sox" )
@@ -256,7 +243,6 @@ def test_bandpass_with_csg(self):
256
243
output_waveform = F .bandpass_biquad (waveform , sample_rate , CENTRAL_FREQ , Q , CONST_SKIRT_GAIN )
257
244
258
245
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
259
- _test_torchscript_functional (F .bandpass_biquad , waveform , sample_rate , CENTRAL_FREQ , Q , CONST_SKIRT_GAIN )
260
246
261
247
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
262
248
@AudioBackendScope ("sox" )
@@ -279,7 +265,6 @@ def test_bandpass_without_csg(self):
279
265
output_waveform = F .bandpass_biquad (waveform , sample_rate , CENTRAL_FREQ , Q , CONST_SKIRT_GAIN )
280
266
281
267
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
282
- _test_torchscript_functional (F .bandpass_biquad , waveform , sample_rate , CENTRAL_FREQ , Q , CONST_SKIRT_GAIN )
283
268
284
269
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
285
270
@AudioBackendScope ("sox" )
@@ -301,7 +286,6 @@ def test_bandreject(self):
301
286
output_waveform = F .bandreject_biquad (waveform , sample_rate , CENTRAL_FREQ , Q )
302
287
303
288
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
304
- _test_torchscript_functional (F .bandreject_biquad , waveform , sample_rate , CENTRAL_FREQ , Q )
305
289
306
290
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
307
291
@AudioBackendScope ("sox" )
@@ -324,7 +308,6 @@ def test_band_with_noise(self):
324
308
output_waveform = F .band_biquad (waveform , sample_rate , CENTRAL_FREQ , Q , NOISE )
325
309
326
310
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
327
- _test_torchscript_functional (F .band_biquad , waveform , sample_rate , CENTRAL_FREQ , Q , NOISE )
328
311
329
312
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
330
313
@AudioBackendScope ("sox" )
@@ -347,7 +330,6 @@ def test_band_without_noise(self):
347
330
output_waveform = F .band_biquad (waveform , sample_rate , CENTRAL_FREQ , Q , NOISE )
348
331
349
332
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
350
- _test_torchscript_functional (F .band_biquad , waveform , sample_rate , CENTRAL_FREQ , Q , NOISE )
351
333
352
334
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
353
335
@AudioBackendScope ("sox" )
@@ -370,7 +352,6 @@ def test_treble(self):
370
352
output_waveform = F .treble_biquad (waveform , sample_rate , GAIN , CENTRAL_FREQ , Q )
371
353
372
354
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
373
- _test_torchscript_functional (F .treble_biquad , waveform , sample_rate , GAIN , CENTRAL_FREQ , Q )
374
355
375
356
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
376
357
@AudioBackendScope ("sox" )
@@ -389,7 +370,6 @@ def test_deemph(self):
389
370
output_waveform = F .deemph_biquad (waveform , sample_rate )
390
371
391
372
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
392
- _test_torchscript_functional (F .deemph_biquad , waveform , sample_rate )
393
373
394
374
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
395
375
@AudioBackendScope ("sox" )
@@ -408,7 +388,6 @@ def test_riaa(self):
408
388
output_waveform = F .riaa_biquad (waveform , sample_rate )
409
389
410
390
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
411
- _test_torchscript_functional (F .riaa_biquad , waveform , sample_rate )
412
391
413
392
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
414
393
@AudioBackendScope ("sox" )
@@ -431,7 +410,6 @@ def test_equalizer(self):
431
410
output_waveform = F .equalizer_biquad (waveform , sample_rate , CENTER_FREQ , GAIN , Q )
432
411
433
412
assert torch .allclose (sox_output_waveform , output_waveform , atol = 1e-4 )
434
- _test_torchscript_functional (F .equalizer_biquad , waveform , sample_rate , CENTER_FREQ , GAIN , Q )
435
413
436
414
@unittest .skipIf ("sox" not in BACKENDS , "sox not available" )
437
415
@AudioBackendScope ("sox" )
@@ -458,9 +436,6 @@ def test_perf_biquad_filtering(self):
458
436
)
459
437
460
438
assert torch .allclose (waveform_sox_out , waveform_lfilter_out , atol = 1e-4 )
461
- _test_torchscript_functional (
462
- F .lfilter , waveform , torch .tensor ([a0 , a1 , a2 ]), torch .tensor ([b0 , b1 , b2 ])
463
- )
464
439
465
440
466
441
if __name__ == "__main__" :
0 commit comments