-
Notifications
You must be signed in to change notification settings - Fork 176
Test failed - added support for int and float #1086
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
base: main
Are you sure you want to change the base?
Changes from all commits
02a3be8
9d4221b
e584ac5
7d5fc04
8336f96
e7ca35a
303d8dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -762,13 +762,13 @@ class CommonVisitor : public AST::BaseVisitor<Derived> { | |
| } else if (var_annotation == "i32") { | ||
| type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, | ||
| 4, dims.p, dims.size())); | ||
| } else if (var_annotation == "i64") { | ||
| } else if (var_annotation == "i64" || var_annotation == "int") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This we should not do, since |
||
| type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, | ||
| 8, dims.p, dims.size())); | ||
| } else if (var_annotation == "f32") { | ||
| type = ASRUtils::TYPE(ASR::make_Real_t(al, loc, | ||
| 4, dims.p, dims.size())); | ||
| } else if (var_annotation == "f64") { | ||
| } else if (var_annotation == "f64" || var_annotation == "float") { | ||
| type = ASRUtils::TYPE(ASR::make_Real_t(al, loc, | ||
| 8, dims.p, dims.size())); | ||
| } else if (var_annotation == "c32") { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| def test_dict(): | ||
| mydictionarty3: dict[int, float] = {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is currently not supported in LPython, as we do not allow arbitrary precision integers. |
||
|
|
||
| test_dict() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| def test_dict(): | ||
| mydictionarty3: dict[float, int] = {} | ||
|
|
||
| test_dict() |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "basename": "asr-dict_expr_01-9c1f5d8", | ||
| "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
| "infile": "tests/dict_expr_01.py", | ||
| "infile_hash": "e31da5228b0722933947559f021553ddf900cedbfeecc93fa71d5761", | ||
| "outfile": null, | ||
| "outfile_hash": null, | ||
| "stdout": "asr-dict_expr_01-9c1f5d8.stdout", | ||
| "stdout_hash": "60af4235ccd42a13ac0b6ce36d8814e168286fb51a1ef2660d3b8339", | ||
| "stderr": null, | ||
| "stderr_hash": null, | ||
| "returncode": 0 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| (TranslationUnit (SymbolTable 1 {_lpython_main_program: (Function (SymbolTable 4 {}) _lpython_main_program [] [] [(SubroutineCall 1 test_dict () [] ())] () Source Public Implementation () .false. .false. .false. .false.), main_program: (Program (SymbolTable 3 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), test_dict: (Function (SymbolTable 2 {mydictionarty3: (Variable 2 mydictionarty3 Local () () Default (Dict (Integer 8 []) (Real 8 [])) Source Public Required .false.)}) test_dict [] [] [(= (Var 2 mydictionarty3) (DictConstant [] [] (Dict (Integer 8 []) (Real 8 []))) ())] () Source Public Implementation () .false. .false. .false. .false.)}) []) |
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.
This works with LPython but not with CPython. CPython throws the following error,
So I pushed 8336f96. Using
py_float,py_intseems a bit hackish but then the alternative is to not supportx: float[:],x: int[:], which makes reduces the significance ofx: floatuse case. Like if users can only declare normal variables and not arrays using floating point annotations then its not worth it to supportfloatannotation. What do you say @certik ?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.
Is there any other way to achieve this (i.e., make the
float[:]work 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.
Why not something like
Array[int]?int[:]might not be in the spirit of PEP 483.I general, we should never have something that works in LPython and not in CPython. That's an extension of Python and is a road to perdition! The reverse is ok IMO.
Uh oh!
There was an error while loading. Please reload this page.
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.
Array[int]makes sense. For multi-dimensional arrays, should it look like,Array[Array[int]]? Plus then we should also supportArray[Array[f32]](similarly for all theltypes).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.
This is a more complex issue, so I created #1107 where we can discuss it more. In short:
Array[int, :, :]can probably be done, but it's quite verbose, so we should first decide if we want to go this route, in addition (or even instead!) of the shorti64[:,:]syntax. Also note thatintin CPython means arbitrary precision integer, so we should not use it interchangeably withi64. However,floatin CPython meansf64, so that could be done, for scalars. For arrays off64, the same issue happens. See #1107 for more discussion.