You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a: f32[10000]
a = numpy.empty(10000, dtype=numpy.float32)
Both of which work in CPython/NumPy. This follows LPython's initial design that requires everything to be explicitly typed. In both cases, a is "declared" as a local array and allocated (on stack or heap, that is ASR backend dependent).
Later on, as we implement type inference, we can omit the type annotation, and just do:
a = numpy.empty(10000, dtype=numpy.float32)
and the compiler will infer the type f32[10000] for a from the RHS.
If the array is only typed using a: f32[10000] but never assigned to using a = numpy.empty(10000, dtype=numpy.float32) or similar, then LPython should given an error message.
Activity
certik commentedon Jan 5, 2022
One way that would definitely work is to make LPython infer the type and array size from the RHS from a code like this:
The alternative, that is, to declare arrays as:
and somehow make it work with CPython is unclear, as somehow the type annotation would need to "execute" and call NumPy.
certik commentedon Jan 6, 2022
After discussing with @namannimmo10, I think the best way is to use:
or an equivalent:
Both of which work in CPython/NumPy. This follows LPython's initial design that requires everything to be explicitly typed. In both cases,
ais "declared" as a local array and allocated (on stack or heap, that is ASR backend dependent).Later on, as we implement type inference, we can omit the type annotation, and just do:
and the compiler will infer the type
f32[10000]forafrom the RHS.If the array is only typed using
a: f32[10000]but never assigned to usinga = numpy.empty(10000, dtype=numpy.float32)or similar, then LPython should given an error message.certik commentedon Jan 7, 2022
Here is another example. This should give a compiler error, that
bis not allocated:The way to write it is as:
or like this:
Another example: this should work, and
bis a pointer toa.certik commentedon Mar 21, 2023
This is mostly fixed, I opened up an issue with the remaining bug: #1599