Debian Codegraph @

tests/test_pyfftw_wisdom.py

raw
1 # Copyright 2014 Knowledge Economy Developments Ltd
2 #
3 # Henry Gomersall
4 # [email protected]
5 #
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # * Redistributions of source code must retain the above copyright notice, this
12 # list of conditions and the following disclaimer.
13 #
14 # * Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 #
18 # * Neither the name of the copyright holder nor the names of its contributors
19 # may be used to endorse or promote products derived from this software without
20 # specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 #
34
35 from pyfftw import (
36 FFTW, empty_aligned,
37 export_wisdom, import_wisdom, forget_wisdom,
38 _supported_types, _supported_nptypes_complex)
39
40 from .test_pyfftw_base import run_test_suites
41
42 import numpy
43 import pickle
44 import sys
45
46 import unittest
47
48 class FFTWWisdomTest(unittest.TestCase):
49
50 def generate_wisdom(self):
51 for each_dtype in _supported_nptypes_complex:
52 n = 16
53 a = empty_aligned((1,1024), each_dtype, n=n)
54 b = empty_aligned(a.shape, dtype=a.dtype, n=n)
55 fft = FFTW(a,b)
56
57
58 def compare_single(self, prec, before, after):
59 # skip over unsupported data types where wisdom is the empty string
60 if prec in _supported_types:
61 # wisdom not updated for ld, at least on appveyor; e.g.
62 # https://ci.appveyor.com/project/hgomersall/pyfftw/build/job/vweyed25jx8oxxcb
63 if prec == 'ld' and sys.platform.startswith("win"):
64 pass
65 else:
66 self.assertNotEqual(before, after)
67 else:
68 self.assertEqual(before, b'')
69 self.assertEqual(before, after)
70
71
72 def compare(self, before, after):
73 for prec, ind in zip(['64', '32', 'ld'], [0,1,2]):
74 self.compare_single(prec, before[ind], after[ind])
75
76
77 def test_export(self):
78
79 forget_wisdom()
80
81 before_wisdom = export_wisdom()
82
83 self.generate_wisdom()
84
85 after_wisdom = export_wisdom()
86
87 self.compare(before_wisdom, after_wisdom)
88
89 def test_import(self):
90
91 forget_wisdom()
92
93 self.generate_wisdom()
94
95 after_wisdom = export_wisdom()
96
97 forget_wisdom()
98 before_wisdom = export_wisdom()
99
100 success = import_wisdom(after_wisdom)
101
102 self.compare(before_wisdom, after_wisdom)
103
104 self.assertEqual(success, tuple([x in _supported_types for x in ['64', '32', 'ld']]))
105
106
107 test_cases = (
108 FFTWWisdomTest,)
109
110 test_set = None
111
112 if __name__ == '__main__':
113
114 run_test_suites(test_cases, test_set)