Skip to content

Commit

Permalink
Add explicit cast in integration_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Nov 9, 2022
1 parent c07bf54 commit d4a9450
Show file tree
Hide file tree
Showing 89 changed files with 600 additions and 595 deletions.
6 changes: 3 additions & 3 deletions integration_tests/array_01_decl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class ArraySizes(Enum):
SIZE_10: i32 = 10

def accept_i16_array(xi16: i16[:]) -> i16:
xi16[2] = 32
xi16[2] = i16(32)
return xi16[2]

def accept_i32_array(xi32: i32[:]) -> i32:
xi32[1] = 32
return xi32[1]

def accept_i64_array(xi64: i64[:]) -> i64:
xi64[1] = 64
xi64[1] = i64(64)
return xi64[1]

def accept_f32_array(xf32: f32[:]) -> f32:
xf32[1] = 32.0
xf32[1] = f32(32.0)
return xf32[1]

def accept_f64_array(xf64: f64[:]) -> f64:
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/array_expr_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def array_expr_01():
g = reshape(e + f, shape1d)

for i in range(dim1d):
assert abs(g[i] - 2*(i + 1)) <= eps
assert abs(g[i] - f64(2*(i + 1))) <= eps

array_expr_01()
8 changes: 4 additions & 4 deletions integration_tests/array_expr_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def modify(array_a: f32[:], n: i32) -> f32[n]:
def verify(array_a: f32[:], array_b: f32[:], result: f32[:], size: i32):
i: i32
eps: f32
eps = 1e-6
eps = f32(1e-6)

for i in range(size):
assert abs(array_a[i] * array_a[i] + sqrt(array_b[i]) - result[i]) <= eps
Expand All @@ -24,12 +24,12 @@ def f():
array_c: f32[256] = empty(256, dtype=float32)

for i in range(256):
array_a[i] = float(i)
array_a[i] = f32(i)

for j in range(256):
array_b[j] = float(j + 5)
array_b[j] = f32(j + 5)

array_c = array_a**2 + modify(array_b, 256)
array_c = array_a**f32(2) + modify(array_b, 256)
verify(array_a, array_b, array_c, 256)


Expand Down
8 changes: 4 additions & 4 deletions integration_tests/bindc_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def f():
yq: CPtr
yptr1: Pointer[i16[:]]
y: i16[2]
y[0] = 1
y[1] = 2
y[0] = i16(1)
y[1] = i16(2)
yptr1 = pointer(y)
print(pointer(y), yptr1)
print(yptr1[0], yptr1[1])
assert yptr1[0] == 1
assert yptr1[1] == 2
assert yptr1[0] == i16(1)
assert yptr1[1] == i16(2)

c_p_pointer(yq, yptr1)

Expand Down
12 changes: 6 additions & 6 deletions integration_tests/bindc_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
def f():
yptr1: Pointer[i16[:]]
y: i16[2]
y[0] = 1
y[1] = 2
y[0] = i16(1)
y[1] = i16(2)
yptr1 = pointer(y)
assert yptr1[0] == 1
assert yptr1[1] == 2
assert yptr1[0] == i16(1)
assert yptr1[1] == i16(2)
x = pointer(y)

def check():
f()
assert x[0] == 1
assert x[1] == 2
assert x[0] == i16(1)
assert x[1] == i16(2)

check()
2 changes: 1 addition & 1 deletion integration_tests/bindc_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def print_value(value: CPtr):

def test_trunc():
float_cptr: CPtr = empty_c_void_p()
float_obj: f32 = 1.3
float_obj: f32 = f32(1.3)

p_c_pointer(pointer(float_obj), float_cptr)
voidobj: Void = Void(float_cptr)
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/const_01.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from ltypes import Const, i32, i64, f32, f64

def test_const_variables():
xci: Const[i32] = 0.0
xci: Const[i32] = i32(0.0)
xi: i32 = 0

yci: Const[i64] = int(1)
yi: i64 = int(1)

xcf: Const[f32] = 2
xf: f32 = 2.0
xcf: Const[f32] = f32(2)
xf: f32 = f32(2.0)

ycf: Const[f64] = 3.0
yf: f64 = 3.0
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/const_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def test_call_cases():
assert f(y) == 2

# argument const, parameter const
assert g(yconst) == 6
assert g(yconst) == 6.0

def test_assign_cases():
y: i32
y: f64
yconst: Const[i32] = 4
# target const, value non-const - error case

