Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -5,10 +5,18 @@ import numpy as np · 4 unmodified lines | |||
| 5 | from numpy.testing import TestCase, assert_almost_equal | 5 | from numpy.testing import TestCase, assert_almost_equal |
| 6 | import aubio | 6 | import aubio |
| 7 | 7 | ||
| 8 | precomputed_arange = [ 9.89949512, -6.44232273, 0., -0.67345482, 0., | ||
| 9 | -0.20090288, 0., -0.05070186] | ||
| 10 | |||
| 11 | precomputed_some_ones = [ 4.28539848, 0.2469689, -0.14625292, -0.58121818, | ||
| 12 | -0.83483052, -0.75921834, -0.35168475, 0.24087936, | ||
| 13 | 0.78539824, 1.06532764, 0.97632152, 0.57164496, 0.03688532, | ||
| 14 | -0.39446154, -0.54619485, -0.37771079] | ||
| 15 | |||
| 8 | class aubio_dct(TestCase): | 16 | class aubio_dct(TestCase): |
| 9 | 17 | ||
| 10 | def test_init(self): | 18 | def test_init(self): |
| 11 | """ check aubio.dct() can be created """ | 19 | """ test that aubio.dct() is created with expected size """ |
| 12 | a_dct = aubio.dct() | 20 | a_dct = aubio.dct() |
| 13 | self.assertEqual(a_dct.size, 1024) | 21 | self.assertEqual(a_dct.size, 1024) |
| 14 | 22 | ||
| @@ -19,27 +27,23 @@ class aubio_dct(TestCase): · 4 unmodified lines | |||
| 19 | >>> a_in = np.arange(8).astype('float32') | 27 | >>> a_in = np.arange(8).astype('float32') |
| 20 | >>> precomputed = dct(a_in, norm='ortho') | 28 | >>> precomputed = dct(a_in, norm='ortho') |
| 21 | """ | 29 | """ |
| 22 | precomputed = [ 9.89949512, -6.44232273, 0., -0.67345482, 0., | 30 | N = len(precomputed_arange) |
| 23 | -0.20090288, 0., -0.05070186] | ||
| 24 | a_dct = aubio.dct(8) | 31 | a_dct = aubio.dct(8) |
| 25 | a_in = np.arange(8).astype('float32') | 32 | a_in = np.arange(8).astype('float32') |
| 26 | a_expected = aubio.fvec(precomputed) | 33 | a_expected = aubio.fvec(precomputed_arange) |
| 27 | assert_almost_equal(a_dct(a_in), a_expected, decimal=6) | 34 | assert_almost_equal(a_dct(a_in), a_expected, decimal=6) |
| 28 | 35 | ||
| 29 | def test_some_ones(self): | 36 | def test_some_ones(self): |
| 30 | """ test that dct(somevector) is computed correctly """ | 37 | """ test that dct(somevector) is computed correctly """ |
| 31 | precomputed = [ 4.28539848, 0.2469689, -0.14625292, -0.58121818, | ||
| 32 | -0.83483052, -0.75921834, -0.35168475, 0.24087936, | ||
| 33 | 0.78539824, 1.06532764, 0.97632152, 0.57164496, 0.03688532, | ||
| 34 | -0.39446154, -0.54619485, -0.37771079] | ||
| 35 | a_dct = aubio.dct(16) | 38 | a_dct = aubio.dct(16) |
| 36 | a_in = np.ones(16).astype('float32') | 39 | a_in = np.ones(16).astype('float32') |
| 37 | a_in[1] = 0 | 40 | a_in[1] = 0 |
| 38 | a_in[3] = np.pi | 41 | a_in[3] = np.pi |
| 39 | a_expected = aubio.fvec(precomputed) | 42 | a_expected = aubio.fvec(precomputed_some_ones) |
| 40 | assert_almost_equal(a_dct(a_in), a_expected, decimal=7) | 43 | assert_almost_equal(a_dct(a_in), a_expected, decimal=7) |
| 41 | 44 | ||
| 42 | def test_reconstruction(self): | 45 | def test_reconstruction(self): |
| 46 | """ test that some_ones vector can be recontructed """ | ||
| 43 | a_dct = aubio.dct(16) | 47 | a_dct = aubio.dct(16) |
| 44 | a_in = np.ones(16).astype('float32') | 48 | a_in = np.ones(16).astype('float32') |
| 45 | a_in[1] = 0 | 49 | a_in[1] = 0 |
| @@ -49,10 +53,12 @@ class aubio_dct(TestCase): · 3 unmodified lines | |||
| 49 | assert_almost_equal(a_dct_reconstructed, a_in, decimal=6) | 53 | assert_almost_equal(a_dct_reconstructed, a_in, decimal=6) |
| 50 | 54 | ||
| 51 | def test_negative_size(self): | 55 | def test_negative_size(self): |
| 56 | """ test that creation fails with a negative size """ | ||
| 52 | with self.assertRaises(ValueError): | 57 | with self.assertRaises(ValueError): |
| 53 | aubio.dct(-1) | 58 | aubio.dct(-1) |
| 54 | 59 | ||
| 55 | def test_wrong_size(self): | 60 | def test_wrong_size(self): |
| 61 | """ test that creation fails with a non power-of-two size """ | ||
| 56 | # supports for non 2** fft sizes only when compiled with fftw3 | 62 | # supports for non 2** fft sizes only when compiled with fftw3 |
| 57 | try: | 63 | try: |
| 58 | with self.assertRaises(RuntimeError): | 64 | with self.assertRaises(RuntimeError): |