From 2edc1de0b64622305a6ccd0410b92a45d0d97980 Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 7 Mar 2024 13:08:45 +0800 Subject: [PATCH] standalone: Update ndarray.py to output all elements in ndarrays --- nac3standalone/demo/src/ndarray.py | 32 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/nac3standalone/demo/src/ndarray.py b/nac3standalone/demo/src/ndarray.py index 16eec74..353ebe5 100644 --- a/nac3standalone/demo/src/ndarray.py +++ b/nac3standalone/demo/src/ndarray.py @@ -9,12 +9,6 @@ def output_float64(x: float): 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(): n: ndarray[float, Literal[1]] = np_ndarray([1]) consume_ndarray_1(n) @@ -26,31 +20,29 @@ def test_ndarray_empty(): def test_ndarray_zeros(): n: ndarray[float, 1] = np_zeros([1]) output_float64(n[0]) - consume_ndarray_1(n) def test_ndarray_ones(): n: ndarray[float, 1] = np_ones([1]) output_float64(n[0]) - consume_ndarray_1(n) def test_ndarray_full(): n_float: ndarray[float, 1] = np_full([1], 2.0) output_float64(n_float[0]) - consume_ndarray_1(n_float) n_i32: ndarray[int32, 1] = np_full([1], 2) output_int32(n_i32[0]) - consume_ndarray_i32_1(n_i32) def test_ndarray_eye(): n: ndarray[float, 2] = np_eye(2) n0: ndarray[float, 1] = n[0] v: float = n0[0] output_float64(v) - consume_ndarray_2(n) def test_ndarray_identity(): n: ndarray[float, 2] = np_identity(2) - consume_ndarray_2(n) + output_float64(n[0][0]) + output_float64(n[0][1]) + output_float64(n[1][0]) + output_float64(n[1][1]) def test_ndarray_fill(): n: ndarray[float, 2] = np_empty([2, 2]) @@ -60,6 +52,21 @@ def test_ndarray_fill(): output_float64(n[1][0]) output_float64(n[1][1]) +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]) + def run() -> int32: test_ndarray_ctor() test_ndarray_empty() @@ -69,5 +76,6 @@ def run() -> int32: test_ndarray_eye() test_ndarray_identity() test_ndarray_fill() + test_ndarray_copy() return 0