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 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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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])
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
def test_ndarray_identity():
|
2024-02-06 12:29:21 +08:00
|
|
|
n: ndarray[float, 2] = np_identity(2)
|
2024-03-07 13:08:45 +08:00
|
|
|
output_float64(n[0][0])
|
|
|
|
output_float64(n[0][1])
|
|
|
|
output_float64(n[1][0])
|
|
|
|
output_float64(n[1][1])
|
2023-11-27 13:25:53 +08:00
|
|
|
|
2024-03-06 16:53:41 +08:00
|
|
|
def test_ndarray_fill():
|
|
|
|
n: ndarray[float, 2] = np_empty([2, 2])
|
|
|
|
n.fill(1.0)
|
|
|
|
output_float64(n[0][0])
|
|
|
|
output_float64(n[0][1])
|
|
|
|
output_float64(n[1][0])
|
|
|
|
output_float64(n[1][1])
|
|
|
|
|
2024-03-07 13:08:45 +08:00
|
|
|
def test_ndarray_copy():
|
|
|
|
x: ndarray[float, 2] = np_identity(2)
|
|
|
|
y = x.copy()
|
|
|
|
x.fill(0.0)
|
|
|
|
|
|
|
|
output_float64(x[0][0])
|
|
|
|
output_float64(x[0][1])
|
|
|
|
output_float64(x[1][0])
|
|
|
|
output_float64(x[1][1])
|
|
|
|
|
|
|
|
output_float64(y[0][0])
|
|
|
|
output_float64(y[0][1])
|
|
|
|
output_float64(y[1][0])
|
|
|
|
output_float64(y[1][1])
|
|
|
|
|
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()
|
2024-03-06 16:53:41 +08:00
|
|
|
test_ndarray_fill()
|
2024-03-07 13:08:45 +08:00
|
|
|
test_ndarray_copy()
|
2023-11-17 17:30:27 +08:00
|
|
|
|
|
|
|
return 0
|