From 0a8487213b4a5292e2685bd28ab01bc5e55018e8 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Fri, 26 Jan 2024 16:11:30 -0500 Subject: [PATCH] Add dataset generator and test. --- .../python/ml/test/TestTensorflowModel.java | 1 + .../data/tensorflow.xml | 10 ++++++++++ .../data/tf2_test_dataset10.py | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 com.ibm.wala.cast.python.test/data/tf2_test_dataset10.py diff --git a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflowModel.java b/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflowModel.java index f42c8a7da..eafe1a115 100644 --- a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflowModel.java +++ b/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflowModel.java @@ -214,6 +214,7 @@ public void testTf2() testTf2("tf2_test_dataset7.py", "add", 2, 2, 2, 3); testTf2("tf2_test_dataset8.py", "add", 2, 2, 2, 3); testTf2("tf2_test_dataset9.py", "add", 2, 2, 2, 3); + testTf2("tf2_test_dataset10.py", "add", 2, 2, 2, 3); testTf2("tf2_test_tensor_list.py", "add", 2, 2, 2, 3); testTf2("tf2_test_tensor_list2.py", "add", 0, 0); testTf2("tf2_test_tensor_list3.py", "add", 0, 0); diff --git a/com.ibm.wala.cast.python.ml/data/tensorflow.xml b/com.ibm.wala.cast.python.ml/data/tensorflow.xml index 60a30dd4d..8cc2c550c 100644 --- a/com.ibm.wala.cast.python.ml/data/tensorflow.xml +++ b/com.ibm.wala.cast.python.ml/data/tensorflow.xml @@ -61,6 +61,8 @@ + + @@ -790,6 +792,14 @@ + + + + + + + + diff --git a/com.ibm.wala.cast.python.test/data/tf2_test_dataset10.py b/com.ibm.wala.cast.python.test/data/tf2_test_dataset10.py new file mode 100644 index 000000000..bf7392bfb --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/tf2_test_dataset10.py @@ -0,0 +1,20 @@ +import tensorflow as tf + + +def gen(): + ragged_tensor = tf.ragged.constant([[1, 2], [3]]) + yield 42, ragged_tensor + + +def add(a, b): + return a + b + + +dataset = tf.data.Dataset.from_generator( + gen, + output_signature=( + tf.TensorSpec(shape=(), dtype=tf.int32), + tf.RaggedTensorSpec(shape=(2, None), dtype=tf.int32))) + +for element in dataset: + c = add(element, element)