Skip to content

Commit 061dc23

Browse files
committed
Add API tf.add().
1 parent 31c6ddc commit 061dc23

File tree

8 files changed

+93
-6
lines changed

8 files changed

+93
-6
lines changed

com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflowModel.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public void testTf2()
107107
testTf2("tf2n.py", "func2", 1, 1, 2);
108108
testTf2("tf2n2.py", "func2", 1, 1, 2);
109109
testTf2("tf2n3.py", "func2", 1, 1, 2);
110-
testTf2("tf2o.py", "add", 2, 2, 2, 3);
111-
testTf2("tf2o2.py", "add", 2, 2, 2, 3);
110+
testTf2("tf2o.py", "add", 2, 3, 2, 3);
111+
testTf2("tf2o2.py", "add", 2, 3, 2, 3);
112112
testTf2("tf2p.py", "value_index", 2, 2, 2, 3);
113113
testTf2("tf2p2.py", "value_index", 2, 2, 2, 3);
114114
testTf2("tf2q.py", "add", 2, 2, 2, 3);
@@ -245,12 +245,18 @@ public void testTf2()
245245
3); // NOTE: Change to 2 tensor parameters and 5 tensor variables once
246246
// https://github.com/wala/ML/issues/127 is fixed. Values 2 and 3 will correspond to the
247247
// tensor parameters.
248-
testTf2("autoencoder.py", "encoder", 1, 10, 2);
249-
testTf2("autoencoder.py", "mean_square", 1, 1, 3);
250-
testTf2("autoencoder.py", "run_optimization", 1, 1, 2);
251-
testTf2("autoencoder.py", "decoder", 1, 8, 2);
248+
testTf2("autoencoder.py", "encoder", 1, 18, 2);
249+
testTf2("autoencoder.py", "mean_square", 2, 2, 2, 3);
250+
testTf2("autoencoder.py", "run_optimization", 1, 3, 2);
251+
testTf2("autoencoder.py", "decoder", 1, 18, 2);
252252
testTf2("tf2_test_sigmoid.py", "f", 1, 1, 2);
253253
testTf2("tf2_test_sigmoid2.py", "f", 1, 1, 2);
254+
testTf2("tf2_test_add.py", "f", 1, 1, 2);
255+
testTf2("tf2_test_add2.py", "f", 1, 1, 2);
256+
testTf2("tf2_test_add3.py", "f", 1, 1, 2);
257+
testTf2("tf2_test_add4.py", "f", 1, 1, 2);
258+
testTf2("tf2_test_add5.py", "f", 1, 1, 2);
259+
testTf2("tf2_test_add6.py", "f", 1, 1, 2);
254260
}
255261

256262
private void testTf2(

com.ibm.wala.cast.python.ml/data/tensorflow.xml

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
<new def="sigmoid" class="Ltensorflow/math/sigmoid" />
7575
<putfield class="LRoot" field="sigmoid" fieldType="LRoot" ref="nn" value="sigmoid" />
7676
<putfield class="LRoot" field="sigmoid" fieldType="LRoot" ref="math" value="sigmoid" />
77+
<new def="add" class="Ltensorflow/math/add" />
78+
<putfield class="LRoot" field="add" fieldType="LRoot" ref="x" value="add" />
79+
<putfield class="LRoot" field="add" fieldType="LRoot" ref="math" value="add" />
7780
<new def="placeholder" class="Ltensorflow/functions/placeholder" />
7881
<putfield class="LRoot" field="placeholder" fieldType="LRoot" ref="x" value="placeholder" />
7982
<new def="examples" class="Lobject" />
@@ -263,6 +266,18 @@
263266
<return value="x" />
264267
</method>
265268
</class>
269+
<class name="add" allocatable="true">
270+
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/add -->
271+
<method name="read_data" descriptor="()LRoot;">
272+
<new def="x" class="Ltensorflow/math/add" />
273+
<return value="x" />
274+
</method>
275+
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self x y name">
276+
<!-- Even though tf.add() isn't a tensor "generator," it can convert its non-tensor arguments to tensors. -->
277+
<call class="LRoot" name="read_data" descriptor="()LRoot;" type="virtual" arg0="arg0" def="xx" />
278+
<return value="xx" />
279+
</method>
280+
</class>
266281
</package>
267282
<package name="tensorflow/functions">
268283
<class name="AdamOptimizer" allocatable="true">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
def f(a):
5+
pass
6+
7+
8+
x = [1, 2, 3, 4, 5]
9+
y = 1
10+
z = tf.add(x, y)
11+
f(z)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
def f(a):
5+
pass
6+
7+
8+
x = tf.convert_to_tensor([1, 2, 3, 4, 5])
9+
y = tf.convert_to_tensor(1)
10+
z = tf.add(x, y)
11+
f(z)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
def f(a):
5+
pass
6+
7+
8+
x = [1, 2, 3, 4, 5]
9+
y = tf.constant([1, 2, 3, 4, 5])
10+
z = tf.add(x, y)
11+
f(z)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
def f(a):
5+
pass
6+
7+
8+
x = [1, 2, 3, 4, 5]
9+
y = 1
10+
z = tf.math.add(x, y)
11+
f(z)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
def f(a):
5+
pass
6+
7+
8+
x = tf.convert_to_tensor([1, 2, 3, 4, 5])
9+
y = tf.convert_to_tensor(1)
10+
z = tf.math.add(x, y)
11+
f(z)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import tensorflow as tf
2+
3+
4+
def f(a):
5+
pass
6+
7+
8+
x = [1, 2, 3, 4, 5]
9+
y = tf.constant([1, 2, 3, 4, 5])
10+
z = tf.math.add(x, y)
11+
f(z)

0 commit comments

Comments
 (0)