lpython
lpython copied to clipboard
TypeVars in parameter declaration versus return types
from numpy import array, empty, int16
from lpython import (i16, i32, c_p_pointer, Pointer, CPtr, TypeVar)
Tn = TypeVar("n")
Tm = TypeVar("m")
Tl = TypeVar("l")
def THIS_WORKS(Anm_l4: CPtr, Tn: i32, Tm: i32, l: i32) -> i16[Tn, Tm]:
A_nm: i16[Tn, Tm] = empty((Tn, Tm), dtype=int16)
return A_nm
def THIS_DOESNT_WORK(d: i16[Tm, Tn], b: CPtr, Tm: i32, Tn: i32) -> None:
B: Pointer[i16[:]] = c_p_pointer(b, i16[:], array([Tm * Tn]))
i: i32
j: i32
for i in range(Tm):
for j in range(Tn):
d[i, j] = B[(i * Tn) + j]
(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)────(brian@MacBook-Pro:s001)─┐
└─(18:59:21 on vector-backend ✹ ✭)──> lpython ../ISSUES/Issue2496.py 2 ↵ ──(Tue,Feb06)─┘
semantic error: Only those local variables which can be reduced to compile time constant should be used in dimensions of an array.
--> ../ISSUES/Issue2496.py:15:29
|
15 | def THIS_DOESNT_WORK(d: i16[Tm, Tn], b: CPtr, Tm: i32, Tn: i32) -> None:
| ^^
Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.
(lp) ┌─(~/Documents/GitHub/lpython/integration_tests)────(brian@MacBook-Pro:s001)─┐
└─(19:00:06 on vector-backend ✹ ✭)──> PYTHONPATH=".:../src/runtime/lpython:.." LPYTHON_PY_MOD_NAME="" LPYTHON_PY_MOD_PATH="_lpython-tmp-test-cpython" python ../ISSUES/Issue2496.py
I miswrote this issue.
Reopened with correct statement of the problem.
Also fails with
Tn = TypeVar("Tn")
Tm = TypeVar("Tm")
Tl = TypeVar("Tl")
Marking this as severe because without advice or a fix or a workaround, I cannot pass arrays as parameters to functions. I must manually inline all code, and that's very nasty.