• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from __future__ import division
2from __future__ import print_function
3
4import os
5import sys
6
7import numpy as np
8
9MAX_INPUT_SIZE = int(1e6)
10MAX_FLOAT32 = np.finfo(np.float32).max
11
12def IsValidSize(n):
13  if n == 0:
14    return False
15  # PFFFT only supports transforms for inputs of length N of the form
16  # N = (2^a)*(3^b)*(5^c) where a >= 5, b >=0, c >= 0.
17  FACTORS = [2, 3, 5]
18  factorization = [0, 0, 0]
19  for i, factor in enumerate(FACTORS):
20    while n % factor == 0:
21      n = n // factor
22      factorization[i] += 1
23  return factorization[0] >= 5 and n == 1
24
25
26def main():
27  if len(sys.argv) < 2:
28    print('Usage: %s <path to output directory>' % sys.argv[0])
29    sys.exit(1)
30
31  output_path = sys.argv[1]
32  if not os.path.exists(output_path):
33    print('The output path does not exists.')
34    sys.exit(2)
35
36  # List of valid input sizes.
37  N = [n for n in range(MAX_INPUT_SIZE) if IsValidSize(n)]
38
39  # Set the seed to always generate the same random data.
40  np.random.seed(0)
41
42  # Generate different types of input arrays for each target length.
43  for n in N:
44    # Zeros.
45    z = np.zeros(n, np.float32)
46    z.tofile(os.path.join(output_path, 'zeros_%d' % n))
47    # Max float 32.
48    m = np.ones(n, np.float32) * MAX_FLOAT32
49    m.tofile(os.path.join(output_path, 'max_%d' % n))
50    # Random values in the s16 range.
51    rnd_s16 = 32768.0 * 2.0 * (np.random.rand(n) - 1.0)
52    rnd_s16 = rnd_s16.astype(np.float32)
53    rnd_s16.tofile(os.path.join(output_path, 'rnd_s16_%d' % n))
54
55  sys.exit(0)
56
57
58if __name__ == '__main__':
59  main()
60