-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial PythonCallable implementation (#1984)
- Loading branch information
1 parent
c459bb5
commit cad1bb8
Showing
5 changed files
with
240 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
from numpy import array | ||
from lpython import i32, f64, lpython, TypeVar | ||
from lpython import i32, i64, f64, lpython, TypeVar | ||
|
||
n = TypeVar("n") | ||
|
||
@lpython | ||
def multiply(n: i32, x: f64[:]) -> f64[n]: | ||
def multiply_01(n: i32, x: f64[:]) -> f64[n]: | ||
i: i32 | ||
for i in range(n): | ||
x[i] *= 5.0 | ||
return x | ||
|
||
def test(): | ||
size: i32 = 5 | ||
x: f64[5] = array([11.0, 12.0, 13.0, 14.0, 15.0]) | ||
y: f64[5] = (multiply(size, x)) | ||
@lpython | ||
def multiply_02(n: i32, x: i64[:], y: i64[:]) -> i64[n]: | ||
z: i64[n]; i: i32 | ||
for i in range(n): | ||
z[i] = x[i] * y[i] | ||
return z | ||
|
||
|
||
def test_01(): | ||
size = 5 | ||
x = array([11.0, 12.0, 13.0, 14.0, 15.0]) | ||
y = multiply_01(size, x) | ||
assert y[2] == 65. | ||
|
||
test() | ||
size = 3 | ||
x = array([11, 12, 13]) | ||
y = array([14, 15, 16]) | ||
z = multiply_02(size, x, y) | ||
for i in range(size): | ||
assert z[i] == x[i] * y[i] | ||
|
||
test_01() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.