From 53d44b95954c59dcb10a8b6b57870007872844b4 Mon Sep 17 00:00:00 2001 From: David Mak Date: Tue, 11 Jun 2024 15:30:57 +0800 Subject: [PATCH] standalone: Add np_array tests --- nac3standalone/demo/interpret_demo.py | 1 + nac3standalone/demo/src/ndarray.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/nac3standalone/demo/interpret_demo.py b/nac3standalone/demo/interpret_demo.py index a26418427..1b68bea6d 100755 --- a/nac3standalone/demo/interpret_demo.py +++ b/nac3standalone/demo/interpret_demo.py @@ -170,6 +170,7 @@ def patch(module): module.np_full = np.full module.np_eye = np.eye module.np_identity = np.identity + module.np_array = np.array # NumPy Math functions module.np_isnan = np.isnan diff --git a/nac3standalone/demo/src/ndarray.py b/nac3standalone/demo/src/ndarray.py index fc60e04e8..2b948b17a 100644 --- a/nac3standalone/demo/src/ndarray.py +++ b/nac3standalone/demo/src/ndarray.py @@ -97,6 +97,19 @@ def test_ndarray_eye(): n: ndarray[float, 2] = np_eye(2) output_ndarray_float_2(n) +def test_ndarray_array(): + n1: ndarray[float, 1] = np_array([1.0, 2.0, 3.0]) + output_ndarray_float_1(n1) + n1to2: ndarray[float, 2] = np_array([1.0, 2.0, 3.0], ndmin=2) + output_ndarray_float_2(n1to2) + n2: ndarray[float, 2] = np_array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) + output_ndarray_float_2(n2) + + # Copy + n2_cpy: ndarray[float, 2] = np_array(n2, copy=False) + n2_cpy.fill(0.0) + output_ndarray_float_2(n2_cpy) + def test_ndarray_identity(): n: ndarray[float, 2] = np_identity(2) output_ndarray_float_2(n) @@ -1373,6 +1386,7 @@ def run() -> int32: test_ndarray_ones() test_ndarray_full() test_ndarray_eye() + test_ndarray_array() test_ndarray_identity() test_ndarray_fill() test_ndarray_copy()