-
Notifications
You must be signed in to change notification settings - Fork 11
/
preleminary.py
38 lines (30 loc) · 1.06 KB
/
preleminary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from timeit import repeat
import numpy
import scipy.fftpack
import pyfftw
def create_array(*size):
#return numpy.random.rand(120, 128, 2*96).view(dtype=complex)
arr = pyfftw.empty_aligned(size, dtype='complex64')
arr[:] = numpy.random.randn(*size) + 1j*numpy.random.randn(*size)
return arr
small = create_array(120, 128, 96)
big = create_array(416, 416, 256)
pyfftw.interfaces.cache.enable()
def numpy_fft(a):
b = numpy.fft.fftn(a)
c = numpy.fft.ifftn(b)
#print(numpy.max(c - a))
def scipy_fft(a):
b = scipy.fftpack.fftn(a)
c = scipy.fftpack.ifftn(b)
#print(numpy.max(c - a))
def fftw_fft(a):
b = pyfftw.interfaces.numpy_fft.fftn(a)
c = pyfftw.interfaces.numpy_fft.ifftn(b)
def run(fft):
return (min(repeat(fft+'(small)', repeat=20, number=1, globals=globals())),
min(repeat(fft+'(big)', repeat=3, number=1, globals=globals())))
print('lib 120x128x96 416x256x416')
print('mkl %7.3f %7.3f' % run('numpy_fft'))
print('scipy %7.3f %7.3f' % run('scipy_fft'))
print('pyfftw %7.3f %7.3f' % run('fftw_fft'))