-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
137 lines (114 loc) · 2.78 KB
/
test.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from scale import scale
from scale.quote import macros, q
import numpy as np
arr = np.arange(9).reshape((3,3)).tolist()
@scale
def double_i(a: [[int]]) -> int:
return a[1,1]
print(double_i([[0,1,2],[3,4,5]]))
@scale
def sum_for(a: [[int]], l: int) -> int:
s = 0
for i in range(l):
for j in range(l):
s += a[i,j]
return s
print(sum_for(arr, len(arr)))
@scale
def laplace(img: [[int]], out: [[int]], l: int) -> int:
for i in range(l-2):
for j in range(l-2):
out[i,j] = img[i+0,j+1] + img[i+2,j+1] + img[i+1,j+2] + img[i+1,j+0] - 4 * img[i+1,j+1]
return out[14,14]
img = np.random.randint(0, 100,(28,28))
print(laplace(img.tolist(), np.random.randint(0,1,(26, 26)).tolist(), 28))
test_index = 14
print(img[test_index+0,test_index+1] + img[test_index+2,test_index+1] + img[test_index+1,test_index+2] + img[test_index+1,test_index+0] - 4 * img[test_index+1,test_index+1])
'''
def gen_square(x):
return q[x * x]
a = 1
with q as block_of_code:
a = a + 2
b = a + 3
@scale
def n1(x: int) -> int:
return x
@scale
def n2(x: int) -> int:
d = n1(x)
c = 1
return x
n2.compile()
@scale
def array_of_array(a: [[int]]) -> int:
b = a[2]
return b[2]
@scale
def create_len_array(n: int) -> float:
a = create_float_array(5)
a[4] = 5.5
return a[4]
@scale
def ret5() -> int:
return 5
@scale
def call_test() -> int:
five = ret5()
return five
@scale
def index_test(a: [int]) -> int:
a[1] = 1
return a[1]
@scale
def array1_test(a: [int]) -> int:
b = [1,2,3]
c = b[1] + b[2]
d = b[1] + c
b[2] = d + a[0]
return d
@scale
def array2_test(a: [int]) -> [int]:
return a
@scale
def mse(a: float, b: float) -> float:
return {gen_square(a)} - {gen_square(b)}
@scale(dump_unescaped=True, dump_llvm=True)
def test_block_quotes(a: int) -> int:
{block_of_code}
return b
@scale(dump_unescaped=True)
def test_block_quotes_captured() -> int:
{block_of_code}
return b
def python_mse(a: float, b: float) -> float:
return a * a + b * b
print(mse(4.0, 3.0))
print(test_block_quotes_captured())
print(test_block_quotes(2))
a = 3
print(test_block_quotes_captured())
print(test_block_quotes(2))
print(index_test([1,2,3]))
print(array1_test([5,5,5]))
print(create_len_array(1))
print(array_of_array([[1,2,3,4],[5,6,7,8],[4,7,8]]))
print(call_test())
@scale.declare
def factorial1(n: int) -> int:
pass
@scale.declare
def factorial2(n: int) -> int:
pass
@scale(dump_unescaped=True, dump_llvm=True)
def factorial1(n: int) -> int:
if n == 1:
return 1
return n * factorial2(n - 1)
@scale(dump_unescaped=True, dump_llvm=True)
def factorial2(n: int) -> int:
if n == 1:
return 1
return n * factorial2(n - 1)
print([factorial1(i) for i in range(1, 10)])
'''