From 70595bd87efccb48a5717f6b34ad4a0317e3c575 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Wed, 8 Jul 2020 22:58:20 -0700 Subject: [PATCH] Add sample for exercising the compiler. --- python/samples/compiled_add.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 python/samples/compiled_add.py diff --git a/python/samples/compiled_add.py b/python/samples/compiled_add.py new file mode 100644 index 000000000..1b19a92f2 --- /dev/null +++ b/python/samples/compiled_add.py @@ -0,0 +1,18 @@ +# Run full pipeline with: +# -npcomp-cpa-type-inference -numpy-public-functions-to-tensor -convert-numpy-to-tcf -canonicalize + +import numpy as np +from npcomp.compiler import test_config + +import_global = test_config.create_import_dump_decorator() + +global_data = (np.zeros((2, 3)) + [1.0, 2.0, 3.0] * np.reshape([1.0, 2.0], + (2, 1))) + +a = np.asarray([1.0, 2.0], dtype=np.float32) +b = np.asarray([3.0, 4.0], dtype=np.float32) + + +@import_global +def global_add(): + return np.add(a, np.add(b, a))