2024-02-19 17:10:44 +08:00
|
|
|
@extern
|
|
|
|
def output_int32(x: int32):
|
|
|
|
...
|
|
|
|
|
|
|
|
@extern
|
|
|
|
def output_float64(x: float):
|
|
|
|
...
|
|
|
|
|
2023-11-17 17:30:27 +08:00
|
|
|
def consume_ndarray_1(n: ndarray[float, Literal[1]]):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def consume_ndarray_i32_1(n: ndarray[int32, Literal[1]]):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def consume_ndarray_2(n: ndarray[float, Literal[2]]):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_ndarray_ctor():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, Literal[1]] = np_ndarray([1])
|
2023-11-17 17:30:27 +08:00
|
|
|
consume_ndarray_1(n)
|
|
|
|
|
|
|
|
def test_ndarray_empty():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, 1] = np_empty([1])
|
2023-11-17 17:30:27 +08:00
|
|
|
consume_ndarray_1(n)
|
|
|
|
|
2023-11-27 13:25:53 +08:00
|
|
|
def test_ndarray_zeros():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, 1] = np_zeros([1])
|
2024-02-19 17:10:44 +08:00
|
|
|
output_float64(n[0])
|
2023-11-27 13:25:53 +08:00
|
|
|
consume_ndarray_1(n)
|
|
|
|
|
|
|
|
def test_ndarray_ones():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, 1] = np_ones([1])
|
2024-02-19 17:10:44 +08:00
|
|
|
output_float64(n[0])
|
2023-11-27 13:25:53 +08:00
|
|
|
consume_ndarray_1(n)
|
|
|
|
|
|
|
|
def test_ndarray_full():
|
2024-02-06 12:29:21 +08:00
|
|
|
n_float: ndarray[float, 1] = np_full([1], 2.0)
|
2024-02-19 17:10:44 +08:00
|
|
|
output_float64(n_float[0])
|
2023-11-27 13:25:53 +08:00
|
|
|
consume_ndarray_1(n_float)
|
2024-02-06 12:29:21 +08:00
|
|
|
n_i32: ndarray[int32, 1] = np_full([1], 2)
|
2024-02-19 17:10:44 +08:00
|
|
|
output_int32(n_i32[0])
|
2023-11-27 13:25:53 +08:00
|
|
|
consume_ndarray_i32_1(n_i32)
|
|
|
|
|
|
|
|
def test_ndarray_eye():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, 2] = np_eye(2)
|
2024-02-19 17:10:44 +08:00
|
|
|
n0: ndarray[float, 1] = n[0]
|
|
|
|
v: float = n0[0]
|
|
|
|
output_float64(v)
|
2023-11-27 13:25:53 +08:00
|
|
|
consume_ndarray_2(n)
|
|
|
|
|
|
|
|
def test_ndarray_identity():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, 2] = np_identity(2)
|
2023-11-27 13:25:53 +08:00
|
|
|
consume_ndarray_2(n)
|
|
|
|
|
2023-11-17 17:30:27 +08:00
|
|
|
def run() -> int32:
|
|
|
|
test_ndarray_ctor()
|
|
|
|
test_ndarray_empty()
|
2023-11-27 13:25:53 +08:00
|
|
|
test_ndarray_zeros()
|
|
|
|
test_ndarray_ones()
|
|
|
|
test_ndarray_full()
|
|
|
|
test_ndarray_eye()
|
|
|
|
test_ndarray_identity()
|
2023-11-17 17:30:27 +08:00
|
|
|
|
|
|
|
return 0
|