| 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 FFTW |
| 36 |
import numpy |
| 37 |
from timeit import Timer |
| 38 |
|
| 39 |
from .test_pyfftw_base import run_test_suites, miss, np_fft |
| 40 |
|
| 41 |
import unittest |
| 42 |
|
| 43 |
from .test_pyfftw_base import FFTWBaseTest |
| 44 |
|
| 45 |
class Complex64MultiThreadedTest(FFTWBaseTest): |
| 46 |
|
| 47 |
def run_multithreaded_test(self, threads): |
| 48 |
in_shape = self.input_shapes['2d']; |
| 49 |
out_shape = self.output_shapes['2d'] |
| 50 |
|
| 51 |
axes=(-1,) |
| 52 |
a, b = self.create_test_arrays(in_shape, out_shape) |
| 53 |
|
| 54 |
fft, ifft = self.run_validate_fft(a, b, axes, threads=threads) |
| 55 |
|
| 56 |
fft_, ifft_ = self.run_validate_fft(a, b, axes, threads=1) |
| 57 |
|
| 58 |
self.timer_routine(fft.execute, fft_.execute, |
| 59 |
comparison_string='singled threaded') |
| 60 |
self.assertTrue(True) |
| 61 |
|
| 62 |
|
| 63 |
def test_2_threads(self): |
| 64 |
self.run_multithreaded_test(2) |
| 65 |
|
| 66 |
def test_4_threads(self): |
| 67 |
self.run_multithreaded_test(4) |
| 68 |
|
| 69 |
def test_7_threads(self): |
| 70 |
self.run_multithreaded_test(7) |
| 71 |
|
| 72 |
def test_25_threads(self): |
| 73 |
self.run_multithreaded_test(25) |
| 74 |
|
| 75 |
@unittest.skipIf(*miss('64')) |
| 76 |
class Complex128MultiThreadedTest(Complex64MultiThreadedTest): |
| 77 |
|
| 78 |
def setUp(self): |
| 79 |
|
| 80 |
self.input_dtype = numpy.complex128 |
| 81 |
self.output_dtype = numpy.complex128 |
| 82 |
self.np_fft_comparison = np_fft.fft |
| 83 |
return |
| 84 |
|
| 85 |
@unittest.skipIf(*miss('ld')) |
| 86 |
class ComplexLongDoubleMultiThreadedTest(Complex64MultiThreadedTest): |
| 87 |
|
| 88 |
def setUp(self): |
| 89 |
|
| 90 |
self.input_dtype = numpy.clongdouble |
| 91 |
self.output_dtype = numpy.clongdouble |
| 92 |
self.np_fft_comparison = self.reference_fftn |
| 93 |
return |
| 94 |
|
| 95 |
def reference_fftn(self, a, axes): |
| 96 |
|
| 97 |
# numpy.fft.fftn doesn't support complex256 type, |
| 98 |
# so we need to compare to a lower precision type. |
| 99 |
a = numpy.complex128(a) |
| 100 |
return np_fft.fftn(a, axes=axes) |
| 101 |
|
| 102 |
test_cases = ( |
| 103 |
Complex64MultiThreadedTest, |
| 104 |
Complex128MultiThreadedTest, |
| 105 |
ComplexLongDoubleMultiThreadedTest,) |
| 106 |
|
| 107 |
test_set = None |
| 108 |
|
| 109 |
if __name__ == '__main__': |
| 110 |
|
| 111 |
run_test_suites(test_cases, test_set) |