core: Add test for indexing into ndarray

This commit is contained in:
David Mak 2024-02-19 17:10:44 +08:00
parent cc538d221a
commit 22e831cb76
1 changed files with 15 additions and 0 deletions

View File

@ -1,3 +1,11 @@
@extern
def output_int32(x: int32):
...
@extern
def output_float64(x: float):
...
def consume_ndarray_1(n: ndarray[float, Literal[1]]): def consume_ndarray_1(n: ndarray[float, Literal[1]]):
pass pass
@ -17,20 +25,27 @@ def test_ndarray_empty():
def test_ndarray_zeros(): def test_ndarray_zeros():
n: ndarray[float, 1] = np_zeros([1]) n: ndarray[float, 1] = np_zeros([1])
output_float64(n[0])
consume_ndarray_1(n) consume_ndarray_1(n)
def test_ndarray_ones(): def test_ndarray_ones():
n: ndarray[float, 1] = np_ones([1]) n: ndarray[float, 1] = np_ones([1])
output_float64(n[0])
consume_ndarray_1(n) consume_ndarray_1(n)
def test_ndarray_full(): def test_ndarray_full():
n_float: ndarray[float, 1] = np_full([1], 2.0) n_float: ndarray[float, 1] = np_full([1], 2.0)
output_float64(n_float[0])
consume_ndarray_1(n_float) consume_ndarray_1(n_float)
n_i32: ndarray[int32, 1] = np_full([1], 2) n_i32: ndarray[int32, 1] = np_full([1], 2)
output_int32(n_i32[0])
consume_ndarray_i32_1(n_i32) consume_ndarray_i32_1(n_i32)
def test_ndarray_eye(): def test_ndarray_eye():
n: ndarray[float, 2] = np_eye(2) n: ndarray[float, 2] = np_eye(2)
n0: ndarray[float, 1] = n[0]
v: float = n0[0]
output_float64(v)
consume_ndarray_2(n) consume_ndarray_2(n)
def test_ndarray_identity(): def test_ndarray_identity():