Skip to content

Commit

Permalink
Merge branch 'main' into docs-enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
kmr-srbh authored Mar 21, 2024
2 parents 407bb77 + 85ced05 commit ba4d09f
Show file tree
Hide file tree
Showing 27 changed files with 670 additions and 51 deletions.
6 changes: 6 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ RUN(NAME array_expr_05 LABELS cpython llvm c)
RUN(NAME array_expr_06 LABELS cpython llvm c)
RUN(NAME array_expr_07 LABELS cpython llvm c)
RUN(NAME array_expr_08 LABELS cpython llvm c)
RUN(NAME array_expr_09 LABELS cpython llvm c)
RUN(NAME array_expr_10 LABELS cpython llvm c)
RUN(NAME array_size_01 LABELS cpython llvm c)
RUN(NAME array_size_02 LABELS cpython llvm c)
RUN(NAME array_01 LABELS cpython llvm wasm c)
Expand Down Expand Up @@ -578,6 +580,7 @@ RUN(NAME test_dict_nested1 LABELS cpython llvm)
RUN(NAME test_set_len LABELS cpython llvm)
RUN(NAME test_set_add LABELS cpython llvm)
RUN(NAME test_set_remove LABELS cpython llvm)
RUN(NAME test_global_set LABELS cpython llvm)
RUN(NAME test_for_loop LABELS cpython llvm c)
RUN(NAME modules_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
RUN(NAME modules_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
Expand Down Expand Up @@ -754,6 +757,8 @@ RUN(NAME test_platform LABELS cpython llvm c)
RUN(NAME test_vars_01 LABELS cpython llvm)
RUN(NAME test_version LABELS cpython llvm)
RUN(NAME logical_binop1 LABELS cpython llvm)
RUN(NAME test_logical_compare LABELS cpython llvm)
RUN(NAME test_logical_assignment LABELS cpython llvm)
RUN(NAME vec_01 LABELS cpython llvm c NOFAST)
RUN(NAME test_str_comparison LABELS cpython llvm c wasm)
RUN(NAME test_bit_length LABELS cpython llvm c)
Expand Down Expand Up @@ -818,6 +823,7 @@ RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython)
# Intrinsic Functions
RUN(NAME intrinsics_01 LABELS cpython llvm NOFAST) # any
RUN(NAME intrinsics_02 LABELS cpython llvm c) # floordiv
RUN(NAME test_builtin_type LABELS cpython llvm c) # type

# lpython decorator
RUN(NAME lpython_decorator_01 LABELS cpython)
Expand Down
23 changes: 23 additions & 0 deletions integration_tests/array_expr_09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from lpython import (i32, Const)
from numpy import empty, int32

dim: Const[i32] = 2
dim2: Const[i32] = 3

def g():
a: i32[dim, dim2] = empty((dim, dim2), dtype=int32)
i1: i32 = 0
i2: i32 = 0
for i1 in range(dim):
for i2 in range(dim2):
a[i1, i2] = i32(i1 * dim2 + i2)
# a: [[0, 1, 2], [3, 4, 5]]
print(a)
assert a[-1, -1] == 5
assert a[-1, -2] == 4
assert a[-1, -3] == 3
assert a[-2, -1] == 2
assert a[-2, -2] == 1
assert a[-2, -3] == 0

g()
17 changes: 17 additions & 0 deletions integration_tests/array_expr_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from lpython import i32
from numpy import empty, int32, array

def foo(x: i32[:]):
print(x[3], x[4], x[-1], x[-2])
assert x[-1] == 5
assert x[-2] == 4
assert x[-3] == 3
assert x[-4] == 2
assert x[-5] == 1

def main():
x: i32[5] = empty(5, dtype=int32)
x = array([1, 2, 3, 4, 5])
foo(x)

main()
27 changes: 27 additions & 0 deletions integration_tests/test_builtin_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from lpython import i32, f64

def test_builtin_type():
i: i32 = 42
f: f64 = 64.0
s: str = "Hello, LPython!"
l: list[i32] = [1, 2, 3, 4, 5]
d: dict[str, i32] = {"a": 1, "b": 2, "c": 3}
res: str = ""

res = str(type(i))
print(res)
assert res == "<class 'int'>"
res = str(type(f))
print(res)
assert res == "<class 'float'>"
res = str(type(s))
print(res)
assert res == "<class 'str'>"
res = str(type(l))
print(res)
assert res == "<class 'list'>"
res = str(type(d))
print(res)
assert res == "<class 'dict'>"

test_builtin_type()
9 changes: 9 additions & 0 deletions integration_tests/test_global_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lpython import i32

s1: set[str] = {"a", "b", "c", "a"}
s2: set[i32] = {1, 2, 3, 1}
s3: set[tuple[i32, i32]] = {(1, 2), (2, 3), (4, 5)}

assert len(s1) == 3
assert len(s2) == 3
assert len(s3) == 3
34 changes: 30 additions & 4 deletions integration_tests/test_gruntz.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
from lpython import S
from sympy import Symbol, log
from sympy import Symbol, log, E, Pow

def mmrv(e: S, x: S) -> list[S]:
empty_list : list[S] = []
if not e.has(x):
list0: list[S] = []
return list0
return empty_list
elif e == x:
list1: list[S] = [x]
return list1
elif e.func == log:
arg0: S = e.args[0]
list2: list[S] = mmrv(arg0, x)
return list2
elif e.func == Pow:
if e.args[0] != E:
e1: S = S(1)
newe: S = e
while newe.func == Pow:
b1: S = newe.args[0]
e1 = e1 * newe.args[1]
newe = b1
if b1 == S(1):
return empty_list
if not e1.has(x):
list3: list[S] = mmrv(b1, x)
return list3
else:
# TODO as noted in #2526
pass
else:
# TODO
pass
else:
raise

Expand All @@ -35,6 +54,13 @@ def test_mrv():
ele2: S = ans3[0]
print(ele2)
assert ele2 == x
assert len(ans2) == 1
assert len(ans3) == 1

# Case 4
ans4: list[S] = mmrv(x**S(2), x)
ele3: S = ans4[0]
print(ele3)
assert ele3 == x
assert len(ans4) == 1

test_mrv()
22 changes: 22 additions & 0 deletions integration_tests/test_logical_assignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from lpython import i32, f64


def test_logical_assignment():
# Can be uncommented after fixing the segfault
# _LPYTHON: str = "LPython"
# s_var: str = "" or _LPYTHON
# assert s_var == "LPython"
# print(s_var)

_MAX_VAL: i32 = 100
i_var: i32 = 0 and 100
assert i_var == 0
print(i_var)

_PI: f64 = 3.14
f_var: f64 = 2.0 * _PI or _PI**2.0
assert f_var == 6.28
print(f_var)


test_logical_assignment()
130 changes: 130 additions & 0 deletions integration_tests/test_logical_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from lpython import i32, f64


def test_logical_compare_literal():
# Integers
print(1 or 3)
assert (1 or 3) == 1

print(1 and 3)
assert (1 and 3) == 3

print(2 or 3 or 5 or 6)
assert (2 or 3 or 5 or 6) == 2

print(1 and 3 or 2 and 4)
assert (1 and 3 or 2 and 4) == 3

print(1 or 3 and 0 or 4)
assert (1 or 3 and 0 or 4) == 1

print(1 and 3 or 2 and 0)
assert (1 and 3 or 2 and 0) == 3

print(1 and 0 or 3 and 4)
assert (1 and 0 or 3 and 4) == 4

# Floating-point numbers
print(1.33 or 6.67)
assert (1.33 or 6.67) == 1.33

print(1.33 and 6.67)
assert (1.33 and 6.67) == 6.67

print(1.33 or 6.67 and 3.33 or 0.0)
assert (1.33 or 6.67 and 3.33 or 0.0) == 1.33

print(1.33 and 6.67 or 3.33 and 0.0)
assert (1.33 and 6.67 or 3.33 and 0.0) == 6.67

print(1.33 and 0.0 and 3.33 and 6.67)
assert (1.33 and 0.0 and 3.33 and 6.67) == 0.0

# Strings
print("a" or "b")
assert ("a" or "b") == "a"

print("abc" or "b")
assert ("abc" or "b") == "abc"

print("a" and "b")
assert ("a" and "b") == "b"

print("a" or "b" and "c" or "d")
assert ("a" or "b" and "c" or "d") == "a"

print("" or " ")
assert ("" or " ") == " "

print("" and " " or "a" and "b" and "c")
assert ("" and " " or "a" and "b" and "c") == "c"

print("" and " " and "a" and "b" and "c")
assert ("" and " " and "a" and "b" and "c") == ""


def test_logical_compare_variable():
# Integers
i_a: i32 = 1
i_b: i32 = 3

print(i_a and i_b)
assert (i_a and i_b) == 3

print(i_a or i_b or 2 or 4)
assert (i_a or i_b or 2 or 4) == 1

print(i_a and i_b or 2 and 4)
assert (i_a and i_b or 2 and 4) == 3

print(i_a or i_b and 0 or 4)
assert (i_a or i_b and 0 or 4) == i_a

print(i_a and i_b or 2 and 0)
assert (i_a and i_b or 2 and 0) == i_b

print(i_a and 0 or i_b and 4)
assert (i_a and 0 or i_b and 4) == 4

print(i_a + i_b or 0 - 4)
assert (i_a + i_b or 0 - 4) == 4

# Floating-point numbers
f_a: f64 = 1.67
f_b: f64 = 3.33

print(f_a // f_b and f_a - f_b)
assert (f_a // f_b and f_a - f_b) == 0.0

print(f_a**3.0 or 3.0**f_a)
assert (f_a**3.0 or 3.0**f_a) == 4.657462999999999

print(f_a - 3.0 and f_a + 3.0 or f_b - 3.0 and f_b + 3.0)
assert (f_a - 3.0 and f_a + 3.0 or f_b - 3.0 and f_b + 3.0) == 4.67

# Can be uncommented after fixing the segfault
# Strings
# s_a: str = "a"
# s_b: str = "b"

# print(s_a or s_b)
# assert (s_a or s_b) == s_a

# print(s_a and s_b)
# assert (s_a and s_b) == s_b

# print(s_a + s_b or s_b + s_a)
# assert (s_a + s_b or s_b + s_a) == "ab"

# print(s_a[0] or s_b[-1])
# assert (s_a[0] or s_b[-1]) == "a"

# print(s_a[0] and s_b[-1])
# assert (s_a[0] and s_b[-1]) == "b"

# print(s_a + s_b or s_b + s_a + s_a[0] and s_b[-1])
# assert (s_a + s_b or s_b + s_a + s_a[0] and s_b[-1]) == "ab"


test_logical_compare_literal()
test_logical_compare_variable()
Loading

0 comments on commit ba4d09f

Please sign in to comment.