Description
Consider the following code:
# tf2_test_reshape.py
# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/reshape
import tensorflow as tf
def f(a):
pass
t1 = tf.ones([2, 3])
t2 = tf.reshape(t1, [6])
f(t2)
t2
should be a (reshaped) tensor, and the argument to f()
should also be tracked as a tensor. Instead, I'm seeing this tensor analysis result:
[INFO] Tensor analysis: answer:
[Node: synthetic < PythonLoader, Ltensorflow/functions/reshape, do()LRoot; > Context: CallStringContext: [ script tf2_test_reshape.py.do()LRoot;@105 ], v2][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_test_reshape.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v245][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Ret-V:Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_reshape.py.do()LRoot;@100 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: synthetic < PythonLoader, Ltensorflow/functions/ones, do()LRoot; > Context: CallStringContext: [ script tf2_test_reshape.py.do()LRoot;@100 ], v5][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
In the IR, v245
refers to the return value of tf.ones()
. That's the only tensor in this file.
Regression
- There is a summary for
tf.reshape()
, but it callscopy_data()
instead ofread_data()
. - There is special handling of
tf.reshape()
in the code, stemming from theMethodReference
fieldcom.ibm.wala.cast.python.ml.client.PythonTensorAnalysisEngine.reshape
.