Changeset c4b2183 for python/tests/test_specdesc.py
 Timestamp:
 Apr 25, 2016, 12:53:03 AM (4 years ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
 Children:
 8bffcff
 Parents:
 fbcee4f
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

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.e1 ) ) / 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.e1 ) ) / 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.