Skip to content

Commit d2cbc66

Browse files
authored
Adding second level APIs (#81)
Adding second-level APIs with their respective tests, which can be found at: https://github.com/ponder-lab/Hybridize-Functions-Refactoring/wiki/TF2-tensor-generators.
1 parent 2aff5fd commit d2cbc66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+837
-0
lines changed

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

+63
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,69 @@ public void testTf2()
108108
// TODO: Uncomment below test when https://github.com/wala/ML/issues/65 is fixed.
109109
// testTf2("tf2s.py", "add", 2, 3, 2, 3);
110110
testTf2("tf2t.py", "add", 2, 3, 2, 3);
111+
testTf2("tf2u.py", "add", 2, 3, 2, 3);
112+
testTf2("tf2u2.py", "add", 2, 3, 2, 3);
113+
testTf2("tf2u3.py", "add", 2, 3, 2, 3);
114+
testTf2("tf2v.py", "add", 2, 3, 2, 3);
115+
testTf2("tf2v2.py", "add", 2, 3, 2, 3);
116+
testTf2("tf2v3.py", "add", 2, 3, 2, 3);
117+
testTf2("tf2v4.py", "add", 2, 4, 2, 3);
118+
testTf2("tf2v5.py", "add", 2, 4, 2, 3);
119+
testTf2("tf2w.py", "add", 2, 3, 2, 3);
120+
testTf2("tf2w2.py", "add", 2, 3, 2, 3);
121+
testTf2("tf2w3.py", "add", 2, 3, 2, 3);
122+
testTf2("tf2w4.py", "add", 2, 3, 2, 3);
123+
testTf2("tf2x.py", "add", 2, 3, 2, 3);
124+
testTf2("tf2x2.py", "add", 2, 3, 2, 3);
125+
testTf2("tf2x3.py", "add", 2, 3, 2, 3);
126+
testTf2("tf2y.py", "add", 2, 3, 2, 3);
127+
testTf2("tf2y2.py", "add", 2, 3, 2, 3);
128+
testTf2("tf2y3.py", "add", 2, 3, 2, 3);
129+
testTf2("tf2y4.py", "add", 2, 3, 2, 3);
130+
testTf2("tf2y5.py", "add", 2, 3, 2, 3);
131+
testTf2("tf2y6.py", "add", 2, 3, 2, 3);
132+
testTf2("tf2z.py", "add", 2, 5, 2, 3);
133+
testTf2("tf2z2.py", "add", 2, 5, 2, 3);
134+
testTf2("tf2z3.py", "add", 2, 5, 2, 3);
135+
testTf2("tf2z4.py", "add", 2, 5, 2, 3);
136+
testTf2("tf2aa.py", "add", 2, 3, 2, 3);
137+
testTf2("tf2aa2.py", "add", 2, 3, 2, 3);
138+
testTf2("tf2aa3.py", "add", 2, 3, 2, 3);
139+
testTf2("tf2aa4.py", "add", 2, 3, 2, 3);
140+
testTf2("tf2aa5.py", "add", 2, 3, 2, 3);
141+
testTf2("tf2aa6.py", "add", 2, 3, 2, 3);
142+
testTf2("tf2aa7.py", "add", 2, 3, 2, 3);
143+
testTf2("tf2aa8.py", "add", 2, 3, 2, 3);
144+
testTf2("tf2bb.py", "add", 2, 5, 2, 3);
145+
testTf2("tf2bb2.py", "add", 2, 5, 2, 3);
146+
testTf2("tf2bb3.py", "add", 2, 5, 2, 3);
147+
testTf2("tf2bb4.py", "add", 2, 5, 2, 3);
148+
testTf2("tf2cc.py", "add", 2, 3, 2, 3);
149+
testTf2("tf2cc2.py", "add", 2, 3, 2, 3);
150+
testTf2("tf2cc3.py", "add", 2, 3, 2, 3);
151+
testTf2("tf2dd.py", "add", 2, 3, 2, 3);
152+
testTf2("tf2dd2.py", "add", 2, 3, 2, 3);
153+
testTf2("tf2ee.py", "add", 2, 3, 2, 3);
154+
testTf2("tf2ee2.py", "add", 2, 3, 2, 3);
155+
testTf2("tf2ff.py", "add", 2, 3, 2, 3);
156+
testTf2("tf2ff2.py", "add", 2, 3, 2, 3);
157+
testTf2("tf2gg.py", "add", 2, 3, 2, 3);
158+
testTf2("tf2gg2.py", "add", 2, 3, 2, 3);
159+
testTf2("tf2gg3.py", "add", 2, 3, 2, 3);
160+
testTf2("tf2hh.py", "add", 2, 3, 2, 3);
161+
testTf2("tf2hh2.py", "add", 2, 3, 2, 3);
162+
testTf2("tf2hh3.py", "add", 2, 3, 2, 3);
163+
testTf2("tf2hh4.py", "add", 2, 3, 2, 3);
164+
testTf2("tf2ii.py", "add", 2, 3, 2, 3);
165+
testTf2("tf2ii2.py", "add", 2, 3, 2, 3);
166+
testTf2("tf2ii3.py", "add", 2, 3, 2, 3);
167+
testTf2("tf2jj.py", "add", 2, 3, 2, 3);
168+
testTf2("tf2jj2.py", "add", 2, 3, 2, 3);
169+
testTf2("tf2kk.py", "add", 2, 3, 2, 3);
170+
testTf2("tf2kk2.py", "add", 2, 3, 2, 3);
171+
testTf2("tf2ll.py", "add", 2, 3, 2, 3);
172+
testTf2("tf2ll2.py", "add", 2, 3, 2, 3);
173+
testTf2("tf2ll3.py", "add", 2, 3, 2, 3);
111174
}
112175

