5 from numpy.testing import TestCase, assert_almost_equal
8 class aubio_dct(TestCase):
11 """ check aubio.dct() can be created """
13 self.assertEqual(a_dct.size, 1024)
15 def test_arange(self):
16 """ test that dct(arange(8)) is computed correctly
18 >>> from scipy.fftpack import dct
19 >>> a_in = np.arange(8).astype('float32')
20 >>> precomputed = dct(a_in, norm='ortho')
22 precomputed = [ 9.89949512, -6.44232273, 0., -0.67345482, 0.,
23 -0.20090288, 0., -0.05070186]
25 a_in = np.arange(8).astype('float32')
26 a_expected = aubio.fvec(precomputed)
27 assert_almost_equal(a_dct(a_in), a_expected, decimal=6)
29 def test_some_ones(self):
30 """ 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]
36 a_in = np.ones(16).astype('float32')
39 a_expected = aubio.fvec(precomputed)
40 assert_almost_equal(a_dct(a_in), a_expected, decimal=7)
42 def test_reconstruction(self):
44 a_in = np.ones(16).astype('float32')
47 a_dct_in = a_dct(a_in)
48 a_dct_reconstructed = a_dct.rdo(a_dct_in)
49 assert_almost_equal(a_dct_reconstructed, a_in, decimal=6)
51 def test_negative_size(self):
52 with self.assertRaises(ValueError):
55 def test_wrong_size(self):
56 # supports for non 2** fft sizes only when compiled with fftw3
58 with self.assertRaises(RuntimeError):
60 except AssertionError:
61 self.skipTest('creating aubio.dct with size %d did not fail' % win_s)