Skip to content

Commit

Permalink
Merge branch 'main' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kmr-srbh authored Mar 11, 2024
2 parents 7315c19 + 3e6ddc6 commit fbf788a
Show file tree
Hide file tree
Showing 121 changed files with 2,823 additions and 1,283 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install Windows Conda Packages
if: contains(matrix.os, 'windows')
shell: bash -e -l {0}
run: conda install m2-bison=3.0.4
run: conda install m2-bison=3.0.4 cmake=3.21.1

- name: Install Linux / macOS Conda Packages
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ RUN(NAME test_list_pop3 LABELS cpython llvm)
RUN(NAME test_list_compare LABELS cpython llvm)
RUN(NAME test_list_concat LABELS cpython llvm c NOFAST)
RUN(NAME test_list_reserve LABELS cpython llvm)
RUN(NAME test_const_list LABELS cpython llvm)
RUN(NAME test_tuple_01 LABELS cpython llvm c)
RUN(NAME test_tuple_02 LABELS cpython llvm c NOFAST)
RUN(NAME test_tuple_03 LABELS cpython llvm c)
Expand Down Expand Up @@ -729,6 +730,7 @@ RUN(NAME test_gruntz LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_15 LABELS c_sym llvm_sym NOFAST)
RUN(NAME symbolics_16 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_17 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_18 LABELS cpython_sym c_sym llvm_sym NOFAST)

RUN(NAME sizeof_01 LABELS llvm c
EXTRAFILES sizeof_01b.c)
Expand Down
41 changes: 40 additions & 1 deletion integration_tests/elemental_06.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lpython import i32, f32, f64
from numpy import empty, arcsin, arccos, sin, cos, sqrt, arctan, tan, degrees, radians, float32, float64
from numpy import empty, arcsin, arccos, sin, cos, sqrt, arctan, tan, degrees, radians, hypot, float32, float64
from math import pi

def verify1d_same(array: f32[:], result: f32[:], size: i32):
Expand Down Expand Up @@ -57,6 +57,15 @@ def verify_arctan_2d(array: f64[:, :], result: f64[:, :], size1:i32, size2:i32):
for j in range(size2):
assert abs(arctan(array[i, j])**2.0 - result[i, j]) <= eps

def verify_hypot_2d(array1: f64[:, :], array2: f64[:, :], result: f64[:, :], size1:i32, size2:i32):
i: i32
j: i32
eps: f64
eps = 1e-12
for i in range(size1):
for j in range(size2):
assert abs(hypot(array1[i, j], array2[i, j]) - result[i, j]) <= eps

def elemental_arcsin():
i: i32
j: i32
Expand Down Expand Up @@ -222,6 +231,35 @@ def elemental_radians():
for j in range(64):
assert abs(radians2d[i, j] - cos(radians(array2d[i, j]))) <= eps_64

def elemental_hypot():
i: i32
j: i32
eps_32: f32
eps_32 = f32(1e-6)

hypot1d: f32[200] = empty(200, dtype=float32)
array1d1: f32[200] = empty(200, dtype=float32)
array1d2: f32[200] = empty(200, dtype=float32)
for i in range(200):
array1d1[i] = f32(i)
array1d2[i] = f32(i+10)

hypot1d = hypot(array1d1, array1d2)

for i in range(200):
assert abs(hypot1d[i] - hypot(array1d1[i], array1d2[i])) <= eps_32

array2d1: f64[64, 64] = empty((64, 64), dtype=float64)
array2d2: f64[64, 64] = empty((64, 64), dtype=float64)
hypot2d: f64[64, 64] = empty((64, 64), dtype=float64)
for i in range(64):
for j in range(64):
array2d1[i,j]= float(i * j)
array2d2[i,j]= float(64*i + j - 2048)

hypot2d = hypot(array2d1, array2d2)
verify_hypot_2d(array2d1, array2d2, hypot2d, 64, 64)


elemental_arcsin()
elemental_arccos()
Expand All @@ -231,3 +269,4 @@ def elemental_radians():
elemental_trig_identity()
elemental_reverse()
elemental_trig_identity_extra()
elemental_hypot()
36 changes: 36 additions & 0 deletions integration_tests/symbolics_18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from lpython import S
from sympy import Symbol, log

def func_01(e: S, x: S) -> S:
print(e)
if e == x:
return x
print(e)
return e

def test_func_01():
x: S = Symbol("x")
ans: S = func_01(log(x), x)
print(ans)

def func_02(e: S, x: S) -> list[S]:
print(e)
if e == x:
list1: list[S] = [x]
return list1
else:
print(e)
list2: list[S] = func_02(x, x)
return list2

def test_func_02():
x: S = Symbol("x")
ans: list[S] = func_02(log(x), x)
ele: S = ans[0]
print(ele)

def tests():
test_func_01()
test_func_02()

tests()
19 changes: 19 additions & 0 deletions integration_tests/test_const_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from lpython import i32, Const


def test_const_list():
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1]

print(CONST_INTEGER_LIST.count(1))
print(CONST_INTEGER_LIST.index(1))
assert CONST_INTEGER_LIST.count(1) == 2
assert CONST_INTEGER_LIST.index(1) == 0

CONST_STRING_LIST: Const[list[str]] = ["ALPHA", "BETA", "RELEASE"]
print(CONST_STRING_LIST.count("ALPHA"))
print(CONST_STRING_LIST.index("RELEASE"))
assert CONST_STRING_LIST.count("ALPHA") == 1
assert CONST_STRING_LIST.index("RELEASE") == 2


