Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/fft/tests/test_helper.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 #!/usr/bin/env python | |
2 """Test functions for fftpack.helper module | |
3 | |
4 Copied from fftpack.helper by Pearu Peterson, October 2005 | |
5 | |
6 """ | |
7 from __future__ import division, absolute_import, print_function | |
8 | |
9 import numpy as np | |
10 from numpy.testing import TestCase, run_module_suite, assert_array_almost_equal | |
11 from numpy import fft | |
12 from numpy import pi | |
13 | |
14 | |
15 class TestFFTShift(TestCase): | |
16 | |
17 def test_definition(self): | |
18 x = [0, 1, 2, 3, 4, -4, -3, -2, -1] | |
19 y = [-4, -3, -2, -1, 0, 1, 2, 3, 4] | |
20 assert_array_almost_equal(fft.fftshift(x), y) | |
21 assert_array_almost_equal(fft.ifftshift(y), x) | |
22 x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1] | |
23 y = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4] | |
24 assert_array_almost_equal(fft.fftshift(x), y) | |
25 assert_array_almost_equal(fft.ifftshift(y), x) | |
26 | |
27 def test_inverse(self): | |
28 for n in [1, 4, 9, 100, 211]: | |
29 x = np.random.random((n,)) | |
30 assert_array_almost_equal(fft.ifftshift(fft.fftshift(x)), x) | |
31 | |
32 def test_axes_keyword(self): | |
33 freqs = [[ 0, 1, 2], [ 3, 4, -4], [-3, -2, -1]] | |
34 shifted = [[-1, -3, -2], [ 2, 0, 1], [-4, 3, 4]] | |
35 assert_array_almost_equal(fft.fftshift(freqs, axes=(0, 1)), shifted) | |
36 assert_array_almost_equal(fft.fftshift(freqs, axes=0), | |
37 fft.fftshift(freqs, axes=(0,))) | |
38 assert_array_almost_equal(fft.ifftshift(shifted, axes=(0, 1)), freqs) | |
39 assert_array_almost_equal(fft.ifftshift(shifted, axes=0), | |
40 fft.ifftshift(shifted, axes=(0,))) | |
41 | |
42 | |
43 class TestFFTFreq(TestCase): | |
44 | |
45 def test_definition(self): | |
46 x = [0, 1, 2, 3, 4, -4, -3, -2, -1] | |
47 assert_array_almost_equal(9*fft.fftfreq(9), x) | |
48 assert_array_almost_equal(9*pi*fft.fftfreq(9, pi), x) | |
49 x = [0, 1, 2, 3, 4, -5, -4, -3, -2, -1] | |
50 assert_array_almost_equal(10*fft.fftfreq(10), x) | |
51 assert_array_almost_equal(10*pi*fft.fftfreq(10, pi), x) | |
52 | |
53 | |
54 class TestRFFTFreq(TestCase): | |
55 | |
56 def test_definition(self): | |
57 x = [0, 1, 2, 3, 4] | |
58 assert_array_almost_equal(9*fft.rfftfreq(9), x) | |
59 assert_array_almost_equal(9*pi*fft.rfftfreq(9, pi), x) | |
60 x = [0, 1, 2, 3, 4, 5] | |
61 assert_array_almost_equal(10*fft.rfftfreq(10), x) | |
62 assert_array_almost_equal(10*pi*fft.rfftfreq(10, pi), x) | |
63 | |
64 | |
65 class TestIRFFTN(TestCase): | |
66 | |
67 def test_not_last_axis_success(self): | |
68 ar, ai = np.random.random((2, 16, 8, 32)) | |
69 a = ar + 1j*ai | |
70 | |
71 axes = (-2,) | |
72 | |
73 # Should not raise error | |
74 fft.irfftn(a, axes=axes) | |
75 | |
76 | |
77 if __name__ == "__main__": | |
78 run_module_suite() |