-
Notifications
You must be signed in to change notification settings - Fork 1
/
cyfunc.pyx
81 lines (72 loc) · 1.92 KB
/
cyfunc.pyx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# cython: language_level=3, boundscheck=False
import numpy as np
cimport numpy as np
cdef void fast_sort5(int a, int b, int c, int d, int e,
int* ao, int* bo, int* co, int* do, int* eo):
"Sort 5 values with 7 Comparisons"
if a < b:
a, b = b, a
if c < d:
c, d = d, c
if a < c:
a, b, c, d = c, d, a, b
if e < c:
if e < d:
pass
else:
d, e = e, d
else:
if e < a:
c, d, e = e, c, d
else:
a, c, d, e = e, a, c, d
if b < d:
if b < e:
ao[0] = b
bo[0] = e
co[0] = d
do[0] = c
eo[0] = a
else:
ao[0] = e
bo[0] = b
co[0] = d
do[0] = c
eo[0] = a
else:
if b < c:
ao[0] = e
bo[0] = d
co[0] = b
do[0] = c
eo[0] = a
else:
ao[0] = e
bo[0] = d
co[0] = c
do[0] = b
eo[0] = a
cpdef np.float64_t[:, :, :, :, ::1] cy_accum_unordered(np.float64_t[:, :, :, :, ::1] x):
cdef:
int i, j, k, l, m, n
int ix, jx, kx, lx, mx
np.ndarray[np.float64_t, ndim=5] gout
np.float64_t[:, :, :, :, ::1] g
n = x.shape[0]
gout = np.zeros_like(x)
g = gout
for i in range(n):
for j in range(n):
if i == j:
continue
for k in range(n):
if i == k or j == k:
continue
for l in range(n):
if i == l or j == l or k == l:
continue
for m in range(n):
if i != m and j != m and k != m and l != m:
fast_sort5(i, j, k, l, m, &ix, &jx, &kx, &lx, &mx)
g[ix, jx, kx, lx, mx] += x[i, j, k, l, m]
return gout