-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare_accuracy_benchmark.py
34 lines (30 loc) · 1.02 KB
/
prepare_accuracy_benchmark.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
''' Calculates the test arrays and the high-precision results of the FFTs.
'''
import numpy as np
from mpmath import mp
import lib
import config
import sys
# generate arrays and calculate their exact FFT using gmpy2
# save the array and its exact FFT
np.random.seed(config.ACCURACY_SEED)
for N in config.ACCURACY_SIZES:
print('Calculating N=%d... ' % N, end='')
sys.stdout.flush()
ca = (np.random.uniform(-0.5, 0.5, N) +
1.0j * np.random.uniform(-0.5, 0.5, N))
ra = np.random.uniform(-0.5, 0.5, N)
ft_ca = lib.exact_fft(ca)
ft_ra = lib.exact_rfft(ra)
with open(config.DATA_DIR + '/%d.npy' % N, 'wb') as f:
np.save(f, ca)
np.save(f, ft_ca)
np.save(f, ra)
np.save(f, ft_ra)
print('Done.')
# generate larger arrrays and save them for the identity test
for N in config.ACCURACY_IDENTITY_SIZES:
ca = (np.random.uniform(-0.5, 0.5, N) +
1.0j * np.random.uniform(-0.5, 0.5, N))
with open(config.DATA_DIR + '/self_%d.npy' % N, 'wb') as f:
np.save(f, ca)