Skip to content

Commit

Permalink
Use scipy to generate random signal
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Jan 30, 2024
1 parent 344c509 commit ff148a5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/py_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pyfftw
import time
import csv
from scipy.stats import unitary_group
import matplotlib.pyplot as plt

from pybindings import fft
Expand All @@ -17,14 +18,16 @@ def main() -> None:
for n in range(4, 29):
print(f"n = {n}")
big_n = 1 << n
a_re = np.asarray([float(i) for i in range(big_n)])
a_im = np.asarray([float(i) for i in range(big_n)])
x = unitary_group.rvs(big_n)

a_re = x[:, 0].copy().real # np.asarray([float(i) for i in range(big_n)])
a_im = x[:, 0].copy().imag # np.asarray([float(i) for i in range(big_n)])

start = time.time()
fft(a_re, a_im)
phastft_elapsed = round((time.time() - start) * 10**6)

a = [complex(i, i) for i in range(big_n)]
a = x[:, 0].copy()

start = time.time()
expected = np.fft.fft(a)
Expand All @@ -41,7 +44,7 @@ def main() -> None:
)
np.testing.assert_allclose(actual, expected)

arr = np.asarray([complex(i, i) for i in range(big_n)])
arr = x[:, 0].copy()
a = pyfftw.empty_aligned(big_n, dtype="complex128")
a[:] = arr
start = time.time()
Expand Down Expand Up @@ -94,7 +97,6 @@ def plot_elapsed_times(data: dict) -> None:
plt.ylabel("Elapsed Time (microseconds)")
plt.yscale("log")
plt.legend()

plt.savefig("py_benchmarks.png", dpi=600)


Expand Down

0 comments on commit ff148a5

Please sign in to comment.