~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to scipy/fftpack/tests/test_helper.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# Created by Pearu Peterson, September 2002
 
3
""" Test functions for fftpack.helper module
 
4
"""
 
5
__usage__ = """
 
6
Build fftpack:
 
7
  python setup_fftpack.py build
 
8
Run tests if scipy is installed:
 
9
  python -c 'import scipy;scipy.fftpack.test(<level>)'
 
10
Run tests if fftpack is not installed:
 
11
  python tests/test_helper.py [<level>]
 
12
"""
 
13
 
 
14
import sys
 
15
from numpy.testing import *
 
16
set_package_path()
 
17
from fftpack import fftshift,ifftshift,fftfreq,rfftfreq
 
18
restore_path()
 
19
 
 
20
from numpy import pi
 
21
 
 
22
def random(size):
 
23
    return rand(*size)
 
24
 
 
25
class test_fftshift(NumpyTestCase):
 
26
 
 
27
    def check_definition(self):
 
28
        x = [0,1,2,3,4,-4,-3,-2,-1]
 
29
        y = [-4,-3,-2,-1,0,1,2,3,4]
 
30
        assert_array_almost_equal(fftshift(x),y)
 
31
        assert_array_almost_equal(ifftshift(y),x)
 
32
        x = [0,1,2,3,4,-5,-4,-3,-2,-1]
 
33
        y = [-5,-4,-3,-2,-1,0,1,2,3,4]
 
34
        assert_array_almost_equal(fftshift(x),y)
 
35
        assert_array_almost_equal(ifftshift(y),x)
 
36
 
 
37
    def check_inverse(self):
 
38
        for n in [1,4,9,100,211]:
 
39
            x = random((n,))
 
40
            assert_array_almost_equal(ifftshift(fftshift(x)),x)
 
41
 
 
42
class test_fftfreq(NumpyTestCase):
 
43
 
 
44
    def check_definition(self):
 
45
        x = [0,1,2,3,4,-4,-3,-2,-1]
 
46
        assert_array_almost_equal(9*fftfreq(9),x)
 
47
        assert_array_almost_equal(9*pi*fftfreq(9,pi),x)
 
48
        x = [0,1,2,3,4,-5,-4,-3,-2,-1]
 
49
        assert_array_almost_equal(10*fftfreq(10),x)
 
50
        assert_array_almost_equal(10*pi*fftfreq(10,pi),x)
 
51
 
 
52
class test_rfftfreq(NumpyTestCase):
 
53
 
 
54
    def check_definition(self):
 
55
        x = [0,1,1,2,2,3,3,4,4]
 
56
        assert_array_almost_equal(9*rfftfreq(9),x)
 
57
        assert_array_almost_equal(9*pi*rfftfreq(9,pi),x)
 
58
        x = [0,1,1,2,2,3,3,4,4,5]
 
59
        assert_array_almost_equal(10*rfftfreq(10),x)
 
60
        assert_array_almost_equal(10*pi*rfftfreq(10,pi),x)
 
61
 
 
62
if __name__ == "__main__":
 
63
    NumpyTest().run()