History

python/tests/test_filterbank*.py: clean-up, improve get_coeff tests

Paul Brossier committed 9 years ago

Commit e116e191 parent c4fc0f22 files · +23 −16Browse files

Showing the changes to python/tests (2 of 2 files). Show all

Unified · Split

2 files
  1. python/tests/test_filterbank.py +11 −4
  2. python/tests/test_filterbank_mel.py +12 −12
python/tests/test_filterbank.py+11−4
@@ -1,9 +1,8 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main
4from numpy.testing import TestCase
5from numpy.testing import assert_equal, assert_almost_equal
6import numpy as np3import numpy as np
4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5
7from aubio import cvec, filterbank, float_type6from aubio import cvec, filterbank, float_type
8from .utils import array_from_text_file7from .utils import array_from_text_file
9 8
@@ -62,6 +61,13 @@ class aubio_filterbank_test_case(TestCase): · 52 unmodified lines
62 f.set_mel_coeffs_slaney(16000)61 f.set_mel_coeffs_slaney(16000)
63 assert_almost_equal ( expected, f.get_coeffs() )62 assert_almost_equal ( expected, f.get_coeffs() )
64 63
64 def test_mfcc_coeffs_get_coeffs(self):
65 f = filterbank(40, 512)
66 coeffs = f.get_coeffs()
67 self.assertIsInstance(coeffs, np.ndarray)
68 assert_equal (coeffs, 0)
69 assert_equal (np.shape(coeffs), (40, 512 / 2 + 1))
70
65class aubio_filterbank_wrong_values(TestCase):71class aubio_filterbank_wrong_values(TestCase):
66 72
67 def test_negative_window(self):73 def test_negative_window(self):
@@ -81,4 +87,5 @@ class aubio_filterbank_wrong_values(TestCase): · 13 unmodified lines
81 f(cvec(256))87 f(cvec(256))
82 88
83if __name__ == '__main__':89if __name__ == '__main__':
84 main()90 import nose2
91 nose2.main()
python/tests/test_filterbank_mel.py+12−12
@@ -1,9 +1,8 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3from unittest import main3import numpy as np
4from numpy.testing import TestCase4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5from numpy.testing import assert_equal, assert_almost_equal5
6from numpy import array, shape
7from aubio import cvec, filterbank, float_type6from aubio import cvec, filterbank, float_type
8 7
9class aubio_filterbank_mel_test_case(TestCase):8class aubio_filterbank_mel_test_case(TestCase):
@@ -12,33 +11,33 @@ class aubio_filterbank_mel_test_case(TestCase): · 2 unmodified lines
12 f = filterbank(40, 512)11 f = filterbank(40, 512)
13 f.set_mel_coeffs_slaney(16000)12 f.set_mel_coeffs_slaney(16000)
14 a = f.get_coeffs()13 a = f.get_coeffs()
15 assert_equal(shape (a), (40, 512/2 + 1) )14 assert_equal(np.shape (a), (40, 512/2 + 1) )
16 15
17 def test_other_slaney(self):16 def test_other_slaney(self):
18 f = filterbank(40, 512*2)17 f = filterbank(40, 512*2)
19 f.set_mel_coeffs_slaney(44100)18 f.set_mel_coeffs_slaney(44100)
20 _ = f.get_coeffs()19 self.assertIsInstance(f.get_coeffs(), np.ndarray)
21 #print "sum is", sum(sum(a))20 #print "sum is", sum(sum(a))
22 for win_s in [256, 512, 1024, 2048, 4096]:21 for win_s in [256, 512, 1024, 2048, 4096]:
23 f = filterbank(40, win_s)22 f = filterbank(40, win_s)
24 f.set_mel_coeffs_slaney(32000)23 f.set_mel_coeffs_slaney(32000)
25 _ = f.get_coeffs()
26 #print "sum is", sum(sum(a))24 #print "sum is", sum(sum(a))
25 self.assertIsInstance(f.get_coeffs(), np.ndarray)
27 26
28 def test_triangle_freqs_zeros(self):27 def test_triangle_freqs_zeros(self):
29 f = filterbank(9, 1024)28 f = filterbank(9, 1024)
30 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]29 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
31 freqs = array(freq_list, dtype = float_type)30 freqs = np.array(freq_list, dtype = float_type)
32 f.set_triangle_bands(freqs, 48000)31 f.set_triangle_bands(freqs, 48000)
33 _ = f.get_coeffs().T
34 assert_equal ( f(cvec(1024)), 0)32 assert_equal ( f(cvec(1024)), 0)
33 self.assertIsInstance(f.get_coeffs(), np.ndarray)
35 34
36 def test_triangle_freqs_ones(self):35 def test_triangle_freqs_ones(self):
37 f = filterbank(9, 1024)36 f = filterbank(9, 1024)
38 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]37 freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
39 freqs = array(freq_list, dtype = float_type)38 freqs = np.array(freq_list, dtype = float_type)
40 f.set_triangle_bands(freqs, 48000)39 f.set_triangle_bands(freqs, 48000)
41 _ = f.get_coeffs().T40 self.assertIsInstance(f.get_coeffs(), np.ndarray)
42 spec = cvec(1024)41 spec = cvec(1024)
43 spec.norm[:] = 142 spec.norm[:] = 1
44 assert_almost_equal ( f(spec),43 assert_almost_equal ( f(spec),
@@ -46,4 +45,5 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line
46 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])45 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
47 46
48if __name__ == '__main__':47if __name__ == '__main__':
49 main()48 import nose2
49 nose2.main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t