113176
private void testTf2(

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

+292
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),tf.RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tensorflow.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),tensorflow.RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
2+
import tensorflow as tf
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow.python.ops.ragged import ragged_tensor
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(ragged_tensor.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),ragged_tensor.RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow.python.ops import ragged
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(ragged.ragged_tensor.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),ragged.ragged_tensor.RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow.python import ops
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(ops.ragged.ragged_tensor.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),ops.ragged.ragged_tensor.RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow import python
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(python.ops.ragged.ragged_tensor.RaggedTensor.from_nested_row_splits([3, 1, 4, 1, 5, 9, 2, 6],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])),python.ops.ragged.ragged_tensor.RaggedTensor.from_nested_row_splits([13, 1, 4, 1, 15, 9, 2, 16],([0, 3, 3, 5], [0, 4, 4, 7, 8, 8])))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
nested_value_rowids = [tf.constant([0, 0, 1, 3, 3], tf.int64),tf.constant([0, 0, 2, 2, 2, 3, 4], tf.int64)]
8+
x = tf.keras.Input(shape=[None], dtype=tf.string)
9+
c = add(tf.RaggedTensor.from_nested_value_rowids(x, nested_value_rowids),tf.RaggedTensor.from_nested_value_rowids(x, nested_value_rowids))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import tensorflow
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
nested_value_rowids = [tensorflow.constant([0, 0, 1, 3, 3], tensorflow.int64),tensorflow.constant([0, 0, 2, 2, 2, 3, 4], tensorflow.int64)]
8+
x = tensorflow.keras.Input(shape=[None], dtype=tensorflow.string)
9+
c = add(tensorflow.RaggedTensor.from_nested_value_rowids(x, nested_value_rowids),tensorflow.RaggedTensor.from_nested_value_rowids(x, nested_value_rowids))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
2+
import tensorflow as tf
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
nested_value_rowids = [tf.constant([0, 0, 1, 3, 3], tf.int64),tf.constant([0, 0, 2, 2, 2, 3, 4], tf.int64)]
9+
x = tf.keras.Input(shape=[None], dtype=tf.string)
10+
c = add(RaggedTensor.from_nested_value_rowids(x, nested_value_rowids),RaggedTensor.from_nested_value_rowids(x, nested_value_rowids))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
2+
import tensorflow as tf
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
nested_value_rowids = [tf.constant([0, 0, 1, 3, 3], tf.int64),tf.constant([0, 0, 2, 2, 2, 3, 4], tf.int64)]
9+
x = tf.keras.Input(shape=[None], dtype=tf.string)
10+
c = add(tf.RaggedTensor.from_nested_value_rowids(x, nested_value_rowids),RaggedTensor.from_nested_value_rowids(x, nested_value_rowids))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.RaggedTensor.from_row_lengths([3, 1, 4, 1, 5, 9, 2, 6], [4, 0, 3, 1, 0]), tf.RaggedTensor.from_row_lengths([3, 11, 4, 11, 5, 19, 21, 6], [4, 0, 3, 1, 0]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tensorflow as tf
2+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.RaggedTensor.from_row_lengths([3, 1, 4, 1, 5, 9, 2, 6], [4, 0, 3, 1, 0]), RaggedTensor.from_row_lengths([3, 11, 4, 11, 5, 19, 21, 6], [4, 0, 3, 1, 0]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow import RaggedTensor
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(RaggedTensor.from_row_lengths([3, 1, 4, 1, 5, 9, 2, 6], [4, 0, 3, 1, 0]), RaggedTensor.from_row_lengths([3, 11, 4, 11, 5, 19, 21, 6], [4, 0, 3, 1, 0]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.RaggedTensor.from_row_limits([3, 1, 4, 1, 5, 9, 2, 6], [4, 4, 7, 8, 8]), tf.RaggedTensor.from_row_limits([3, 11, 4, 11, 5, 19, 21, 6], [4, 4, 7, 8, 8]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tensorflow as tf
2+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.RaggedTensor.from_row_limits([3, 1, 4, 1, 5, 9, 2, 6], [4, 4, 7, 8, 8]), RaggedTensor.from_row_limits([3, 11, 4, 11, 5, 19, 21, 6], [4, 4, 7, 8, 8]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.RaggedTensor.from_row_splits([3, 1, 4, 1, 5, 9, 2, 6], [0, 4, 4, 7, 8, 8]), tf.RaggedTensor.from_row_splits([2, 3, 7, 17, 8, 19, 2, 6], [0, 4, 4, 7, 8, 8]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tensorflow as tf
2+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.RaggedTensor.from_row_splits([3, 1, 4, 1, 5, 9, 2, 6], [0, 4, 4, 7, 8, 8]), RaggedTensor.from_row_splits([2, 3, 7, 17, 8, 19, 2, 6], [0, 4, 4, 7, 8, 8]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.RaggedTensor.from_row_starts([3, 1, 4, 1, 5, 9, 2, 6], [0, 4, 4, 7, 8]), tf.RaggedTensor.from_row_starts([3, 11, 4, 11, 5, 19, 21, 6], [0, 4, 4, 7, 8]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tensorflow as tf
2+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.RaggedTensor.from_row_starts([3, 1, 4, 1, 5, 9, 2, 6], [0, 4, 4, 7, 8]), RaggedTensor.from_row_starts([3, 11, 4, 11, 5, 19, 21, 6], [0, 4, 4, 7, 8]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.RaggedTensor.from_value_rowids([3, 1, 4, 1, 5, 9, 2, 6],[0, 0, 0, 0, 2, 2, 2, 3]), tf.RaggedTensor.from_value_rowids([3, 1, 14, 1, 5, 19, 2, 16],[0, 0, 0, 0, 2, 2, 2, 3]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tensorflow as tf
2+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.RaggedTensor.from_value_rowids([3, 1, 4, 1, 5, 9, 2, 6],[0, 0, 0, 0, 2, 2, 2, 3]), RaggedTensor.from_value_rowids([3, 1, 14, 1, 5, 19, 2, 16],[0, 0, 0, 0, 2, 2, 2, 3]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(RaggedTensor.from_value_rowids([3, 1, 4, 1, 5, 9, 2, 6],[0, 0, 0, 0, 2, 2, 2, 3]), RaggedTensor.from_value_rowids([3, 1, 14, 1, 5, 19, 2, 16],[0, 0, 0, 0, 2, 2, 2, 3]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.random.gamma([10], [0.5, 1.5]), tf.random.gamma([10], [1, 2.5]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tensorflow import random
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(random.gamma([10], [0.5, 1.5]), random.gamma([10], [1, 2.5]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tensorflow.python.ops.random_ops import random_gamma
2+
import tensorflow as tf
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(tf.random.gamma([10], [0.5, 1.5]), random_gamma([10], [1, 2.5]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tensorflow.python.ops.random_ops import random_gamma
2+
from tensorflow import random
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(random.gamma([10], [0.5, 1.5]), random_gamma([10], [1, 2.5]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.random.normal([4], 0, 1, tf.float32), tf.random.normal([4], 2, 1, tf.float32))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tensors
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tensors.random.normal([4], 0, 1, tensors.float32), tensors.random.normal([4], 2, 1, tensors.float32))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from tensorflow import random
2+
from tensorflow.python.ops.random_ops import random_normal
3+
import tensorflow as tf
4+
5+
def add(a, b):
6+
return a + b
7+
8+
9+
c = add(random.normal([4], 0, 1, tf.float32), random_normal([4], 2, 1, tf.float32))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.random.poisson([10], [0.5, 1.5]), tf.random.poisson([10], [1, 2.5]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tensorflow import random
2+
from tensorflow.python.ops.random_ops import random_poisson_v2
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(random.poisson([10], [0.5, 1.5]), random_poisson_v2([10], [1, 2.5]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return a + b
5+
6+
7+
c = add(tf.random.truncated_normal([2]), tf.random.truncated_normal([2], 3, 1))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tensorflow import random
2+
from tensorflow.python.ops.random_ops import truncated_normal
3+
4+
def add(a, b):
5+
return a + b
6+
7+
8+
c = add(random.truncated_normal([2]), truncated_normal([2], 3, 1))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tensorflow as tf
2+
3+
def add(a, b):
4+
return tf.sparse.add(a,b)
5+
6+
7+
c = add(tf.sparse.eye(2,3), tf.sparse.eye(2,3))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tensorflow.python.ops.sparse_ops import sparse_eye
2+
import tensorflow as tf
3+
4+
def add(a, b):
5+
return tf.sparse.add(a,b)
6+
7+
8+
c = add(sparse_eye(2,3), sparse_eye(2,3))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from tensorflow.python.ops.sparse_ops import sparse_eye
2+
import tensorflow as tf
3+
from tensorflow import sparse
4+
5+
def add(a, b):
6+
return tf.sparse.add(a,b)
7+
8+
9+
c = add(sparse.eye(2,3), sparse_eye(2,3))

0 commit comments

Comments
 (0)