Expand Down
8 changes: 4 additions & 4 deletions integration_tests/const_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CONST_1: Const[f64] = 32.0
CONST_2: Const[f64] = CONST_1 * 2.0
CONST_3: Const[i64] = CONST_1 + CONST_2
CONST_3: Const[i64] = i64(CONST_1 + CONST_2)

CONST_11: Const[i32] = 32
CONST_12: Const[i32] = CONST_11
Expand All @@ -20,8 +20,8 @@ def test_global_consts():
print(CONST_12)
print_value_c(CONST_1)
print_value_c(CONST_2)
assert CONST_1 == 32
assert CONST_2 == 64
assert abs(CONST_3 - 96.0) < 1e-12
assert CONST_1 == 32.0
assert CONST_2 == 64.0
assert f64(abs(CONST_3 - i64(96))) < 1e-12

test_global_consts()
6 changes: 3 additions & 3 deletions integration_tests/const_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def sum_const_array(array: Const[i16[:]], size: i32) -> i16:
i: i32
array_sum: i16 = 0
array_sum: i16 = i16(0)
for i in range(size):
array_sum += array[i]
return array_sum
Expand All @@ -12,7 +12,7 @@ def test_const_array():
arr: i16[4] = empty(4, dtype=int16)
i: i32
for i in range(4):
arr[i] = i
assert sum_const_array(arr, 4) == 6
arr[i] = i16(i)
assert sum_const_array(arr, 4) == i16(6)

test_const_array()
28 changes: 14 additions & 14 deletions integration_tests/elemental_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def verify1d(array: f32[:], result: f32[:], size: i32):
i: i32
eps: f32
eps = 1e-6
eps = f32(1e-6)

