Spaces:
Runtime error
Runtime error
kevinwang676
commited on
Commit
•
b5192c0
1
Parent(s):
f9bb9f0
Create core.py
Browse files- monotonic_align/core.py +36 -0
monotonic_align/core.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numba
|
2 |
+
|
3 |
+
|
4 |
+
@numba.jit(numba.void(numba.int32[:, :, ::1], numba.float32[:, :, ::1], numba.int32[::1], numba.int32[::1]),
|
5 |
+
nopython=True, nogil=True)
|
6 |
+
def maximum_path_jit(paths, values, t_ys, t_xs):
|
7 |
+
b = paths.shape[0]
|
8 |
+
max_neg_val = -1e9
|
9 |
+
for i in range(int(b)):
|
10 |
+
path = paths[i]
|
11 |
+
value = values[i]
|
12 |
+
t_y = t_ys[i]
|
13 |
+
t_x = t_xs[i]
|
14 |
+
|
15 |
+
v_prev = v_cur = 0.0
|
16 |
+
index = t_x - 1
|
17 |
+
|
18 |
+
for y in range(t_y):
|
19 |
+
for x in range(max(0, t_x + y - t_y), min(t_x, y + 1)):
|
20 |
+
if x == y:
|
21 |
+
v_cur = max_neg_val
|
22 |
+
else:
|
23 |
+
v_cur = value[y - 1, x]
|
24 |
+
if x == 0:
|
25 |
+
if y == 0:
|
26 |
+
v_prev = 0.
|
27 |
+
else:
|
28 |
+
v_prev = max_neg_val
|
29 |
+
else:
|
30 |
+
v_prev = value[y - 1, x - 1]
|
31 |
+
value[y, x] += max(v_prev, v_cur)
|
32 |
+
|
33 |
+
for y in range(t_y - 1, -1, -1):
|
34 |
+
path[y, index] = 1
|
35 |
+
if index != 0 and (index == y or value[y - 1, index] < value[y - 1, index - 1]):
|
36 |
+
index = index - 1
|