-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturboseti_wrapper.py
executable file
·55 lines (42 loc) · 1.34 KB
/
turboseti_wrapper.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
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
"""
A wrapper that just runs the inner part of turboSETI that does the Taylor tree stuff.
"""
import cupy as cp
import math
import time
import turbo_seti
from turbo_seti.find_doppler.kernels import Kernels
from performance import *
assert __name__ == "__main__"
kernels = Kernels(gpu_backend=True, precision=1)
assert kernels.gpu_backend
arr = make_test_array()
bin_height = f"{N_TIME:b}"
assert bin_height.count("1") == 1
def row_index_bit_reverse(n):
assert 0 <= n < N_TIME
n_bits = f"{(N_TIME + n):b}"[1:]
assert len(n_bits) == bin_height.count("0")
return int("".join(reversed(n_bits)), 2)
def unshuffle_array(arr):
"""
Turboseti stores its tree in such a way that the row is indexed by the bit-reversed drift.
This unshuffling converts the turboseti output to an array indexed by
arr[drift rate][start column]
"""
shuffled = arr.reshape((N_TIME, N_FREQ))
output = cp.empty((N_TIME, N_FREQ))
for i in range(N_TIME):
j = row_index_bit_reverse(i)
output[i] = shuffled[j]
return output
arr = make_test_array()
print("array:")
show_array(arr.reshape((N_TIME, N_FREQ)))
start_time = time.time()
kernels.tt.flt(arr, N_TIME * N_FREQ, N_TIME)
print(f"time elapsed in flt: {time.time() - start_time:.3f}s")
output = unshuffle_array(arr)
print("output:")
show_array(output)