from ltypes import f64, TypeVar
n = TypeVar('n')
@overload
def sqrt(x: f64[n]) -> f64[n]:
r: f64[n] = empty(size(x))
i: i32
for i in range(size(x)):
r[i] = sqrt(x[i])
return r
For a 2d array:
from ltypes import f64, TypeVar
n = TypeVar('n')
m = TypeVar('m')
@overload
def sqrt(x: f64[n,m]) -> f64[n,m]:
r: f64[n,m] = empty((size(x,1),size(x,2))) # or empty(shape(x))
i: i32
j: i32
for i in range(size(x,1)):
for j in range(size(x,2)):
r[i,j] = sqrt(x[i,j])
return r
For a 1D array:
For a 2d array: