Created
January 22, 2016 13:55
-
-
Save ThomasA/0cabd9a9b488fba3a154 to your computer and use it in GitHub Desktop.
The purpose of this script is to evaluate how severe the run-time overhead is when specifying a transform size parameter for FFT and DCT. It has been observed that specifying this parameter increases the run-time, even if the specified size is equal to the size of the input. The objective here is to figure out whether this overhead is a constant…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""The purpose of this script is to evaluate how severe the run-time | |
overhead is when specifying a transform size parameter for FFT and | |
DCT. It has been observed that specifying this parameter increases the | |
run-time, even if the specified size is equal to the size of the | |
input. The objective here is to figure out whether this overhead is a | |
constant set-up cost or it depends on the input size. | |
""" | |
import numpy as np | |
import scipy.fftpack as sfft | |
import time | |
import matplotlib.pyplot as plt | |
sizes = 2**np.arange(1,11) | |
repetitions = 100 | |
times_dct_padding = [] | |
times_dct_normal = [] | |
times_fft_padding = [] | |
times_fft_normal = [] | |
for size in sizes: | |
time_dct_padding_acc = 0 | |
time_dct_normal_acc = 0 | |
time_fft_padding_acc = 0 | |
time_fft_normal_acc = 0 | |
for count in range(repetitions): | |
# DCT | |
data = np.random.randn(size**2) | |
tic = time.time() | |
output = sfft.dct(data, n=size**2) | |
toc = time.time() | |
time_dct_padding_acc += toc - tic | |
tic = time.time() | |
output = sfft.dct(data) | |
toc = time.time() | |
time_dct_normal_acc += toc - tic | |
# DFT | |
data = np.random.randn(size,size) | |
tic = time.time() | |
output = np.fft.fft2(data, s=data.shape) | |
toc = time.time() | |
time_fft_padding_acc += toc - tic | |
tic = time.time() | |
output = np.fft.fft2(data) | |
toc = time.time() | |
time_fft_normal_acc += toc - tic | |
times_dct_padding.append(time_dct_padding_acc / repetitions) | |
times_dct_normal.append(time_dct_normal_acc / repetitions) | |
times_fft_padding.append(time_fft_padding_acc / repetitions) | |
times_fft_normal.append(time_fft_normal_acc / repetitions) | |
plt.figure() | |
plt.title('DCT') | |
plt.plot(sizes**2, times_dct_normal, label='normal') | |
plt.plot(sizes**2, times_dct_padding, label='padding') | |
plt.legend() | |
plt.figure() | |
plt.title('FFT') | |
plt.plot(sizes**2, times_fft_normal, label='normal') | |
plt.plot(sizes**2, times_fft_padding, label='padding') | |
plt.legend() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment