-
Notifications
You must be signed in to change notification settings - Fork 165
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
BindPython ASR Pass: aggregate type conversions #2803
Merged
Shaikh-Ubaid
merged 10 commits into
lcompilers:main
from
Vipul-Cariappa:BindPython-aggregate-type
Aug 18, 2024
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9d881a6
native to cpython tuple conversion
Vipul-Cariappa 2b3bd2d
PythonBind ABI: native to cpython list conversion
Vipul-Cariappa 45a774a
PythonBind ABI: native to cpython set conversion
Vipul-Cariappa 4a97719
PythonBind ABI: native to cpython dict conversion
Vipul-Cariappa fe46c5e
PythonBind ABI: cpython to native list conversion
Vipul-Cariappa 4a95a97
PythonBind ABI: cpython to native tuple conversion
Vipul-Cariappa 7c98f66
PythonBind ABI: cpython to native set conversion
Vipul-Cariappa b6cbaa0
PythonBind ABI: cpython to native dict conversion
Vipul-Cariappa 4f6714f
PythonBind ABI: testing aggregate type conversions
Vipul-Cariappa ca09e53
NOFAST for bindpy_06 test
Vipul-Cariappa 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 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 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,72 @@ | ||
from lpython import i32, f64, pythoncall, Const | ||
from numpy import empty, int32, float64 | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_cpython_version() -> str: | ||
pass | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_dict(d: dict[str, i32]) -> dict[str, i32]: | ||
pass | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_list(d: list[str]) -> list[str]: | ||
pass | ||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_tuple(t: tuple[i32, i32]) -> tuple[i32, i32, i32]: | ||
pass | ||
|
||
|
||
@pythoncall(module = "bindpy_06_module") | ||
def get_modified_set(s: set[i32]) -> set[i32]: | ||
pass | ||
|
||
|
||
def test_list(): | ||
l: list[str] = ["LPython"] | ||
lr: list[str] = get_modified_list(l) | ||
assert len(lr) == 2 | ||
assert lr[0] == "LPython" | ||
assert lr[1] == "LFortran" | ||
|
||
|
||
def test_tuple(): | ||
t: tuple[i32, i32] = (2, 4) | ||
tr: tuple[i32, i32, i32] = get_modified_tuple(t) | ||
assert tr[0] == t[0] | ||
assert tr[1] == t[1] | ||
assert tr[2] == t[0] + t[1] | ||
|
||
|
||
def test_set(): | ||
s: set[i32] = {1, 2, 3} | ||
sr: set[i32] = get_modified_set(s) | ||
assert len(sr) == 4 | ||
assert 1 in sr | ||
assert 2 in sr | ||
assert 3 in sr | ||
assert 100 in sr | ||
|
||
|
||
def test_dict(): | ||
d: dict[str, i32] = { | ||
"LPython": 50 | ||
} | ||
dr: dict[str, i32] = get_modified_dict(d) | ||
assert len(dr) == 2 | ||
assert dr["LPython"] == 50 | ||
assert dr["LFortran"] == 100 | ||
|
||
|
||
def main0(): | ||
test_list() | ||
test_tuple() | ||
test_set() | ||
test_dict() | ||
|
||
|
||
main0() |
This file contains 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,24 @@ | ||
import platform | ||
|
||
|
||
def get_cpython_version(): | ||
return platform.python_version() | ||
|
||
|
||
def get_modified_dict(d): | ||
d["LFortran"] = 100 | ||
return d | ||
|
||
|
||
def get_modified_list(l): | ||
l.append("LFortran") | ||
return l | ||
|
||
|
||
def get_modified_tuple(t): | ||
return (t[0], t[1], t[0] + t[1]) | ||
|
||
|
||
def get_modified_set(s): | ||
s.add(100) | ||
return s |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add NOFAST to this. Also, I think we should be testing this with
cpython
as well to ensure what we support also works with CPython. We should not support something that is not supported with CPython.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test bindpy_05.py with CPython.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindpy_05.py
with cpython fails with:I have added cpython for
bindpy_06
andNOFAST
flag.