- Timestamp:
- Apr 25, 2016, 12:53:03 AM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 8bffcff
- Parents:
- fbcee4f
- Location:
- python/tests
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_filterbank.py
rfbcee4f rc4b2183 6 6 from math import pi 7 7 from numpy import array 8 from aubio import cvec, filterbank 8 from aubio import cvec, filterbank, float_type 9 9 from utils import array_from_text_file 10 10 … … 17 17 def test_set_coeffs(self): 18 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 20 f.set_coeffs(r) 21 21 assert_equal (r, f.get_coeffs()) … … 36 36 f = filterbank(40, 512) 37 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 39 assert_equal( f(c), 0) 40 40 … … 42 42 f = filterbank(40, 512) 43 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 45 r /= r.sum() 46 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 48 assert_equal ( f(c) < 1., True ) 49 49 assert_equal ( f(c) > 0., True ) … … 53 53 c = cvec(512) 54 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 56 assert_equal ( f(c) < 1., True ) 57 57 assert_equal ( f(c) > 0., True ) -
python/tests/test_filterbank_mel.py
rfbcee4f rc4b2183 4 4 from numpy.testing import assert_equal, assert_almost_equal 5 5 from numpy import array, shape 6 from aubio import cvec, filterbank 6 from aubio import cvec, filterbank, float_type 7 7 8 8 class aubio_filterbank_mel_test_case(TestCase): … … 28 28 f = filterbank(9, 1024) 29 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 31 f.set_triangle_bands(freqs, 48000) 32 32 f.get_coeffs().T … … 36 36 f = filterbank(9, 1024) 37 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 39 f.set_triangle_bands(freqs, 48000) 40 40 f.get_coeffs().T -
python/tests/test_fvec.py
rfbcee4f rc4b2183 4 4 from numpy.testing import assert_equal, assert_almost_equal 5 5 from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal 6 from aubio import float_type 6 7 from numpy import array, shape 8 9 wrong_type = 'float32' if float_type == 'float64' else 'float64' 7 10 8 11 default_size = 512 … … 12 15 def test_vector_created_with_zeroes(self): 13 16 a = fvec(10) 14 assert a.dtype == 'float32'17 assert a.dtype == float_type 15 18 assert a.shape == (10,) 16 19 assert_equal (a, 0) … … 18 21 def test_vector_create_with_list(self): 19 22 a = fvec([0,1,2,3]) 20 assert a.dtype == 'float32'23 assert a.dtype == float_type 21 24 assert a.shape == (4,) 22 25 assert_equal (list(range(4)), a) … … 58 61 a[1] = 1 59 62 self.assertEqual (alpha_norm(a, 1), 1) 60 a = array([0, 1], dtype= 'float32')63 a = array([0, 1], dtype=float_type) 61 64 from math import sqrt 62 65 assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.) … … 67 70 def test_alpha_norm_of_array_of_float32(self): 68 71 # check scalar fails 69 a = array(1, dtype = 'float32')72 a = array(1, dtype = float_type) 70 73 self.assertRaises (ValueError, alpha_norm, a, 1) 71 74 # check 2d array fails 72 a = array([[2],[4]], dtype = 'float32')75 a = array([[2],[4]], dtype = float_type) 73 76 self.assertRaises (ValueError, alpha_norm, a, 1) 74 77 # check 1d array 75 a = array(range(10), dtype = 'float32')78 a = array(range(10), dtype = float_type) 76 79 self.assertEqual (alpha_norm(a, 1), 4.5) 77 80 … … 89 92 90 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 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 97 self.assertEqual (zero_crossing_rate(a), 0 ) 95 a = array([-1.]*100, dtype= 'float32')98 a = array([-1.]*100, dtype=float_type) 96 99 self.assertEqual (zero_crossing_rate(a), 0 ) 97 a = array([1.]*100, dtype= 'float32')100 a = array([1.]*100, dtype=float_type) 98 101 self.assertEqual (zero_crossing_rate(a), 0 ) 99 102 100 103 def test_alpha_norm_of_array_of_float64(self): 101 104 # check scalar fail 102 a = array(1, dtype = 'float64')105 a = array(1, dtype = wrong_type) 103 106 self.assertRaises (ValueError, alpha_norm, a, 1) 104 107 # check 3d array fail 105 a = array([[[1,2],[3,4]]], dtype = 'float64')108 a = array([[[1,2],[3,4]]], dtype = wrong_type) 106 109 self.assertRaises (ValueError, alpha_norm, a, 1) 107 110 # check float64 1d array fail 108 a = array(list(range(10)), dtype = 'float64')111 a = array(list(range(10)), dtype = wrong_type) 109 112 self.assertRaises (ValueError, alpha_norm, a, 1) 110 113 # 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 115 self.assertRaises (ValueError, alpha_norm, a, 1) 113 116 114 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 119 b = min_removal(a) 117 120 assert_equal (array(b), [19, 0, 18]) … … 122 125 123 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 128 self.assertRaises (ValueError, min_removal, a) 126 129 127 130 def test_fvec_min_removal_of_fvec(self): 128 131 a = fvec(3) 129 a = array([20, 1, 19], dtype = 'float32')132 a = array([20, 1, 19], dtype = float_type) 130 133 b = min_removal(a) 131 134 assert_equal (array(b), [19, 0, 18]) -
python/tests/test_musicutils.py
rfbcee4f rc4b2183 8 8 from aubio import window, level_lin, db_spl, silence_detection, level_detection 9 9 10 from aubio import fvec 10 from aubio import fvec, float_type 11 11 12 12 class aubio_window(TestCase): … … 54 54 def test_minus_ones_is_one(self): 55 55 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 58 58 class aubio_db_spl(TestCase): … … 74 74 def test_minus_ones_is_zero(self): 75 75 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 78 78 class aubio_silence_detection(TestCase): … … 94 94 def test_minus_ones_is_zero(self): 95 95 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 98 98 class aubio_level_detection(TestCase): … … 114 114 def test_minus_ones_is_zero(self): 115 115 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 118 118 if __name__ == '__main__': -
python/tests/test_pitch.py
rfbcee4f rc4b2183 5 5 from numpy import random, sin, arange, mean, median, isnan 6 6 from math import pi 7 from aubio import fvec, pitch, freqtomidi 7 from aubio import fvec, pitch, freqtomidi, float_type 8 8 9 9 class aubio_pitch_Good_Values(TestCase): … … 51 51 52 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 55 def run_pitch(self, p, input_vec, freq): -
python/tests/test_specdesc.py
rfbcee4f rc4b2183 3 3 from numpy.testing import TestCase, assert_equal, assert_almost_equal 4 4 from numpy import random, arange, log, zeros 5 from aubio import specdesc, cvec 5 from aubio import specdesc, cvec, float_type 6 6 from math import pi 7 7 … … 38 38 #print "%20s" % method, str(o(spec)) 39 39 o(spec) 40 spec.norm = random.random_sample((len(spec.norm),)).astype( 'float32')41 spec.phas = random.random_sample((len(spec.phas),)).astype( 'float32')40 spec.norm = random.random_sample((len(spec.norm),)).astype(float_type) 41 spec.phas = random.random_sample((len(spec.phas),)).astype(float_type) 42 42 #print "%20s" % method, str(o(spec)) 43 43 assert (o(spec) != 0.) … … 61 61 # phase of zeros is zero 62 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 64 # phase of random is not zero 65 65 spec.norm[:] = 1 … … 71 71 # specdiff of zeros is zero 72 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 74 # phase of random is not zero 75 75 spec.norm[:] = 1 … … 80 80 c = cvec() 81 81 assert_equal( 0., o(c)) 82 a = arange(c.length, dtype= 'float32')82 a = arange(c.length, dtype=float_type) 83 83 c.norm = a 84 84 assert_equal (a, c.norm) … … 89 89 c = cvec() 90 90 assert_equal( 0., o(c)) 91 a = arange(c.length, dtype= 'float32')91 a = arange(c.length, dtype=float_type) 92 92 c.norm = a 93 93 assert_equal (a, c.norm) … … 102 102 c = cvec() 103 103 assert_equal( 0., o(c)) 104 a = arange(c.length, dtype= 'float32')104 a = arange(c.length, dtype=float_type) 105 105 c.norm = a 106 106 assert_almost_equal( sum(a * log(1.+ a/1.e-1 ) ) / o(c), 1., decimal=6) … … 110 110 c = cvec() 111 111 assert_equal( 0., o(c)) 112 a = arange(c.length, dtype= 'float32')112 a = arange(c.length, dtype=float_type) 113 113 c.norm = a 114 114 assert_almost_equal( sum(log(1.+ a/1.e-1 ) ) / o(c), 1, decimal=6) … … 118 118 c = cvec() 119 119 assert_equal( 0., o(c)) 120 a = arange(c.length, dtype= 'float32')120 a = arange(c.length, dtype=float_type) 121 121 c.norm = a 122 122 assert_equal( sum(a), o(c)) 123 123 assert_equal( 0, o(c)) 124 c.norm = zeros(c.length, dtype= 'float32')124 c.norm = zeros(c.length, dtype=float_type) 125 125 assert_equal( 0, o(c)) 126 126 … … 130 130 # make sure centroid of zeros is zero 131 131 assert_equal( 0., o(c)) 132 a = arange(c.length, dtype= 'float32')132 a = arange(c.length, dtype=float_type) 133 133 c.norm = a 134 134 centroid = sum(a*a) / sum(a) … … 141 141 o = specdesc("spread") 142 142 c = cvec(2048) 143 ramp = arange(c.length, dtype= 'float32')143 ramp = arange(c.length, dtype=float_type) 144 144 assert_equal( 0., o(c)) 145 145 … … 154 154 c = cvec() 155 155 assert_equal( 0., o(c)) 156 a = arange(c.length, dtype= 'float32')156 a = arange(c.length, dtype=float_type) 157 157 c.norm = a 158 158 centroid = sum(a*a) / sum(a) … … 168 168 c = cvec() 169 169 assert_equal( 0., o(c)) 170 a = arange(c.length, dtype= 'float32')170 a = arange(c.length, dtype=float_type) 171 171 c.norm = a 172 172 centroid = sum(a*a) / sum(a) … … 179 179 c = cvec() 180 180 assert_equal( 0., o(c)) 181 a = arange(c.length * 2, 0, -2, dtype= 'float32')182 k = arange(c.length, dtype= 'float32')181 a = arange(c.length * 2, 0, -2, dtype=float_type) 182 k = arange(c.length, dtype=float_type) 183 183 c.norm = a 184 184 num = len(a) * sum(k*a) - sum(k)*sum(a) … … 187 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 190 c.norm = a 191 191 num = len(a) * sum(k*a) - sum(k)*sum(a) … … 194 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 197 c.norm = a * 2 198 198 assert_almost_equal (slope, o(c), decimal = 5) … … 202 202 c = cvec() 203 203 assert_equal( 0., o(c)) 204 a = arange(c.length * 2, 0, -2, dtype= 'float32')205 k = arange(c.length, dtype= 'float32')204 a = arange(c.length * 2, 0, -2, dtype=float_type) 205 k = arange(c.length, dtype=float_type) 206 206 c.norm = a 207 207 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:]) 208 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 211 c.norm = a 212 212 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:]) 213 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 216 c.norm = a * 2 217 217 decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:]) … … 222 222 c = cvec() 223 223 assert_equal( 0., o(c)) 224 a = arange(c.length * 2, 0, -2, dtype= 'float32')225 k = arange(c.length, dtype= 'float32')224 a = arange(c.length * 2, 0, -2, dtype=float_type) 225 k = arange(c.length, dtype=float_type) 226 226 c.norm = a 227 227 cumsum = .95*sum(a*a)
Note: See TracChangeset
for help on using the changeset viewer.