Test failed - added support for int and float#1086
Test failed - added support for int and float#1086ronnuriel wants to merge 7 commits intolcompilers:mainfrom
Conversation
Signed-off-by: Ron Nuriel <rnuriel@gsitechnology.com>
bab8f5e to
7d5fc04
Compare
| def accept_int_array(xint: int[:]) -> i64: | ||
| xint[0] = 64 | ||
| return xint[0] | ||
|
|
There was a problem hiding this comment.
This works with LPython but not with CPython. CPython throws the following error,
Traceback (most recent call last):
File "/Users/czgdp1807/lpython_project/lpython/integration_tests/array_01_decl.py", line 12, in <module>
def accept_int_array(xint: int[:]) -> i64:
TypeError: 'type' object is not subscriptableSo I pushed 8336f96. Using py_float, py_int seems a bit hackish but then the alternative is to not support x: float[:], x: int[:], which makes reduces the significance of x: float use case. Like if users can only declare normal variables and not arrays using floating point annotations then its not worth it to support float annotation. What do you say @certik ?
There was a problem hiding this comment.
Is there any other way to achieve this (i.e., make the float[:] work with CPython)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Array[int] makes sense. For multi-dimensional arrays, should it look like, Array[Array[int]]? Plus then we should also support Array[Array[f32]] (similarly for all the ltypes).
There was a problem hiding this comment.
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 short i64[:,:] syntax. Also note that int in CPython means arbitrary precision integer, so we should not use it interchangeably with i64. However, float in CPython means f64, so that could be done, for scalars. For arrays of f64, the same issue happens. See #1107 for more discussion.
| 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") { |
There was a problem hiding this comment.
This we should not do, since int means arbitrary precision integer, which we will eventually support in LPython as well, but that is not the same as f64.
| @@ -0,0 +1,4 @@ | |||
| def test_dict(): | |||
| mydictionarty3: dict[int, float] = {} | |||
There was a problem hiding this comment.
This is currently not supported in LPython, as we do not allow arbitrary precision integers.
|
To move forward, I would not allow We could allow Instead, why don't we do the following: if a user writes |
|
I am marking this as Draft for now. If this becomes ready, just click on "Ready for review". |
Signed-off-by: Ron Nuriel rnuriel@gsitechnology.com