for i in range(size):
assert abs(sin(sin(array[i])) - result[i]) <= eps
Expand All @@ -19,7 +19,7 @@ def verifynd(array: f64[:, :, :], result: f64[:, :, :], size1: i32, size2: i32,
for i in range(size1):
for j in range(size2):
for k in range(size3):
assert abs(sin(array[i, j, k])**2 - result[i, j, k]) <= eps
assert abs(sin(array[i, j, k])**2.0 - result[i, j, k]) <= eps

def verify2d(array: f64[:, :], result: f64[:, :], size1: i32, size2: i32):
i: i32
Expand All @@ -29,7 +29,7 @@ def verify2d(array: f64[:, :], result: f64[:, :], size1: i32, size2: i32):

for i in range(size1):
for j in range(size2):
assert abs(cos(array[i, j])**2 - result[i, j]) <= eps
assert abs(cos(array[i, j])**2.0 - result[i, j]) <= eps


def verify1d_sum(array_a: f64[:], array_b: f64[:], result: f64[:], size: i32):
Expand All @@ -38,7 +38,7 @@ def verify1d_sum(array_a: f64[:], array_b: f64[:], result: f64[:], size: i32):
eps = 1e-12

for i in range(size):
assert abs(array_a[i]**2 + 5*array_b[i]**3 - result[i]) <= eps
assert abs(array_a[i]**2.0 + 5.0*array_b[i]**3.0 - result[i]) <= eps


def verify1d_mul(array_a: f64[:], array_b: f64[:], result: f64[:], size: i32):
Expand All @@ -47,7 +47,7 @@ def verify1d_mul(array_a: f64[:], array_b: f64[:], result: f64[:], size: i32):
eps = 1e-12

for i in range(size):
assert abs(array_a[i]**2 * 5*array_b[i]**3 - result[i]) <= eps
assert abs(array_a[i]**2.0 * 5.0*array_b[i]**3.0 - result[i]) <= eps


def elemental_sum():
Expand All @@ -65,7 +65,7 @@ def elemental_sum():
for j in range(100):
array_b[j] = float(j+5)

array_c = array_a**2 + 5*array_b**3
array_c = array_a**2.0 + 5.0*array_b**3.0
verify1d_sum(array_a, array_b, array_c, 100)


Expand All @@ -84,7 +84,7 @@ def elemental_mul():
for j in range(100):
array_b[j] = float(j+5)

array_c = array_a**2 * 5*array_b**3
array_c = array_a**2.0 * 5.0*array_b**3.0
verify1d_mul(array_a, array_b, array_c, 100)


Expand All @@ -97,7 +97,7 @@ def elemental_sin():
sin1d: f32[256] = empty(256)

for i in range(256):
array1d[i] = float(i)
array1d[i] = f32(i)

sin1d = sin(sin(array1d))

Expand All @@ -111,7 +111,7 @@ def elemental_sin():
for k in range(16):
arraynd[i, j, k] = float(i + j + k)

sinnd = sin(arraynd)**2
sinnd = sin(arraynd)**2.0

verifynd(arraynd, sinnd, 256, 64, 16)

Expand All @@ -126,7 +126,7 @@ def elemental_cos():
for j in range(64):
array2d[i, j] = float(i + j)

cos2d = cos(array2d)**2
cos2d = cos(array2d)**2.0

verify2d(array2d, cos2d, 256, 64)

Expand All @@ -136,7 +136,7 @@ def elemental_trig_identity():
k: i32
l: i32
eps: f32
eps = 1e-6
eps = f32(1e-6)

arraynd: f32[64, 32, 8, 4] = empty((64, 32, 8, 4))
observed: f32[64, 32, 8, 4] = empty((64, 32, 8, 4))
Expand All @@ -146,16 +146,16 @@ def elemental_trig_identity():
for j in range(32):
for k in range(8):
for l in range(4):
arraynd[i, j, k, l] = float(i + j + k + l)
arraynd[i, j, k, l] = f32(i + j + k + l)

observed = sin(arraynd)**2 + cos(arraynd)**2
observed = sin(arraynd)**f32(2) + cos(arraynd)**f32(2)

newshape: i32[1] = empty(1, dtype=int)
newshape[0] = 65536
observed1d = reshape(observed, newshape)

for i in range(65536):
assert abs(observed1d[i] - 1.0) <= eps
assert abs(observed1d[i] - f32(1.0)) <= eps


elemental_sin()
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/elemental_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def elemental_tan32():
i: i32
j: i32
eps: f32
eps = 1e-6
eps = f32(1e-6)

for i in range(25):
theta1d[i] = float(i + 1)
theta1d[i] = f32(i + 1)

shapend[0] = 5
shapend[1] = 5
Expand Down
16 changes: 8 additions & 8 deletions integration_tests/elemental_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ def elemental_sqrt64():
shape[0] = 4096
observed = reshape(sqrt(array), shape)
for l in range(4096):
i = int(l/256)
i = i32(int(l/256))
j = (l - i*256)//16
k = (l - i*256 - j*16)
assert abs(observed[l]**2 - i - j - k) <= eps
assert abs(observed[l]**2.0 - f64(i + j + k)) <= eps

def elemental_sqrt32():
array: f32[16, 16] = empty((16, 16))
observed: f32[256] = empty(256)
shape: i32[1] = empty(1, dtype=int)
eps: f32
eps = 2e-6
eps = f32(2e-6)
i: i32
j: i32
l: i32

for i in range(16):
for j in range(16):
array[i, j] = float(i + j)
array[i, j] = f32(i + j)

shape[0] = 256
observed = reshape(sqrt(array), shape)
for l in range(256):
i = int(l/16)
i = i32(int(l/16))
j = (l - i*16)
assert abs(observed[l]**2 - i - j) <= eps
assert abs(observed[l]**f32(2.0) - f32(i + j)) <= eps


def elemental_norm():
Expand All @@ -61,13 +61,13 @@ def elemental_norm():
for j in range(100):
array_b[j] = float(j+5)

array_c = sqrt(array_a**2 + array_b**2)
array_c = sqrt(array_a**2.0 + array_b**2.0)

eps: f64
eps = 1e-12

for i in range(100):
assert abs(array_c[i] - sqrt(array_a[i]**2 + array_b[i]**2)) <= eps
assert abs(array_c[i] - sqrt(array_a[i]**2.0 + array_b[i]**2.0)) <= eps


elemental_sqrt64()
Expand Down
10 changes: 5 additions & 5 deletions integration_tests/elemental_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def elemental_log():
observed = log(array)

for i in range(100):
assert abs(exp(observed[i]) - i - 1) <= eps
assert abs(exp(observed[i]) - f64(i + 1)) <= eps

def verify(observed: f32[:], base: i32, eps: f32):
k: i32
i: i32
j: i32

for k in range(100):
i = int(k/10)
i = i32(int(k/10))
j = (k - i*10)
assert abs(base**(observed[k]) - i - j - 1) <= eps
assert abs(f32(base)**(observed[k]) - f32(i + j + 1)) <= eps

def elemental_log2_log10():
array: f32[10, 10] = empty((10, 10))
Expand All @@ -34,11 +34,11 @@ def elemental_log2_log10():
i: i32
j: i32
eps: f32
eps = 2e-6
eps = f32(2e-6)

for i in range(10):
for j in range(10):
array[i, j] = float(i + j + 1)
array[i, j] = f32(i + j + 1)

shape[0] = 100
observed = reshape(log2(array), shape)
Expand Down
Loading

0 comments on commit d4a9450

Please sign in to comment.