-
Notifications
You must be signed in to change notification settings - Fork 19
/
position.py
40 lines (32 loc) · 1.28 KB
/
position.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
from numba import jit
import numpy as np
import logging
numba_logger = logging.getLogger('numba')
numba_logger.setLevel(logging.WARNING)
@jit(nopython=True)
def nodets2key(batch: int, node: int, ts: float):
ts = 0
key = '-'.join([str(batch), str(node), float2str(ts)])
return key
@jit(nopython=True)
def float2str(ts):
return str(int(round(ts)))
def make_batched_keys(node_record, t_record):
batch = node_record.shape[0]
support = node_record.shape[1]
batched_keys = make_batched_keys_l(node_record, t_record, batch, support)
batched_keys = np.array(batched_keys).reshape((batch, support))
# batched_keys = np.array([nodets2key(b, n, t) for b, n, t in zip(batch_matrix.ravel(), node_record.ravel(), t_record.ravel())]).reshape(batch, support)
return batched_keys
@jit(nopython=True)
def make_batched_keys_l(node_record, t_record, batch, support):
batch_matrix = np.arange(batch).repeat(support).reshape((-1, support))
# batch_matrix = np.tile(np.expand_dims(np.arange(batch), 1), (1, support))
batched_keys = []
for i in range(batch):
for j in range(support):
b = batch_matrix[i, j]
n = node_record[i, j]
t = t_record[i, j]
batched_keys.append(nodets2key(b, n, t))
return batched_keys