Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "third level" (i.e., tf.x.y.z) APIs #85

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ public void testTf2()
testTf2("tf2ll.py", "add", 2, 3, 2, 3);
testTf2("tf2ll2.py", "add", 2, 3, 2, 3);
testTf2("tf2ll3.py", "add", 2, 3, 2, 3);
testTf2("tf2mm.py", "add", 2, 3, 2, 3);
testTf2("tf2mm2.py", "add", 2, 3, 2, 3);
testTf2("tf2nn.py", "value_index", 2, 4, 2, 3);
testTf2("tf2nn2.py", "value_index", 2, 4, 2, 3);
testTf2("tf2nn3.py", "value_index", 2, 4, 2, 3);
testTf2("tf2nn4.py", "value_index", 2, 4, 2, 3);
testTf2("tf2oo.py", "func2", 1, 4, 2);
testTf2("tf2oo2.py", "func2", 1, 4, 2);
testTf2("tf2oo3.py", "func2", 1, 4, 2);
testTf2("tf2oo4.py", "func2", 1, 4, 2);
}

private void testTf2(
Expand Down
32 changes: 27 additions & 5 deletions com.ibm.wala.cast.python.ml/data/tensorflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

<new def="nn" class="Lobject" />
<putfield class="LRoot" field="nn" fieldType="LRoot" ref="x" value="nn" />
<new def="layers" class="Lobject" />
<putfield class="LRoot" field="layers" fieldType="LRoot" ref="x" value="layers" />
<new def="random" class="Lobject" />
<putfield class="LRoot" field="random" fieldType="LRoot" ref="x" value="random" />
<new def="sparse" class="Lobject" />
Expand All @@ -45,6 +43,9 @@
<putfield class="LRoot" field="linalg" fieldType="LRoot" ref="x" value="linalg" />
<new def="keras" class="Lobject" />
<putfield class="LRoot" field="keras" fieldType="LRoot" ref="x" value="keras" />
<new def="layers" class="Lobject" />
<putfield class="LRoot" field="layers" fieldType="LRoot" ref="x" value="layers" />
<putfield class="LRoot" field="layers" fieldType="LRoot" ref="keras" value="layers" />

<new def="app" class="Lobject" />
<putfield class="LRoot" field="app" fieldType="LRoot" ref="x" value="app" />
Expand All @@ -63,9 +64,6 @@
<new def="reshape" class="Ltensorflow/functions/reshape" />
<putfield class="LRoot" field="reshape" fieldType="LRoot" ref="x" value="reshape" />

<new def="Input" class="Ltensorflow/functions/Input" />
<putfield class="LRoot" field="Input" fieldType="LRoot" ref="keras" value="Input" />

<new def="conv2d" class="Ltensorflow/functions/conv2d" />
<putfield class="LRoot" field="conv2d" fieldType="LRoot" ref="x" value="conv2d" />
<putfield class="LRoot" field="conv2d" fieldType="LRoot" ref="nn" value="conv2d" />
Expand Down Expand Up @@ -106,6 +104,12 @@
<putfield class="LRoot" field="ragged" fieldType="LRoot" ref="x" value="ragged" />
<putfield class="LRoot" field="ragged" fieldType="LRoot" ref="ops" value="ragged" />

<new def="experimental" class="Lobject" />
<putfield class="LRoot" field="experimental" fieldType="LRoot" ref="x" value="experimental" />

<new def="numpy" class="Lobject" />
<putfield class="LRoot" field="numpy" fieldType="LRoot" ref="experimental" value="numpy" />

<new def="array_ops" class="Lobject" />
<putfield class="LRoot" field="array_ops" fieldType="LRoot" ref="ops" value="array_ops" />

Expand Down Expand Up @@ -139,6 +143,13 @@
<new def="ragged_tensor" class="Lobject" />
<putfield class="LRoot" field="ragged_tensor" fieldType="LRoot" ref="ragged" value="ragged_tensor" />

<new def="ndarray" class="Ltensorflow/functions/ndarray" />
<putfield class="LRoot" field="ndarray" fieldType="LRoot" ref="numpy" value="ndarray" />

<new def="Input" class="Ltensorflow/functions/Input" />
<putfield class="LRoot" field="Input" fieldType="LRoot" ref="keras" value="Input" />
<putfield class="LRoot" field="Input" fieldType="LRoot" ref="layers" value="Input" />

<new def="Variable" class="Ltensorflow/functions/Variable" />
<putfield class="LRoot" field="Variable" fieldType="LRoot" ref="x" value="Variable" />
<putfield class="LRoot" field="Variable" fieldType="LRoot" ref="variables" value="Variable" />
Expand Down Expand Up @@ -470,6 +481,17 @@
</method>
</class>

<class name="ndarray" allocatable="true">
<method name="read_data" descriptor="()LRoot;">
<new def="x" class="Ltensorflow/python/framework/ops/ndarray" />
<return value="x" />
</method>
<method name="do" descriptor="()LRoot;" numArgs="3" paramNames="op value_index dtype">
<call class="LRoot" name="read_data" descriptor="()LRoot;" type="virtual" arg0="arg0" def="x" />
<return value="x" />
</method>
</class>

<class name="ragged_range" allocatable="true">
<method name="read_data" descriptor="()LRoot;">
<new def="x" class="Ltensorflow/python/ops/ragged/ragged_math_ops/range" />
Expand Down
7 changes: 7 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2mm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tensorflow as tf

def add(a, b):
return a + b


c = add(tf.keras.layers.Input(shape=(32,)), tf.keras.layers.Input(shape=(32,)))
7 changes: 7 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2mm2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tensorflow

def add(a, b):
return a + b


c = add(tensorflow.keras.layers.Input(shape=(32,)), tensorflow.keras.layers.Input(shape=(32,)))
13 changes: 13 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2nn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import tensorflow as tf

def value_index(a,b):
return a.value_index + b.value_index

# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/Graph#using_graphs_directly_deprecated
g = tf.Graph()
with g.as_default():
# Defines operation and tensor in graph
c = tf.constant(30.0)
assert c.graph is g

result = value_index(tf.experimental.numpy.ndarray(g.get_operations()[0], 0, tf.float32), tf.experimental.numpy.ndarray(g.get_operations()[0], 0, tf.float32))
14 changes: 14 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2nn2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tensorflow.experimental import numpy
import tensorflow as tf

def value_index(a,b):
return a.value_index + b.value_index

# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/Graph#using_graphs_directly_deprecated
g = tf.Graph()
with g.as_default():
# Defines operation and tensor in graph
c = tf.constant(30.0)
assert c.graph is g

result = value_index(numpy.ndarray(g.get_operations()[0], 0, tf.float32), numpy.ndarray(g.get_operations()[0], 0, tf.float32))
14 changes: 14 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2nn3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tensorflow.experimental.numpy import ndarray
import tensorflow as tf

def value_index(a,b):
return a.value_index + b.value_index

# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/Graph#using_graphs_directly_deprecated
g = tf.Graph()
with g.as_default():
# Defines operation and tensor in graph
c = tf.constant(30.0)
assert c.graph is g

result = value_index(ndarray(g.get_operations()[0], 0, tf.float32), ndarray(g.get_operations()[0], 0, tf.float32))
14 changes: 14 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2nn4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tensorflow import experimental
import tensorflow as tf

def value_index(a,b):
return a.value_index + b.value_index

# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/Graph#using_graphs_directly_deprecated
g = tf.Graph()
with g.as_default():
# Defines operation and tensor in graph
c = tf.constant(30.0)
assert c.graph is g

result = value_index(experimental.numpy.ndarray(g.get_operations()[0], 0, tf.float32), experimental.numpy.ndarray(g.get_operations()[0], 0, tf.float32))
14 changes: 14 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2oo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tensorflow as tf

def func2(t):
pass

@tf.function
def func():
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[1.0, 1.0], [0.0, 1.0]])
c = tf.matmul(a, b)
tensor = tf.experimental.numpy.ndarray(c.op, 0, tf.float32)
func2(tensor)

func()
15 changes: 15 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2oo2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tensorflow import experimental
import tensorflow as tf

def func2(t):
pass

@tf.function
def func():
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[1.0, 1.0], [0.0, 1.0]])
c = tf.matmul(a, b)
tensor = experimental.numpy.ndarray(c.op, 0, tf.float32)
func2(tensor)

func()
15 changes: 15 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2oo3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tensorflow.experimental import numpy
import tensorflow as tf

def func2(t):
pass

@tf.function
def func():
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[1.0, 1.0], [0.0, 1.0]])
c = tf.matmul(a, b)
tensor = numpy.ndarray(c.op, 0, tf.float32)
func2(tensor)

func()
15 changes: 15 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2oo4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tensorflow.experimental.numpy import ndarray
import tensorflow as tf

def func2(t):
pass

@tf.function
def func():
a = tf.constant([[1.0, 2.0], [3.0, 4.0]])
b = tf.constant([[1.0, 1.0], [0.0, 1.0]])
c = tf.matmul(a, b)
tensor = ndarray(c.op, 0, tf.float32)
func2(tensor)

func()