Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/fft/tests/test_fftpack.py @ 87:2a2c65a20a8b
Add Python libs and headers
author | Chris Cannam |
---|---|
date | Wed, 25 Feb 2015 14:05:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
86:413a9d26189e | 87:2a2c65a20a8b |
---|---|
1 from __future__ import division, absolute_import, print_function | |
2 | |
3 import numpy as np | |
4 from numpy.testing import TestCase, run_module_suite, assert_array_almost_equal | |
5 from numpy.testing import assert_array_equal | |
6 import threading | |
7 import sys | |
8 if sys.version_info[0] >= 3: | |
9 import queue | |
10 else: | |
11 import Queue as queue | |
12 | |
13 | |
14 def fft1(x): | |
15 L = len(x) | |
16 phase = -2j*np.pi*(np.arange(L)/float(L)) | |
17 phase = np.arange(L).reshape(-1, 1) * phase | |
18 return np.sum(x*np.exp(phase), axis=1) | |
19 | |
20 | |
21 class TestFFTShift(TestCase): | |
22 | |
23 def test_fft_n(self): | |
24 self.assertRaises(ValueError, np.fft.fft, [1, 2, 3], 0) | |
25 | |
26 | |
27 class TestFFT1D(TestCase): | |
28 | |
29 def test_basic(self): | |
30 rand = np.random.random | |
31 x = rand(30) + 1j*rand(30) | |
32 assert_array_almost_equal(fft1(x), np.fft.fft(x)) | |
33 | |
34 | |
35 class TestFFTThreadSafe(TestCase): | |
36 threads = 16 | |
37 input_shape = (800, 200) | |
38 | |
39 def _test_mtsame(self, func, *args): | |
40 def worker(args, q): | |
41 q.put(func(*args)) | |
42 | |
43 q = queue.Queue() | |
44 expected = func(*args) | |
45 | |
46 # Spin off a bunch of threads to call the same function simultaneously | |
47 t = [threading.Thread(target=worker, args=(args, q)) | |
48 for i in range(self.threads)] | |
49 [x.start() for x in t] | |
50 | |
51 [x.join() for x in t] | |
52 # Make sure all threads returned the correct value | |
53 for i in range(self.threads): | |
54 assert_array_equal(q.get(timeout=5), expected, | |
55 'Function returned wrong value in multithreaded context') | |
56 | |
57 def test_fft(self): | |
58 a = np.ones(self.input_shape) * 1+0j | |
59 self._test_mtsame(np.fft.fft, a) | |
60 | |
61 def test_ifft(self): | |
62 a = np.ones(self.input_shape) * 1+0j | |
63 self._test_mtsame(np.fft.ifft, a) | |
64 | |
65 def test_rfft(self): | |
66 a = np.ones(self.input_shape) | |
67 self._test_mtsame(np.fft.rfft, a) | |
68 | |
69 def test_irfft(self): | |
70 a = np.ones(self.input_shape) * 1+0j | |
71 self._test_mtsame(np.fft.irfft, a) | |
72 | |
73 | |
74 if __name__ == "__main__": | |
75 run_module_suite() |