-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrijumptable.py
executable file
·43 lines (35 loc) · 1.24 KB
/
rijumptable.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
39
40
41
42
43
#!/usr/bin/env python3
# rsm :: Random Sampling Mathematics
# Copyright (c) 2018 Michał Siejak
# Released under the MIT license; see LICENSE file for details
import math
def primes(N):
p = [2, 3]
np = p[-1] + 2
while len(p) < N:
is_prime = True
for divisor in range(2, int(math.sqrt(np)) + 1):
if np % divisor == 0:
is_prime = False
break
if is_prime:
p.append(np)
np += 2
return p
def generate(N):
assert N >= 3
print("// Generated by rijumptable.py for N={}".format(N))
for index, p in enumerate(primes(N)[2:]):
print("case {}: return radical_inverse_scrambled<T>({}, perm, value);".format(index + 2, p))
def main():
import sys, argparse
parser = argparse.ArgumentParser(description="Generate radical inverse jump table for RSM library.")
parser.add_argument("N", nargs='?', type=int, default=128, help="Maximum sampling dimension to support with the generated table (default: 128, min: 3)")
args = parser.parse_args()
if args.N >= 3:
generate(args.N)
else:
print("error: maximum sampling dimension needs to be at least 3", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()