Open rebcabin opened 7 months ago
The following is a workaround. Leaving this open as a Design Change Request because I would like to see either documentation or a more discoverable / intuitive design for returning arrays from functions:
rows = TypeVar("rows")
cols = TypeVar("cols")
def load_lpython_array_from_c_fortran_array(b: CPtr, rows: i32, cols: i32) -> i16[rows, cols]:
"""Load an LPython array from a C / Fortran array."""
B: Pointer[i16[:]] = c_p_pointer(b, i16[:], array([rows * cols]))
D: i16[rows, cols] = empty((rows, cols), dtype=int16)
i: i32
j: i32
for i in range(rows):
for j in range(cols):
D[i, j] = B[(i * cols) + j]
return D
All these work in CPython. LPython produces an unhandled exception: