-
Notifications
You must be signed in to change notification settings - Fork 171
Supporting list of lists, list of tuples and tuples with lists #952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6e46aad
Added test for list of tuples
czgdp1807 135a67f
Added test for list of lists
czgdp1807 1f88753
Added test for tuples of lists
czgdp1807 1534a3d
Handle deepcopy function calls
czgdp1807 2afbf1f
Added support for list.clear in ASR
czgdp1807 98556df
Added ListClear statement in ASR
czgdp1807 1610c7e
Added interface and inline implementations for following use cases,
czgdp1807 67868c4
Implemented code generation for the following,
czgdp1807 4d32dc4
Use updated APIs from llvm_utils.h
czgdp1807 6807960
Registered test_list_05/06/07.py
czgdp1807 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from ltypes import i32, f64 | ||
|
||
def check_list_of_tuples(l: list[tuple[i32, f64, str]], sign: i32): | ||
size: i32 = len(l) | ||
i: i32 | ||
t: tuple[i32, f64, str] | ||
string: str | ||
|
||
for i in range(size): | ||
t = l[i] | ||
string = str(sign * i) + "_str" | ||
assert t[0] == sign * i | ||
assert l[i][0] == sign * i | ||
|
||
assert t[1] == float(sign * i) | ||
assert l[i][1] == float(sign * i) | ||
|
||
assert t[2] == string | ||
assert l[i][2] == string | ||
|
||
def test_list_of_tuples(): | ||
l1: list[tuple[i32, f64, str]] = [] | ||
t: tuple[i32, f64, str] | ||
size: i32 = 20 | ||
i: i32 | ||
string: str | ||
|
||
for i in range(size): | ||
t = (i, float(i), str(i) + "_str") | ||
l1.append(t) | ||
|
||
check_list_of_tuples(l1, 1) | ||
|
||
for i in range(size//2): | ||
l1.remove(l1[len(l1) - 1]) | ||
|
||
t = l1[len(l1) - 1] | ||
assert t[0] == size//2 - 1 | ||
assert t[1] == size//2 - 1 | ||
assert t[2] == str(size//2 - 1) + "_str" | ||
|
||
for i in range(size//2, size): | ||
string = str(i) + "_str" | ||
t = (i, float(i), string) | ||
l1.insert(i, t) | ||
|
||
check_list_of_tuples(l1, 1) | ||
|
||
for i in range(size): | ||
string = str(-i) + "_str" | ||
t = (-i, float(-i), string) | ||
l1[i] = t | ||
|
||
check_list_of_tuples(l1, -1) | ||
|
||
test_list_of_tuples() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from ltypes import i32, f64 | ||
from copy import deepcopy | ||
|
||
def check_mat_and_vec(mat: list[list[f64]], vec: list[f64]): | ||
rows: i32 = len(mat) | ||
cols: i32 = len(vec) | ||
i: i32 | ||
j: i32 | ||
|
||
for i in range(rows): | ||
for j in range(cols): | ||
assert mat[i][j] == float(i + j) | ||
|
||
for i in range(cols): | ||
assert vec[i] == 2 * float(i) | ||
|
||
def test_list_of_lists(): | ||
tensors: list[list[list[list[f64]]]] = [] | ||
tensor: list[list[list[f64]]] = [] | ||
mat: list[list[f64]] = [] | ||
vec: list[f64] = [] | ||
rows: i32 = 10 | ||
cols: i32 = 5 | ||
i: i32 | ||
j: i32 | ||
k: i32 | ||
l: i32 | ||
|
||
for i in range(rows): | ||
for j in range(cols): | ||
vec.append(float(i + j)) | ||
mat.append(deepcopy(vec)) | ||
vec.clear() | ||
|
||
for i in range(cols): | ||
vec.append(2 * float(i)) | ||
|
||
check_mat_and_vec(mat, vec) | ||
|
||
for k in range(rows): | ||
tensor.append(deepcopy(mat)) | ||
for i in range(rows): | ||
for j in range(cols): | ||
mat[i][j] += float(1) | ||
|
||
for k in range(rows): | ||
for i in range(rows): | ||
for j in range(cols): | ||
assert mat[i][j] - tensor[k][i][j] == rows - k | ||
|
||
for l in range(2 * rows): | ||
tensors.append(deepcopy(tensor)) | ||
for i in range(rows): | ||
for j in range(rows): | ||
for k in range(cols): | ||
tensor[i][j][k] += float(1) | ||
|
||
for l in range(2 * rows): | ||
for i in range(rows): | ||
for j in range(rows): | ||
for k in range(cols): | ||
assert tensor[i][j][k] - tensors[l][i][j][k] == 2 * rows - l | ||
|
||
test_list_of_lists() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from ltypes import c64, i32 | ||
from copy import deepcopy | ||
|
||
def test_tuple_with_lists(): | ||
mat: list[list[c64]] = [] | ||
vec: list[c64] = [] | ||
tensor: tuple[list[list[c64]], list[c64]] | ||
tensors: list[tuple[list[list[c64]], list[c64]]] = [] | ||
i: i32 | ||
j: i32 | ||
k: i32 | ||
l: i32 | ||
rows: i32 = 10 | ||
cols: i32 = 5 | ||
|
||
for i in range(rows): | ||
for j in range(cols): | ||
vec.append(complex(i + j, 0)) | ||
mat.append(deepcopy(vec)) | ||
vec.clear() | ||
|
||
for i in range(cols): | ||
vec.append(complex(2 * i, 0)) | ||
|
||
for i in range(rows): | ||
for j in range(cols): | ||
assert mat[i][j] - vec[j] == i - j | ||
|
||
tensor = (deepcopy(mat), deepcopy(vec)) | ||
|
||
for i in range(rows): | ||
for j in range(cols): | ||
mat[i][j] += complex(0, 3.0) | ||
|
||
for i in range(cols): | ||
vec[i] += complex(0, 2.0) | ||
|
||
for i in range(rows): | ||
for j in range(cols): | ||
assert tensor[0][i][j] - mat[i][j] == -complex(0, 3.0) | ||
|
||
for i in range(cols): | ||
assert tensor[1][i] - vec[i] == -complex(0, 2.0) | ||
|
||
tensor = (deepcopy(mat), deepcopy(vec)) | ||
|
||
for k in range(2 * rows): | ||
tensors.append(deepcopy(tensor)) | ||
for i in range(rows): | ||
for j in range(cols): | ||
mat[i][j] += complex(1.0, 2.0) | ||
|
||
for i in range(cols): | ||
vec[i] += complex(1.0, 2.0) | ||
|
||
tensor = (deepcopy(mat), deepcopy(vec)) | ||
|
||
for k in range(2 * rows): | ||
for i in range(rows): | ||
for j in range(cols): | ||
assert tensors[k][0][i][j] - mat[i][j] == -(2 * rows - k) * complex(1.0, 2.0) | ||
|
||
for k in range(2 * rows): | ||
for i in range(cols): | ||
assert tensors[k][1][i] - vec[i] == -(2 * rows - k) * complex(1.0, 2.0) | ||
|
||
test_tuple_with_lists() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.