History

python/tests: use aubio.float_type

Paul Brossier committed 10 years ago

Commit c4b21831 parent fbcee4f6 files · +61 −58Browse files

Showing the changes to python (6 of 6 files). Show all

Unified · Split

6 files
  1. python/tests/test_filterbank.py +6 −6
  2. python/tests/test_filterbank_mel.py +3 −3
  3. python/tests/test_fvec.py +20 −17
  4. python/tests/test_musicutils.py +5 −5
  5. python/tests/test_pitch.py +2 −2
  6. python/tests/test_specdesc.py +25 −25
python/tests/test_filterbank.py+6−6
@@ -5,7 +5,7 @@ from numpy.testing import assert_equal, assert_almost_equal · 4 unmodified lines
5from numpy import random5from numpy import random
6from math import pi6from math import pi
7from numpy import array7from numpy import array
8from aubio import cvec, filterbank8from aubio import cvec, filterbank, float_type
9from utils import array_from_text_file9from utils import array_from_text_file
10 10
11class aubio_filterbank_test_case(TestCase):11class aubio_filterbank_test_case(TestCase):
@@ -16,7 +16,7 @@ class aubio_filterbank_test_case(TestCase): · 4 unmodified lines
16 16
17 def test_set_coeffs(self):17 def test_set_coeffs(self):
18 f = filterbank(40, 512)18 f = filterbank(40, 512)
19 r = random.random([40, int(512 / 2) + 1]).astype('float32')19 r = random.random([40, int(512 / 2) + 1]).astype(float_type)
20 f.set_coeffs(r)20 f.set_coeffs(r)
21 assert_equal (r, f.get_coeffs())21 assert_equal (r, f.get_coeffs())
22 22
@@ -35,16 +35,16 @@ class aubio_filterbank_test_case(TestCase): · 12 unmodified lines
35 def test_random_norm(self):35 def test_random_norm(self):
36 f = filterbank(40, 512)36 f = filterbank(40, 512)
37 c = cvec(512)37 c = cvec(512)
38 c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')38 c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type)
39 assert_equal( f(c), 0)39 assert_equal( f(c), 0)
40 40
41 def test_random_coeffs(self):41 def test_random_coeffs(self):
42 f = filterbank(40, 512)42 f = filterbank(40, 512)
43 c = cvec(512)43 c = cvec(512)
44 r = random.random([40, int(512 / 2) + 1]).astype('float32')44 r = random.random([40, int(512 / 2) + 1]).astype(float_type)
45 r /= r.sum()45 r /= r.sum()
46 f.set_coeffs(r)46 f.set_coeffs(r)
47 c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')47 c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type)
48 assert_equal ( f(c) < 1., True )48 assert_equal ( f(c) < 1., True )
49 assert_equal ( f(c) > 0., True )49 assert_equal ( f(c) > 0., True )
50 50
@@ -52,7 +52,7 @@ class aubio_filterbank_test_case(TestCase): · 1 unmodified line
52 f = filterbank(40, 512)52 f = filterbank(40, 512)
53 c = cvec(512)53 c = cvec(512)
54 f.set_mel_coeffs_slaney(44100)54 f.set_mel_coeffs_slaney(44100)
55 c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')55 c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type)
56 assert_equal ( f(c) < 1., True )56 assert_equal ( f(c) < 1., True )
57 assert_equal ( f(c) > 0., True )57 assert_equal ( f(c) > 0., True )
58 58
python/tests/test_filterbank_mel.py+3−3
@@ -3,7 +3,7 @@ · 2 unmodified lines
3from numpy.testing import TestCase, run_module_suite3from numpy.testing import TestCase, run_module_suite
4from numpy.testing import assert_equal, assert_almost_equal4from numpy.testing import assert_equal, assert_almost_equal
5from numpy import array, shape5from numpy import array, shape
6from aubio import cvec, filterbank6from aubio import cvec, filterbank, float_type
7 7
8class aubio_filterbank_mel_test_case(TestCase):8class aubio_filterbank_mel_test_case(TestCase):
9 9
@@ -27,7 +27,7 @@ class aubio_filterbank_mel_test_case(TestCase): · 17 unmodified lines
27 def test_triangle_freqs_zeros(self):27 def test_triangle_freqs_zeros(self):
28 f = filterbank(9, 1024)28 f = filterbank(9, 1024)
29 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]
30 freqs = array(freq_list, dtype = 'float32')30 freqs = array(freq_list, dtype = float_type)
31 f.set_triangle_bands(freqs, 48000)31 f.set_triangle_bands(freqs, 48000)
32 f.get_coeffs().T32 f.get_coeffs().T
33 assert_equal ( f(cvec(1024)), 0)33 assert_equal ( f(cvec(1024)), 0)
@@ -35,7 +35,7 @@ class aubio_filterbank_mel_test_case(TestCase): · 1 unmodified line
35 def test_triangle_freqs_ones(self):35 def test_triangle_freqs_ones(self):
36 f = filterbank(9, 1024)36 f = filterbank(9, 1024)
37 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]
38 freqs = array(freq_list, dtype = 'float32')38 freqs = array(freq_list, dtype = float_type)
39 f.set_triangle_bands(freqs, 48000)39 f.set_triangle_bands(freqs, 48000)
40 f.get_coeffs().T40 f.get_coeffs().T
41 spec = cvec(1024)41 spec = cvec(1024)
python/tests/test_fvec.py+20−17
@@ -3,21 +3,24 @@ · 2 unmodified lines
3from numpy.testing import TestCase, run_module_suite3from numpy.testing import TestCase, run_module_suite
4from numpy.testing import assert_equal, assert_almost_equal4from numpy.testing import assert_equal, assert_almost_equal
5from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal5from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal
6from aubio import float_type
6from numpy import array, shape7from numpy import array, shape
7 8
9wrong_type = 'float32' if float_type == 'float64' else 'float64'
10
8default_size = 51211default_size = 512
9 12
10class aubio_fvec_test_case(TestCase):13class aubio_fvec_test_case(TestCase):
11 14
12 def test_vector_created_with_zeroes(self):15 def test_vector_created_with_zeroes(self):
13 a = fvec(10)16 a = fvec(10)
14 assert a.dtype == 'float32'17 assert a.dtype == float_type
15 assert a.shape == (10,)18 assert a.shape == (10,)
16 assert_equal (a, 0)19 assert_equal (a, 0)
17 20
18 def test_vector_create_with_list(self):21 def test_vector_create_with_list(self):
19 a = fvec([0,1,2,3])22 a = fvec([0,1,2,3])
20 assert a.dtype == 'float32'23 assert a.dtype == float_type
21 assert a.shape == (4,)24 assert a.shape == (4,)
22 assert_equal (list(range(4)), a)25 assert_equal (list(range(4)), a)
23 26
@@ -57,7 +60,7 @@ class aubio_fvec_test_case(TestCase): · 33 unmodified lines
57 self.assertEqual (alpha_norm(a, 1), 0.5)60 self.assertEqual (alpha_norm(a, 1), 0.5)
58 a[1] = 161 a[1] = 1
59 self.assertEqual (alpha_norm(a, 1), 1)62 self.assertEqual (alpha_norm(a, 1), 1)
60 a = array([0, 1], dtype='float32')63 a = array([0, 1], dtype=float_type)
61 from math import sqrt64 from math import sqrt
62 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)65 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
63 66
@@ -66,13 +69,13 @@ class aubio_fvec_test_case(TestCase): · 2 unmodified lines
66 69
67 def test_alpha_norm_of_array_of_float32(self):70 def test_alpha_norm_of_array_of_float32(self):
68 # check scalar fails71 # check scalar fails
69 a = array(1, dtype = 'float32')72 a = array(1, dtype = float_type)
70 self.assertRaises (ValueError, alpha_norm, a, 1)73 self.assertRaises (ValueError, alpha_norm, a, 1)
71 # check 2d array fails74 # check 2d array fails
72 a = array([[2],[4]], dtype = 'float32')75 a = array([[2],[4]], dtype = float_type)
73 self.assertRaises (ValueError, alpha_norm, a, 1)76 self.assertRaises (ValueError, alpha_norm, a, 1)
74 # check 1d array77 # check 1d array
75 a = array(range(10), dtype = 'float32')78 a = array(range(10), dtype = float_type)
76 self.assertEqual (alpha_norm(a, 1), 4.5)79 self.assertEqual (alpha_norm(a, 1), 4.5)
77 80
78 def test_alpha_norm_of_array_of_int(self):81 def test_alpha_norm_of_array_of_int(self):
@@ -88,31 +91,31 @@ class aubio_fvec_test_case(TestCase): · 9 unmodified lines
88 self.assertRaises (ValueError, alpha_norm, a, 1)91 self.assertRaises (ValueError, alpha_norm, a, 1)
89 92
90 def test_zero_crossing_rate(self):93 def test_zero_crossing_rate(self):
91 a = array([0,1,-1], dtype='float32')94 a = array([0,1,-1], dtype=float_type)
92 assert_almost_equal (zero_crossing_rate(a), 1./3. )95 assert_almost_equal (zero_crossing_rate(a), 1./3. )
93 a = array([0.]*100, dtype='float32')96 a = array([0.]*100, dtype=float_type)
94 self.assertEqual (zero_crossing_rate(a), 0 )97 self.assertEqual (zero_crossing_rate(a), 0 )
95 a = array([-1.]*100, dtype='float32')98 a = array([-1.]*100, dtype=float_type)
96 self.assertEqual (zero_crossing_rate(a), 0 )99 self.assertEqual (zero_crossing_rate(a), 0 )
97 a = array([1.]*100, dtype='float32')100 a = array([1.]*100, dtype=float_type)
98 self.assertEqual (zero_crossing_rate(a), 0 )101 self.assertEqual (zero_crossing_rate(a), 0 )
99 102
100 def test_alpha_norm_of_array_of_float64(self):103 def test_alpha_norm_of_array_of_float64(self):
101 # check scalar fail104 # check scalar fail
102 a = array(1, dtype = 'float64')105 a = array(1, dtype = wrong_type)
103 self.assertRaises (ValueError, alpha_norm, a, 1)106 self.assertRaises (ValueError, alpha_norm, a, 1)
104 # check 3d array fail107 # check 3d array fail
105 a = array([[[1,2],[3,4]]], dtype = 'float64')108 a = array([[[1,2],[3,4]]], dtype = wrong_type)
106 self.assertRaises (ValueError, alpha_norm, a, 1)109 self.assertRaises (ValueError, alpha_norm, a, 1)
107 # check float64 1d array fail110 # check float64 1d array fail
108 a = array(list(range(10)), dtype = 'float64')111 a = array(list(range(10)), dtype = wrong_type)
109 self.assertRaises (ValueError, alpha_norm, a, 1)112 self.assertRaises (ValueError, alpha_norm, a, 1)
110 # check float64 2d array fail113 # check float64 2d array fail
111 a = array([list(range(10)), list(range(10))], dtype = 'float64')114 a = array([list(range(10)), list(range(10))], dtype = wrong_type)
112 self.assertRaises (ValueError, alpha_norm, a, 1)115 self.assertRaises (ValueError, alpha_norm, a, 1)
113 116
114 def test_fvec_min_removal_of_array(self):117 def test_fvec_min_removal_of_array(self):
115 a = array([20,1,19], dtype='float32')118 a = array([20,1,19], dtype=float_type)
116 b = min_removal(a)119 b = min_removal(a)
117 assert_equal (array(b), [19, 0, 18])120 assert_equal (array(b), [19, 0, 18])
118 assert_equal (b, [19, 0, 18])121 assert_equal (b, [19, 0, 18])
@@ -121,12 +124,12 @@ class aubio_fvec_test_case(TestCase): · 2 unmodified lines
121 assert_equal (a, b)124 assert_equal (a, b)
122 125
123 def test_fvec_min_removal_of_array_float64(self):126 def test_fvec_min_removal_of_array_float64(self):
124 a = array([20,1,19], dtype='float64')127 a = array([20,1,19], dtype=wrong_type)
125 self.assertRaises (ValueError, min_removal, a)128 self.assertRaises (ValueError, min_removal, a)
126 129
127 def test_fvec_min_removal_of_fvec(self):130 def test_fvec_min_removal_of_fvec(self):
128 a = fvec(3)131 a = fvec(3)
129 a = array([20, 1, 19], dtype = 'float32')132 a = array([20, 1, 19], dtype = float_type)
130 b = min_removal(a)133 b = min_removal(a)
131 assert_equal (array(b), [19, 0, 18])134 assert_equal (array(b), [19, 0, 18])
132 assert_equal (b, [19, 0, 18])135 assert_equal (b, [19, 0, 18])
python/tests/test_musicutils.py+5−5
@@ -7,7 +7,7 @@ from math import pi · 6 unmodified lines
7 7
8from aubio import window, level_lin, db_spl, silence_detection, level_detection8from aubio import window, level_lin, db_spl, silence_detection, level_detection
9 9
10from aubio import fvec10from aubio import fvec, float_type
11 11
12class aubio_window(TestCase):12class aubio_window(TestCase):
13 13
@@ -53,7 +53,7 @@ class aubio_level_lin(TestCase): · 39 unmodified lines
53 53
54 def test_minus_ones_is_one(self):54 def test_minus_ones_is_one(self):
55 from numpy import ones55 from numpy import ones
56 assert_equal(level_lin(-ones(1024, dtype="float32")), 1.)56 assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.)
57 57
58class aubio_db_spl(TestCase):58class aubio_db_spl(TestCase):
59 def test_accept_fvec(self):59 def test_accept_fvec(self):
@@ -73,7 +73,7 @@ class aubio_db_spl(TestCase): · 13 unmodified lines
73 73
74 def test_minus_ones_is_zero(self):74 def test_minus_ones_is_zero(self):
75 from numpy import ones75 from numpy import ones
76 assert_equal(db_spl(-ones(1024, dtype="float32")), 0.)76 assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.)
77 77
78class aubio_silence_detection(TestCase):78class aubio_silence_detection(TestCase):
79 def test_accept_fvec(self):79 def test_accept_fvec(self):
@@ -93,7 +93,7 @@ class aubio_silence_detection(TestCase): · 13 unmodified lines
93 93
94 def test_minus_ones_is_zero(self):94 def test_minus_ones_is_zero(self):
95 from numpy import ones95 from numpy import ones
96 assert silence_detection(ones(1024, dtype="float32"), -70) == 096 assert silence_detection(ones(1024, dtype = float_type), -70) == 0
97 97
98class aubio_level_detection(TestCase):98class aubio_level_detection(TestCase):
99 def test_accept_fvec(self):99 def test_accept_fvec(self):
@@ -113,7 +113,7 @@ class aubio_level_detection(TestCase): · 13 unmodified lines
113 113
114 def test_minus_ones_is_zero(self):114 def test_minus_ones_is_zero(self):
115 from numpy import ones115 from numpy import ones
116 assert level_detection(ones(1024, dtype="float32"), -70) == 0116 assert level_detection(ones(1024, dtype = float_type), -70) == 0
117 117
118if __name__ == '__main__':118if __name__ == '__main__':
119 from unittest import main119 from unittest import main
python/tests/test_pitch.py+2−2
@@ -4,7 +4,7 @@ from unittest import TestCase · 3 unmodified lines
4from numpy.testing import assert_equal, assert_almost_equal4from numpy.testing import assert_equal, assert_almost_equal
5from numpy import random, sin, arange, mean, median, isnan5from numpy import random, sin, arange, mean, median, isnan
6from math import pi6from math import pi
7from aubio import fvec, pitch, freqtomidi7from aubio import fvec, pitch, freqtomidi, float_type
8 8
9class aubio_pitch_Good_Values(TestCase):9class aubio_pitch_Good_Values(TestCase):
10 10
@@ -50,7 +50,7 @@ class aubio_pitch_Sinusoid(TestCase): · 39 unmodified lines
50 self.run_pitch(p, sinvec, freq)50 self.run_pitch(p, sinvec, freq)
51 51
52 def build_sinusoid(self, length, freq, samplerate):52 def build_sinusoid(self, length, freq, samplerate):
53 return sin( 2. * pi * arange(length).astype('float32') * freq / samplerate)53 return sin( 2. * pi * arange(length).astype(float_type) * freq / samplerate)
54 54
55 def run_pitch(self, p, input_vec, freq):55 def run_pitch(self, p, input_vec, freq):
56 count = 056 count = 0
python/tests/test_specdesc.py+25−25
@@ -2,7 +2,7 @@ · 1 unmodified line
2 2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from numpy import random, arange, log, zeros4from numpy import random, arange, log, zeros
5from aubio import specdesc, cvec5from aubio import specdesc, cvec, float_type
6from math import pi6from math import pi
7 7
8methods = ["default",8methods = ["default",
@@ -37,8 +37,8 @@ class aubio_specdesc(TestCase): · 28 unmodified lines
37 spec.norm[1] = 1./2.37 spec.norm[1] = 1./2.
38 #print "%20s" % method, str(o(spec))38 #print "%20s" % method, str(o(spec))
39 o(spec)39 o(spec)
40 spec.norm = random.random_sample((len(spec.norm),)).astype('float32')40 spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
41 spec.phas = random.random_sample((len(spec.phas),)).astype('float32')41 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
42 #print "%20s" % method, str(o(spec))42 #print "%20s" % method, str(o(spec))
43 assert (o(spec) != 0.)43 assert (o(spec) != 0.)
44 44
@@ -60,7 +60,7 @@ class aubio_specdesc(TestCase): · 15 unmodified lines
60 spec = cvec(buf_size)60 spec = cvec(buf_size)
61 # phase of zeros is zero61 # phase of zeros is zero
62 assert_equal (o(spec), 0.)62 assert_equal (o(spec), 0.)
63 spec.phas = random.random_sample((len(spec.phas),)).astype('float32')63 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
64 # phase of random is not zero64 # phase of random is not zero
65 spec.norm[:] = 165 spec.norm[:] = 1
66 assert (o(spec) != 0.)66 assert (o(spec) != 0.)
@@ -70,7 +70,7 @@ class aubio_specdesc(TestCase): · 3 unmodified lines
70 spec = cvec(buf_size)70 spec = cvec(buf_size)
71 # specdiff of zeros is zero71 # specdiff of zeros is zero
72 assert_equal (o(spec), 0.)72 assert_equal (o(spec), 0.)
73 spec.phas = random.random_sample((len(spec.phas),)).astype('float32')73 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
74 # phase of random is not zero74 # phase of random is not zero
75 spec.norm[:] = 175 spec.norm[:] = 1
76 assert (o(spec) != 0.)76 assert (o(spec) != 0.)
@@ -79,7 +79,7 @@ class aubio_specdesc(TestCase): · 2 unmodified lines
79 o = specdesc("hfc")79 o = specdesc("hfc")
80 c = cvec()80 c = cvec()
81 assert_equal( 0., o(c))81 assert_equal( 0., o(c))
82 a = arange(c.length, dtype='float32')82 a = arange(c.length, dtype=float_type)
83 c.norm = a83 c.norm = a
84 assert_equal (a, c.norm)84 assert_equal (a, c.norm)
85 assert_equal ( sum(a*(a+1)), o(c))85 assert_equal ( sum(a*(a+1)), o(c))
@@ -88,7 +88,7 @@ class aubio_specdesc(TestCase): · 2 unmodified lines
88 o = specdesc("complex")88 o = specdesc("complex")
89 c = cvec()89 c = cvec()
90 assert_equal( 0., o(c))90 assert_equal( 0., o(c))
91 a = arange(c.length, dtype='float32')91 a = arange(c.length, dtype=float_type)
92 c.norm = a92 c.norm = a
93 assert_equal (a, c.norm)93 assert_equal (a, c.norm)
94 # the previous run was on zeros, so previous frames are still 094 # the previous run was on zeros, so previous frames are still 0
@@ -101,7 +101,7 @@ class aubio_specdesc(TestCase): · 6 unmodified lines
101 o = specdesc("kl")101 o = specdesc("kl")
102 c = cvec()102 c = cvec()
103 assert_equal( 0., o(c))103 assert_equal( 0., o(c))
104 a = arange(c.length, dtype='float32')104 a = arange(c.length, dtype=float_type)
105 c.norm = a105 c.norm = a
106 assert_almost_equal( sum(a * log(1.+ a/1.e-1 ) ) / o(c), 1., decimal=6)106 assert_almost_equal( sum(a * log(1.+ a/1.e-1 ) ) / o(c), 1., decimal=6)
107 107
@@ -109,7 +109,7 @@ class aubio_specdesc(TestCase): · 1 unmodified line
109 o = specdesc("mkl")109 o = specdesc("mkl")
110 c = cvec()110 c = cvec()
111 assert_equal( 0., o(c))111 assert_equal( 0., o(c))
112 a = arange(c.length, dtype='float32')112 a = arange(c.length, dtype=float_type)
113 c.norm = a113 c.norm = a
114 assert_almost_equal( sum(log(1.+ a/1.e-1 ) ) / o(c), 1, decimal=6)114 assert_almost_equal( sum(log(1.+ a/1.e-1 ) ) / o(c), 1, decimal=6)
115 115
@@ -117,11 +117,11 @@ class aubio_specdesc(TestCase): · 1 unmodified line
117 o = specdesc("specflux")117 o = specdesc("specflux")
118 c = cvec()118 c = cvec()
119 assert_equal( 0., o(c))119 assert_equal( 0., o(c))
120 a = arange(c.length, dtype='float32')120 a = arange(c.length, dtype=float_type)
121 c.norm = a121 c.norm = a
122 assert_equal( sum(a), o(c))122 assert_equal( sum(a), o(c))
123 assert_equal( 0, o(c))123 assert_equal( 0, o(c))
124 c.norm = zeros(c.length, dtype='float32')124 c.norm = zeros(c.length, dtype=float_type)
125 assert_equal( 0, o(c))125 assert_equal( 0, o(c))
126 126
127 def test_centroid(self):127 def test_centroid(self):
@@ -129,7 +129,7 @@ class aubio_specdesc(TestCase): · 1 unmodified line
129 c = cvec()129 c = cvec()
130 # make sure centroid of zeros is zero130 # make sure centroid of zeros is zero
131 assert_equal( 0., o(c))131 assert_equal( 0., o(c))
132 a = arange(c.length, dtype='float32')132 a = arange(c.length, dtype=float_type)
133 c.norm = a133 c.norm = a
134 centroid = sum(a*a) / sum(a)134 centroid = sum(a*a) / sum(a)
135 assert_almost_equal (centroid, o(c), decimal = 2)135 assert_almost_equal (centroid, o(c), decimal = 2)
@@ -140,7 +140,7 @@ class aubio_specdesc(TestCase): · 4 unmodified lines
140 def test_spread(self):140 def test_spread(self):
141 o = specdesc("spread")141 o = specdesc("spread")
142 c = cvec(2048)142 c = cvec(2048)
143 ramp = arange(c.length, dtype='float32')143 ramp = arange(c.length, dtype=float_type)
144 assert_equal( 0., o(c))144 assert_equal( 0., o(c))
145 145
146 a = ramp146 a = ramp
@@ -153,7 +153,7 @@ class aubio_specdesc(TestCase): · 6 unmodified lines
153 o = specdesc("skewness")153 o = specdesc("skewness")
154 c = cvec()154 c = cvec()
155 assert_equal( 0., o(c))155 assert_equal( 0., o(c))
156 a = arange(c.length, dtype='float32')156 a = arange(c.length, dtype=float_type)
157 c.norm = a157 c.norm = a
158 centroid = sum(a*a) / sum(a)158 centroid = sum(a*a) / sum(a)
159 spread = sum( (a - centroid)**2 *a) / sum(a)159 spread = sum( (a - centroid)**2 *a) / sum(a)
@@ -167,7 +167,7 @@ class aubio_specdesc(TestCase): · 7 unmodified lines
167 o = specdesc("kurtosis")167 o = specdesc("kurtosis")
168 c = cvec()168 c = cvec()
169 assert_equal( 0., o(c))169 assert_equal( 0., o(c))
170 a = arange(c.length, dtype='float32')170 a = arange(c.length, dtype=float_type)
171 c.norm = a171 c.norm = a
172 centroid = sum(a*a) / sum(a)172 centroid = sum(a*a) / sum(a)
173 spread = sum( (a - centroid)**2 *a) / sum(a)173 spread = sum( (a - centroid)**2 *a) / sum(a)
@@ -178,22 +178,22 @@ class aubio_specdesc(TestCase): · 4 unmodified lines
178 o = specdesc("slope")178 o = specdesc("slope")
179 c = cvec()179 c = cvec()
180 assert_equal( 0., o(c))180 assert_equal( 0., o(c))
181 a = arange(c.length * 2, 0, -2, dtype='float32')181 a = arange(c.length * 2, 0, -2, dtype=float_type)
182 k = arange(c.length, dtype='float32')182 k = arange(c.length, dtype=float_type)
183 c.norm = a183 c.norm = a
184 num = len(a) * sum(k*a) - sum(k)*sum(a)184 num = len(a) * sum(k*a) - sum(k)*sum(a)
185 den = (len(a) * sum(k**2) - sum(k)**2)185 den = (len(a) * sum(k**2) - sum(k)**2)
186 slope = num/den/sum(a)186 slope = num/den/sum(a)
187 assert_almost_equal (slope, o(c), decimal = 5)187 assert_almost_equal (slope, o(c), decimal = 5)
188 188
189 a = arange(0, c.length * 2, +2, dtype='float32')189 a = arange(0, c.length * 2, +2, dtype=float_type)
190 c.norm = a190 c.norm = a
191 num = len(a) * sum(k*a) - sum(k)*sum(a)191 num = len(a) * sum(k*a) - sum(k)*sum(a)
192 den = (len(a) * sum(k**2) - sum(k)**2)192 den = (len(a) * sum(k**2) - sum(k)**2)
193 slope = num/den/sum(a)193 slope = num/den/sum(a)
194 assert_almost_equal (slope, o(c), decimal = 5)194 assert_almost_equal (slope, o(c), decimal = 5)
195 195
196 a = arange(0, c.length * 2, +2, dtype='float32')196 a = arange(0, c.length * 2, +2, dtype=float_type)
197 c.norm = a * 2197 c.norm = a * 2
198 assert_almost_equal (slope, o(c), decimal = 5)198 assert_almost_equal (slope, o(c), decimal = 5)
199 199
@@ -201,18 +201,18 @@ class aubio_specdesc(TestCase): · 1 unmodified line
201 o = specdesc("decrease")201 o = specdesc("decrease")
202 c = cvec()202 c = cvec()
203 assert_equal( 0., o(c))203 assert_equal( 0., o(c))
204 a = arange(c.length * 2, 0, -2, dtype='float32')204 a = arange(c.length * 2, 0, -2, dtype=float_type)
205 k = arange(c.length, dtype='float32')205 k = arange(c.length, dtype=float_type)
206 c.norm = a206 c.norm = a
207 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:]) 207 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:])
208 assert_almost_equal (decrease, o(c), decimal = 5)208 assert_almost_equal (decrease, o(c), decimal = 5)
209 209
210 a = arange(0, c.length * 2, +2, dtype='float32')210 a = arange(0, c.length * 2, +2, dtype=float_type)
211 c.norm = a211 c.norm = a
212 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:]) 212 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:])
213 assert_almost_equal (decrease, o(c), decimal = 5)213 assert_almost_equal (decrease, o(c), decimal = 5)
214 214
215 a = arange(0, c.length * 2, +2, dtype='float32')215 a = arange(0, c.length * 2, +2, dtype=float_type)
216 c.norm = a * 2216 c.norm = a * 2
217 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:]) 217 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:])
218 assert_almost_equal (decrease, o(c), decimal = 5)218 assert_almost_equal (decrease, o(c), decimal = 5)
@@ -221,8 +221,8 @@ class aubio_specdesc(TestCase): · 2 unmodified lines
221 o = specdesc("rolloff")221 o = specdesc("rolloff")
222 c = cvec()222 c = cvec()
223 assert_equal( 0., o(c))223 assert_equal( 0., o(c))
224 a = arange(c.length * 2, 0, -2, dtype='float32')224 a = arange(c.length * 2, 0, -2, dtype=float_type)
225 k = arange(c.length, dtype='float32')225 k = arange(c.length, dtype=float_type)
226 c.norm = a226 c.norm = a
227 cumsum = .95*sum(a*a)227 cumsum = .95*sum(a*a)
228 i = 0; rollsum = 0228 i = 0; rollsum = 0

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