test_const_list()
50 changes: 50 additions & 0 deletions integration_tests/test_str_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,55 @@ def test_str_split():
assert res5 == ["123"]
# assert res6 == [""]

def test_str_replace():
x: str = "abc"
a: str = "zzaaabracadabra"
print(a.replace("a",""))
print(a.replace("",""))
print(a.replace("a","b"))
print(a.replace("e","a"))
print(a.replace("ab","ba"))
print(a.replace("c","z"))
print(a.replace("zza","yo"))
print(a.replace("a","b",0))
print(a.replace("a","b",1))
print(a.replace("a","b",2))
print(a.replace("a","b",2))
print(a.replace("a","b",3))
print(a.replace("a","b",4))
print(a.replace("a","b",5))
print(a.replace("a","b",6))
print(a.replace("a","b",7))
print(a.replace("a","b",8))
print(a.replace("a","b",9))
print(a.replace("b","k",1))
print(a.replace("b","k",2))
print(a.replace("zza","yo",2))
print(x.replace("", ","))
assert a.replace("a","") == "zzbrcdbr"
assert a.replace("","") == "zzaaabracadabra"
assert a.replace("a","b") == "zzbbbbrbcbdbbrb"
assert a.replace("e","a") == "zzaaabracadabra"
assert a.replace("ab","ba") == "zzaabaracadbara"
assert a.replace("c","z") == "zzaaabrazadabra"
assert a.replace("zza","yo") == "yoaabracadabra"
assert a.replace("a","b",0) == "zzaaabracadabra"
assert a.replace("a","b",1) == "zzbaabracadabra"
assert a.replace("a","b",2) == "zzbbabracadabra"
assert a.replace("a","b",2) == "zzbbabracadabra"
assert a.replace("a","b",3) == "zzbbbbracadabra"
assert a.replace("a","b",4) == "zzbbbbrbcadabra"
assert a.replace("a","b",5) == "zzbbbbrbcbdabra"
assert a.replace("a","b",6) == "zzbbbbrbcbdbbra"
assert a.replace("a","b",7) == "zzbbbbrbcbdbbrb"
assert a.replace("a","b",8) == "zzbbbbrbcbdbbrb"
assert a.replace("a","b",9) == "zzbbbbrbcbdbbrb"
assert a.replace("b","k",1) == "zzaaakracadabra"
assert a.replace("b","k",2) == "zzaaakracadakra"
assert a.replace("zza","yo",2) == "yoaabracadabra"
assert x.replace("", ",") == ",a,b,c,"


def check():
f()
test_str_concat()
Expand All @@ -127,5 +176,6 @@ def check():
test_constant_str_subscript()
test_str_title()
test_str_split()
test_str_replace()

check()
64 changes: 64 additions & 0 deletions integration_tests/test_str_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,69 @@ def is_space():
s = ""
assert s.isspace() == False

def is_alnum():
a: str = "helloworld"
b: str = "hj kl"
c: str = "a12(){}A"
d: str = " "
e: str = ""
f: str = "ab23"
g: str = "ab2%3"
res: bool = a.isalnum()
res2: bool = b.isalnum()
res3: bool = c.isalnum()
res4: bool = d.isalnum()
res5: bool = e.isalnum()
res6: bool = f.isalnum()
res7: bool = g.isalnum()

assert res == True
assert res2 == False
assert res3 == False
assert res4 == False
assert res5 == False
assert res6 == True
assert res7 == False

assert "helloworld".isalnum() == True
assert "hj kl".isalnum() == False
assert "a12(){}A".isalnum() == False
assert " ".isalnum() == False
assert "".isalnum() == False
assert "ab23".isalnum() == True
assert "ab2%3".isalnum() == False

def is_numeric():
a: str = "123"
b: str = "12 34"
c: str = "-123"
d: str = "12.3"
e: str = " "
f: str = ""
g: str = "ab2%3"
res: bool = a.isnumeric()
res2: bool = b.isnumeric()
res3: bool = c.isnumeric()
res4: bool = d.isnumeric()
res5: bool = e.isnumeric()
res6: bool = f.isnumeric()
res7: bool = g.isnumeric()

assert res == True
assert res2 == False
assert res3 == False
assert res4 == False
assert res5 == False
assert res6 == False
assert res7 == False

assert "123".isnumeric() == True
assert "12 34".isnumeric() == False
assert "-123".isnumeric() == False
assert "12.3".isnumeric() == False
assert " ".isnumeric() == False
assert "".isnumeric() == False
assert "ab2%3".isnumeric() == False

def check():
capitalize()
Expand All @@ -386,6 +448,8 @@ def check():
is_alpha()
is_title()
is_space()
is_alnum()
is_numeric()


check()
6 changes: 6 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def is_included(backend):
llvm_dbg = is_included("llvm_dbg")
cpp = is_included("cpp")
c = is_included("c")
python = is_included("python")
is_cumulative = is_included("cumulative")
wat = is_included("wat")
run = is_included("run")
Expand Down Expand Up @@ -133,6 +134,11 @@ def is_included(backend):
else:
run_test(filename, "c", "lpython --no-color --show-c {infile}",
filename, update_reference, extra_args)

if python:
run_test(filename, "python", "lpython --no-color --show-python {infile}",
filename, update_reference, extra_args)

if wat:
run_test(filename, "wat", "lpython --no-color --show-wat {infile}",
filename, update_reference, extra_args)
Expand Down
Loading

0 comments on commit fbf788a

Please sign in to comment.