From 39c7fb5d011e07340f39173823f9ed41d7d607b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 00:21:25 -0500 Subject: [PATCH 01/70] update --- .../hybridize/core/analysis/Function.java | 139 ++++++++- .../testDecoratorArguments/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments10/in/A.py | 12 + .../testDecoratorArguments10/in/custom.py | 11 + .../in/requirements.txt | 0 .../testDecoratorArguments11/in/A.py | 13 + .../testDecoratorArguments11/in/custom.py | 11 + .../in/requirements.txt | 1 + .../testDecoratorArguments12/in/A.py | 12 + .../in/requirements.txt | 1 + .../testDecoratorArguments2/in/A.py | 13 + .../in/requirements.txt | 1 + .../testDecoratorArguments3/in/A.py | 11 + .../in/requirements.txt | 1 + .../testDecoratorArguments4/in/A.py | 11 + .../in/requirements.txt | 1 + .../testDecoratorArguments5/in/A.py | 11 + .../in/requirements.txt | 1 + .../testDecoratorArguments6/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments7/in/A.py | 11 + .../in/requirements.txt | 1 + .../testDecoratorArguments8/in/A.py | 12 + .../in/requirements.txt | 1 + .../testDecoratorArguments9/in/A.py | 13 + .../in/requirements.txt | 1 + .../HybridizeFunctionRefactoringTest.java | 275 ++++++++++++++++++ 28 files changed, 578 insertions(+), 8 deletions(-) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/requirements.txt diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 3c2101713..b656eaf73 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -14,6 +14,7 @@ import org.python.pydev.parser.jython.ast.Attribute; import org.python.pydev.parser.jython.ast.Call; import org.python.pydev.parser.jython.ast.FunctionDef; +import org.python.pydev.parser.jython.ast.Name; import org.python.pydev.parser.jython.ast.NameTok; import org.python.pydev.parser.jython.ast.argumentsType; import org.python.pydev.parser.jython.ast.decoratorsType; @@ -101,6 +102,46 @@ public class HybridizationParameters { */ private boolean reduceRetracingParamExists; + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. + */ + private String autoGraphParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. + */ + private String experimentaFollowTypeHintsParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. + */ + private String experimentalAutographOptionsParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. + */ + private String experimentalImplementsParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter func. + */ + private String funcParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. + */ + private String inputSignatureParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. + */ + private String jitCompileParamValue; + + /** + * Value of this {@link Function}'s {@link decoratorsType} has parameter reduce_retracing. + */ + private String reduceRetracingParamValue; + public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); decoratorsType[] decoratorArray = functionDefinition.getFunctionDef().decs; @@ -133,37 +174,47 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep for (keywordType keyword : keywords) { if (keyword.arg instanceof NameTok) { NameTok name = (NameTok) keyword.arg; - if (name.id.equals(FUNC)) + Name value = (Name) keyword.value; + if (name.id.equals(FUNC)) { // Found parameter func this.funcParamExists = true; - else if (name.id.equals(INPUT_SIGNATURE)) + this.funcParamValue = value.id; + } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature this.inputSignatureParamExists = true; - else if (name.id.equals(AUTOGRAPH)) + this.inputSignatureParamValue = value.id; + } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph this.autoGraphParamExists = true; + this.autoGraphParamValue = value.id; // The version of the API we are using allows // parameter names jit_compile and // deprecated name experimental_compile - else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) + } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; + this.jitCompileParamValue = value.id; // The version of the API we are using allows // parameter names reduce_retracing // and deprecated name experimental_relax_shapes - else if (name.id.equals(REDUCE_RETRACING) || name.id.equals(EXPERIMENTAL_RELAX_SHAPES)) + } else if (name.id.equals(REDUCE_RETRACING) || name.id.equals(EXPERIMENTAL_RELAX_SHAPES)) { // Found parameter reduce_retracing // or experimental_relax_shapes this.reduceRetracingParamExists = true; - else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) + this.reduceRetracingParamValue = value.id; + } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements this.experimentalImplementsParamExists = true; - else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) + this.experimentaFollowTypeHintsParamValue = value.id; + } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options this.experimentalAutographOptionsParamExists = true; - else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) + this.experimentalAutographOptionsParamValue = value.id; + } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints this.experimentaFollowTypeHintsParamExists = true; + this.experimentaFollowTypeHintsParamValue = value.id; + } } } } // else, tf.function is used without parameters. @@ -240,6 +291,78 @@ public boolean hasJitCompileParam() { public boolean hasReduceRetracingParam() { return this.reduceRetracingParamExists; } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter autograph. + * + * @return String of this {@link decoratorType} parameter autograph. + */ + public String getAutoGraphArg() { + return this.autoGraphParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. + * + * @return String of this {@link decoratorType} parameter experimental_autograph_options. + */ + public String getExperimentalAutographOptArg() { + return this.experimentalAutographOptionsParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_implements. + * + * @return String of this {@link decoratorType} parameter experimental_implements. + */ + public String getExperimentalImplementsArg() { + return this.experimentalImplementsParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. + * + * @return String of this {@link decoratorType} parameter experimental_follow_type_hints. + */ + public String getExperimentalFollowTypeHintsArg() { + return this.experimentaFollowTypeHintsParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter has parameter func. + * + * @return String of this {@link decoratorType} parameter func. + */ + public String getFuncArg() { + return this.funcParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter input_signature. + * + * @return String of this {@link decoratorType} parameter input_signature. + */ + public String getInputSignatureArg() { + return this.inputSignatureParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter jit_compile. + * + * @return String of this {@link decoratorType} parameter jit_compile. + */ + public String getJitCompileArg() { + return this.jitCompileParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter reduce_retracing. + * + * @return String of this {@link Function} parameter reduce_retracing. + */ + public String getReduceRetracingArg() { + return this.reduceRetracingParamValue; + } } private static final String TF_FUNCTION_FQN = "tensorflow.python.eager.def_function.function"; diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py new file mode 100644 index 000000000..69b144c7f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),)) +def func(x): + return x + +if __name__ == '__main__': + number = tf.constant([1.0, 1.0]) + func(number) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py new file mode 100644 index 000000000..3de535d5e --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py @@ -0,0 +1,12 @@ +import custom + + +@custom.decorator(input_signature=None) +def func(x): + print('Tracing with', x) + return x + + +if __name__ == '__main__': + func(1) + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py new file mode 100644 index 000000000..041bb974b --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py @@ -0,0 +1,11 @@ +def decorator(input_signature=None): + + def decorated(inner_function): + + def wrapper(*args, **kwargs): + result = function(*args, **kwargs) + return result + + return decorated + + return decorator diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py new file mode 100644 index 000000000..ac38d4cb1 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py @@ -0,0 +1,13 @@ +import custom +import tensorflow as tf + + +@custom.decorator(input_signature=None) +@tf.function(autograph=False) +def func(): + pass + + +if __name__ == '__main__': + func() + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py new file mode 100644 index 000000000..041bb974b --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py @@ -0,0 +1,11 @@ +def decorator(input_signature=None): + + def decorated(inner_function): + + def wrapper(*args, **kwargs): + result = function(*args, **kwargs) + return result + + return decorated + + return decorator diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py new file mode 100644 index 000000000..dd415ea3d --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py @@ -0,0 +1,12 @@ +import tensorflow as tf + + +@tf.function(autograph=False) +@tf.function(jit_compile=True) +def func(x): + return x + + +if __name__ == '__main__': + func(tf.constant(1)) + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py new file mode 100644 index 000000000..47a397ccd --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py @@ -0,0 +1,13 @@ +import tensorflow as tf + + +@tf.function(experimental_autograph_options=tf.autograph.experimental.Feature.EQUALITY_OPERATORS) +def func(i): + if i == 0: + tf.print('i is zero') + + +if __name__ == '__main__': + x = tf.constant(1) + func(x) + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py new file mode 100644 index 000000000..efd65dbd3 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(experimental_follow_type_hints=True) +def func(): + pass + + +if __name__ == '__main__': + func() + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py new file mode 100644 index 000000000..ccbd1c5fc --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(experimental_implements="google.matmul_low_rank_matrix") +def func(): + pass + + +if __name__ == '__main__': + func() + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py new file mode 100644 index 000000000..6c9135806 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(jit_compile=True) +def func(): + print("Tracing") + + +if __name__ == '__main__': + func() + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py new file mode 100644 index 000000000..56d547fea --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(reduce_retracing=True) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py new file mode 100644 index 000000000..03cee7678 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(autograph=False) +def func(): + print("Testing") + + +if __name__ == '__main__': + func() + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py new file mode 100644 index 000000000..2a176ee4c --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py @@ -0,0 +1,12 @@ +import tensorflow as tf + + +@tf.function +def test(x): + return x + + +if __name__ == '__main__': + x = tf.constant(1) + test(x) + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py new file mode 100644 index 000000000..11139cb78 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py @@ -0,0 +1,13 @@ +import tensorflow as tf + + +@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),), autograph=False) +def func(x): + print('Tracing with', x) + return x + + +if __name__ == '__main__': + number = tf.constant([1.0, 1.0]) + func(number) + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index fdc14ed4f..5d869ef9a 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -826,6 +826,281 @@ public void testComputeParameters12() throws Exception { } + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + */ + @Test + public void testDecoratorArguments2() throws Exception { + Set functions = this.getFunctions(); + + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("tf.autograph.experimental.Feature.EQUALITY_OPERATORS", args.getExperimentalAutographOptArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_follow_type_hints. + */ + @Test + public void testDecoratorArguments3() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && args.hasExperimentalFollowTypeHintsParam()) + assertEquals("True", args.getExperimentalFollowTypeHintsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + */ + @Test + public void testDecoratorArguments4() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. + */ + @Test + public void testDecoratorArguments5() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("True", args.getJitCompileArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument reduce_retracing. + */ + @Test + public void testDecoratorArguments6() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("True", args.getReduceRetracingArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument autograph. + */ + @Test + public void testDecoratorArguments7() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("False", args.getAutoGraphArg()); + } + + /** + * Test for #136. This simply tests whether we can identify when there are no tf.function args. + */ + @Test + public void testDecoratorArguments8() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + assertTrue(args.getFuncArg().isBlank() && args.getInputSignatureArg().isBlank() & args.getAutoGraphArg().isBlank() + && args.getJitCompileArg().isBlank() && args.getReduceRetracingArg().isBlank() + && args.getExperimentalImplementsArg().isBlank() && args.getExperimentalAutographOptArg().isBlank() + && args.getExperimentalFollowTypeHintsArg().isBlank()); + } + + /** + * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. + */ + @Test + public void testDecoratorArguments9() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + assertEquals("False", args.getAutoGraphArg()); + } + } + + /** + * Test for #136. Test custom decorator with the same parameter names as tf.function. + */ + @Test + public void testDecoratorArguments10() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertFalse(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + + // This test is with a custom decorator `@custom.decorator` that contains a parameter `input_signature` + // like `tf.function`. With this test, we want to verify that we only parse through the arguments + // if the function is hybrid. Since this test is not with `tf.function` we are expecting the method + // to return False. + + assertNull(args); + } + + /** + * Test for #136. Test custom decorator with the same parameter names as tf.function and a tf.function (total of two decorators) and + * only count the parameters from the tf.function decorator. + */ + @Test + public void testDecoratorArguments11() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + // This test is with a custom decorator `@custom.decorator` that contains a parameter `input_signature` + // like `tf.function`. But it also has a tf.function decorator, therefore args should not be Null. + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("None", args.getAutoGraphArg()); + assertTrue(args.getInputSignatureArg().isBlank()); + } + + } + + /** + * Test for #136. Tests two different tf.functions. Should only count the parameters of the last one. + */ + @Test + public void testDecoratorArguments12() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("True", args.getJitCompileArg()); + assertTrue(args.getAutoGraphArg().isBlank()); + } + + } + /** * This simply tests whether we have the correct qualified name. */ From f21e4233a71f9505ae43eafbb673fc82e91aa9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 11:35:40 -0500 Subject: [PATCH 02/70] progress --- .../hybridize/core/analysis/Function.java | 41 ++++-- .../HybridizeFunctionRefactoringTest.java | 130 +++++++++--------- 2 files changed, 96 insertions(+), 75 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index b656eaf73..52f7c7033 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -174,45 +174,66 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep for (keywordType keyword : keywords) { if (keyword.arg instanceof NameTok) { NameTok name = (NameTok) keyword.arg; - Name value = (Name) keyword.value; if (name.id.equals(FUNC)) { // Found parameter func this.funcParamExists = true; + Name value = (Name) keyword.value; this.funcParamValue = value.id; } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature this.inputSignatureParamExists = true; - this.inputSignatureParamValue = value.id; + // Tuple value = (Tuple) keyword.value; + // this.inputSignatureParamValue = value.id; } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph this.autoGraphParamExists = true; + Name value = (Name) keyword.value; this.autoGraphParamValue = value.id; - // The version of the API we are using allows - // parameter names jit_compile and - // deprecated name experimental_compile + // The version of the API we are using allows + // parameter names jit_compile and + // deprecated name experimental_compile } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; + Name value = (Name) keyword.value; this.jitCompileParamValue = value.id; - // The version of the API we are using allows - // parameter names reduce_retracing - // and deprecated name experimental_relax_shapes + // The version of the API we are using allows + // parameter names reduce_retracing + // and deprecated name experimental_relax_shapes } else if (name.id.equals(REDUCE_RETRACING) || name.id.equals(EXPERIMENTAL_RELAX_SHAPES)) { // Found parameter reduce_retracing // or experimental_relax_shapes this.reduceRetracingParamExists = true; + Name value = (Name) keyword.value; this.reduceRetracingParamValue = value.id; } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements this.experimentalImplementsParamExists = true; - this.experimentaFollowTypeHintsParamValue = value.id; + // this.experimentalImplementsParamValue = value.id; } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options this.experimentalAutographOptionsParamExists = true; - this.experimentalAutographOptionsParamValue = value.id; + if (keyword.value instanceof Attribute) { + Attribute attr = (Attribute) keyword.value; + NameTok lastAttribute = (NameTok) attr.attr; + while (attr.value instanceof Attribute) { + attr.value = attr.value; + } + if (attr.value instanceof Name) { + Name value = (Name) attr.value; + this.experimentalAutographOptionsParamValue = value.id; + while (attr.attr instanceof NameTok) { + NameTok valueAttribute = (NameTok) attr.attr; + this.experimentalAutographOptionsParamValue += "." + valueAttribute.id; + } + } + this.experimentalAutographOptionsParamValue += "." + lastAttribute.id; + System.out.println("VAMOS A VER SI FUNCTIONA " + this.experimentalAutographOptionsParamExists); + } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints this.experimentaFollowTypeHintsParamExists = true; + Name value = (Name) keyword.value; this.experimentaFollowTypeHintsParamValue = value.id; } } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 5d869ef9a..01ae1703d 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -826,27 +826,27 @@ public void testComputeParameters12() throws Exception { } - /** - * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - */ - @Test - public void testDecoratorArguments() throws Exception { - Set functions = this.getFunctions(); - assertNotNull(functions); - assertEquals(1, functions.size()); - Function function = functions.iterator().next(); - assertNotNull(function); - - assertTrue(function.isHybrid()); - - Function.HybridizationParameters args = function.getHybridizationParameters(); - assertNotNull(args); - - if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - } + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + // */ + // @Test + // public void testDecoratorArguments() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + // } /** * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options @@ -893,27 +893,27 @@ public void testDecoratorArguments3() throws Exception { assertEquals("True", args.getExperimentalFollowTypeHintsArg()); } - /** - * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. - */ - @Test - public void testDecoratorArguments4() throws Exception { - Set functions = this.getFunctions(); - assertNotNull(functions); - assertEquals(1, functions.size()); - Function function = functions.iterator().next(); - assertNotNull(function); - - assertTrue(function.isHybrid()); - - Function.HybridizationParameters args = function.getHybridizationParameters(); - assertNotNull(args); - - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); - } + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + // */ + // @Test + // public void testDecoratorArguments4() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); + // } /** * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. @@ -1001,29 +1001,29 @@ public void testDecoratorArguments8() throws Exception { && args.getExperimentalFollowTypeHintsArg().isBlank()); } - /** - * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. - */ - @Test - public void testDecoratorArguments9() throws Exception { - Set functions = this.getFunctions(); - assertNotNull(functions); - assertEquals(1, functions.size()); - Function function = functions.iterator().next(); - assertNotNull(function); - - assertTrue(function.isHybrid()); - - Function.HybridizationParameters args = function.getHybridizationParameters(); - assertNotNull(args); - - if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - assertEquals("False", args.getAutoGraphArg()); - } - } + // /** + // * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. + // */ + // @Test + // public void testDecoratorArguments9() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) { + // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + // assertEquals("False", args.getAutoGraphArg()); + // } + // } /** * Test for #136. Test custom decorator with the same parameter names as tf.function. From 747d5c583963678fdc442e621179a19c99e59a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 11:57:59 -0500 Subject: [PATCH 03/70] Progress --- .../src/edu/cuny/hunter/hybridize/core/analysis/Function.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 52f7c7033..8268bd4cf 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -217,7 +217,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep Attribute attr = (Attribute) keyword.value; NameTok lastAttribute = (NameTok) attr.attr; while (attr.value instanceof Attribute) { - attr.value = attr.value; + attr = (Attribute) attr.value; } if (attr.value instanceof Name) { Name value = (Name) attr.value; From 8f8c0b15840165fe72cf5e8c8f82d2e02735de09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 12:04:39 -0500 Subject: [PATCH 04/70] Progress --- .../cuny/hunter/hybridize/core/analysis/Function.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 8268bd4cf..ac057e320 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -218,14 +218,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep NameTok lastAttribute = (NameTok) attr.attr; while (attr.value instanceof Attribute) { attr = (Attribute) attr.value; - } - if (attr.value instanceof Name) { - Name value = (Name) attr.value; - this.experimentalAutographOptionsParamValue = value.id; - while (attr.attr instanceof NameTok) { - NameTok valueAttribute = (NameTok) attr.attr; - this.experimentalAutographOptionsParamValue += "." + valueAttribute.id; - } + NameTok valueAttribute = (NameTok) attr.attr; + this.experimentalAutographOptionsParamValue += "." + valueAttribute.id; } this.experimentalAutographOptionsParamValue += "." + lastAttribute.id; System.out.println("VAMOS A VER SI FUNCTIONA " + this.experimentalAutographOptionsParamExists); From 4ffa27af0c9f88eb63a866d2ad9946fb3fd6b4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 15:55:11 -0500 Subject: [PATCH 05/70] Progress --- .../HybridizeFunctionRefactoringTest.java | 127 +++++++++--------- 1 file changed, 63 insertions(+), 64 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 01ae1703d..d02cb0f60 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -826,27 +826,27 @@ public void testComputeParameters12() throws Exception { } - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - // */ - // @Test - // public void testDecoratorArguments() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + // */ + // @Test + // public void testDecoratorArguments() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); // - // assertTrue(function.isHybrid()); + // assertTrue(function.isHybrid()); // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - // } + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + // } /** * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options @@ -893,27 +893,27 @@ public void testDecoratorArguments3() throws Exception { assertEquals("True", args.getExperimentalFollowTypeHintsArg()); } - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. - // */ + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + // */ // @Test - // public void testDecoratorArguments4() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); + // public void testDecoratorArguments4() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); // - // assertTrue(function.isHybrid()); + // assertTrue(function.isHybrid()); // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); // - // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); - // } + // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); + // } /** * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. @@ -995,35 +995,34 @@ public void testDecoratorArguments8() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - assertTrue(args.getFuncArg().isBlank() && args.getInputSignatureArg().isBlank() & args.getAutoGraphArg().isBlank() - && args.getJitCompileArg().isBlank() && args.getReduceRetracingArg().isBlank() - && args.getExperimentalImplementsArg().isBlank() && args.getExperimentalAutographOptArg().isBlank() - && args.getExperimentalFollowTypeHintsArg().isBlank()); - } - - // /** - // * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. - // */ - // @Test - // public void testDecoratorArguments9() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); + assertTrue(args.getFuncArg() == null && args.getInputSignatureArg() == null & args.getAutoGraphArg() == null + && args.getJitCompileArg() == null && args.getReduceRetracingArg() == null && args.getExperimentalImplementsArg() == null + && args.getExperimentalAutographOptArg() == null && args.getExperimentalFollowTypeHintsArg() == null); + } + + // /** + // * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. + // */ + // @Test + // public void testDecoratorArguments9() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); // - // assertTrue(function.isHybrid()); + // assertTrue(function.isHybrid()); // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) { - // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - // assertEquals("False", args.getAutoGraphArg()); - // } - // } + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) { + // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + // assertEquals("False", args.getAutoGraphArg()); + // } + // } /** * Test for #136. Test custom decorator with the same parameter names as tf.function. @@ -1070,8 +1069,8 @@ public void testDecoratorArguments11() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("None", args.getAutoGraphArg()); - assertTrue(args.getInputSignatureArg().isBlank()); + assertEquals("False", args.getAutoGraphArg()); + assertTrue(args.getInputSignatureArg() == null); } } @@ -1096,7 +1095,7 @@ public void testDecoratorArguments12() throws Exception { && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { assertEquals("True", args.getJitCompileArg()); - assertTrue(args.getAutoGraphArg().isBlank()); + assertTrue(args.getAutoGraphArg() == null); } } From 21a8004921074b79f4eae59a6acbce06883d31ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 17:56:35 -0500 Subject: [PATCH 06/70] Progress --- .../cuny/hunter/hybridize/core/analysis/Function.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index ac057e320..c16f0eaea 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -213,16 +213,17 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options this.experimentalAutographOptionsParamExists = true; + StringBuilder argument = new StringBuilder(); if (keyword.value instanceof Attribute) { Attribute attr = (Attribute) keyword.value; NameTok lastAttribute = (NameTok) attr.attr; while (attr.value instanceof Attribute) { - attr = (Attribute) attr.value; NameTok valueAttribute = (NameTok) attr.attr; - this.experimentalAutographOptionsParamValue += "." + valueAttribute.id; + argument.append(valueAttribute.id); + argument.append("."); + attr = (Attribute) attr.value; } - this.experimentalAutographOptionsParamValue += "." + lastAttribute.id; - System.out.println("VAMOS A VER SI FUNCTIONA " + this.experimentalAutographOptionsParamExists); + this.experimentalAutographOptionsParamValue = argument.toString() + "." + lastAttribute.id; } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints From 89e4dd00fad051f4e7cbb4e279e0c4db3390689f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 31 Jan 2023 19:00:23 -0500 Subject: [PATCH 07/70] Progress --- .../cuny/hunter/hybridize/core/analysis/Function.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index c16f0eaea..31f670384 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -216,14 +216,15 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep StringBuilder argument = new StringBuilder(); if (keyword.value instanceof Attribute) { Attribute attr = (Attribute) keyword.value; - NameTok lastAttribute = (NameTok) attr.attr; while (attr.value instanceof Attribute) { NameTok valueAttribute = (NameTok) attr.attr; - argument.append(valueAttribute.id); - argument.append("."); + System.out.println("SOLO: " + valueAttribute.id); + argument.insert(0, valueAttribute.id); + argument.insert(0, "."); attr = (Attribute) attr.value; } - this.experimentalAutographOptionsParamValue = argument.toString() + "." + lastAttribute.id; + this.experimentalAutographOptionsParamValue = ((Name) attr.value).id + "." + ((NameTok) attr.attr).id + + argument.toString(); } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints From b6f4e9c88f040b3c460ae224c46a39a00adfd6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 1 Feb 2023 10:54:13 -0500 Subject: [PATCH 08/70] Progress --- .../edu/cuny/hunter/hybridize/core/analysis/Function.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 31f670384..58c5cb628 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -218,7 +218,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep Attribute attr = (Attribute) keyword.value; while (attr.value instanceof Attribute) { NameTok valueAttribute = (NameTok) attr.attr; - System.out.println("SOLO: " + valueAttribute.id); argument.insert(0, valueAttribute.id); argument.insert(0, "."); attr = (Attribute) attr.value; @@ -226,6 +225,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.experimentalAutographOptionsParamValue = ((Name) attr.value).id + "." + ((NameTok) attr.attr).id + argument.toString(); } + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentalAutographOptionsParamValue = value.id; + } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints this.experimentaFollowTypeHintsParamExists = true; From b9c8107f3ce378464f61aa32a2fdc2b6c9a02eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 1 Feb 2023 15:53:20 -0500 Subject: [PATCH 09/70] adding more testing --- .../testDecoratorArguments/in/A.py | 2 +- .../testDecoratorArguments10/in/A.py | 12 +- .../in/requirements.txt | 1 + .../testDecoratorArguments11/in/A.py | 11 +- .../testDecoratorArguments12/in/A.py | 12 +- .../testDecoratorArguments13/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments14/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments15/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments16/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments17/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments18/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments19/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments2/in/A.py | 13 +- .../testDecoratorArguments20/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments21/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments22/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments23/in/A.py | 10 + .../in/requirements.txt | 1 + .../testDecoratorArguments24/in/A.py | 12 + .../in/requirements.txt | 1 + .../testDecoratorArguments25/in/A.py | 11 + .../in/custom.py | 2 +- .../in/requirements.txt | 1 + .../testDecoratorArguments26/in/A.py | 12 + .../in/custom.py | 2 +- .../in/requirements.txt | 1 + .../testDecoratorArguments27/in/A.py | 11 + .../in/requirements.txt | 1 + .../testDecoratorArguments3/in/A.py | 11 +- .../testDecoratorArguments4/in/A.py | 11 +- .../testDecoratorArguments5/in/A.py | 11 +- .../testDecoratorArguments6/in/A.py | 2 +- .../testDecoratorArguments7/in/A.py | 9 +- .../testDecoratorArguments8/in/A.py | 12 +- .../testDecoratorArguments9/in/A.py | 13 +- .../HybridizeFunctionRefactoringTest.java | 392 ++++++++++++++++-- 46 files changed, 584 insertions(+), 103 deletions(-) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py rename edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/{testDecoratorArguments10 => testDecoratorArguments25}/in/custom.py (91%) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py rename edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/{testDecoratorArguments11 => testDecoratorArguments26}/in/custom.py (91%) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/requirements.txt diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py index 69b144c7f..0b74fa6d9 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py @@ -1,7 +1,7 @@ import tensorflow as tf -@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),)) +@tf.function(input_signature=None) def func(x): return x diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py index 3de535d5e..31b29a7f0 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py @@ -1,12 +1,10 @@ -import custom +import tensorflow as tf -@custom.decorator(input_signature=None) -def func(x): - print('Tracing with', x) - return x +@tf.function(jit_compile=None) +def func(): + pass if __name__ == '__main__': - func(1) - + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt index e69de29bb..b154f958f 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py index ac38d4cb1..56d547fea 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py @@ -1,13 +1,10 @@ -import custom import tensorflow as tf -@custom.decorator(input_signature=None) -@tf.function(autograph=False) +@tf.function(reduce_retracing=True) def func(): - pass - + pass + if __name__ == '__main__': - func() - + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py index dd415ea3d..5d50229e5 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py @@ -1,12 +1,10 @@ import tensorflow as tf -@tf.function(autograph=False) -@tf.function(jit_compile=True) -def func(x): - return x +@tf.function(reduce_retracing=False) +def func(): + pass - + if __name__ == '__main__': - func(tf.constant(1)) - + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py new file mode 100644 index 000000000..425fb101e --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_implements="google.matmul_low_rank_matrix") +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py new file mode 100644 index 000000000..d3bc1edbb --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_implements="google.embedded_matmul") +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py new file mode 100644 index 000000000..e550407e9 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_implements=None) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py new file mode 100644 index 000000000..e9b7f7db1 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_autograph_options="tf.autograph.experimental.Feature.EQUALITY_OPERATORS") +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py new file mode 100644 index 000000000..d59b57c62 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_autograph_options="tf.autograph.experimental.Feature.ALL") +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py new file mode 100644 index 000000000..c40b2c9b8 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_autograph_options=(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py new file mode 100644 index 000000000..2b49f866c --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_autograph_options=None) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py index 47a397ccd..69b144c7f 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/A.py @@ -1,13 +1,10 @@ import tensorflow as tf -@tf.function(experimental_autograph_options=tf.autograph.experimental.Feature.EQUALITY_OPERATORS) -def func(i): - if i == 0: - tf.print('i is zero') +@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),)) +def func(x): + return x - if __name__ == '__main__': - x = tf.constant(1) - func(x) - + number = tf.constant([1.0, 1.0]) + func(number) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py new file mode 100644 index 000000000..e523599eb --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_follow_type_hints=True) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py new file mode 100644 index 000000000..05385048f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_follow_type_hints=False) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py new file mode 100644 index 000000000..92fa92e1c --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(experimental_follow_type_hints=None) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py new file mode 100644 index 000000000..094d0e246 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py new file mode 100644 index 000000000..00fd848d6 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py @@ -0,0 +1,12 @@ +import tensorflow as tf + + +@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),), autograph=False) +def func(x): + print('Tracing with', x) + return x + + +if __name__ == '__main__': + number = tf.constant([1.0, 1.0]) + func(number) \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py new file mode 100644 index 000000000..4fe4dc22b --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py @@ -0,0 +1,11 @@ +import custom + +@custom.decorator(input_signature=None) +def func(x): + print('Tracing with', x) + return x + + +if __name__ == '__main__': + func(1) + \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py similarity index 91% rename from edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py rename to edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py index 041bb974b..81a5551d2 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/custom.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py @@ -8,4 +8,4 @@ def wrapper(*args, **kwargs): return decorated - return decorator + return decorator \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/requirements.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/requirements.txt @@ -0,0 +1 @@ + diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py new file mode 100644 index 000000000..98c9365a1 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py @@ -0,0 +1,12 @@ +import custom +import tensorflow as tf + + +@custom.decorator(input_signature=None) +@tf.function(autograph=False) +def func(): + pass + + +if __name__ == '__main__': + func() \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py similarity index 91% rename from edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py rename to edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py index 041bb974b..81a5551d2 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/custom.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py @@ -8,4 +8,4 @@ def wrapper(*args, **kwargs): return decorated - return decorator + return decorator \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py new file mode 100644 index 000000000..7d9eb9885 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(autograph=False) +@tf.function(jit_compile=True) +def func(x): + return x + + +if __name__ == '__main__': + func(tf.constant(1)) \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py index efd65dbd3..ff293572a 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py @@ -1,11 +1,10 @@ import tensorflow as tf -@tf.function(experimental_follow_type_hints=True) -def func(): - pass +@tf.function(input_signature=(tf.TensorSpec(shape=(2, 2), dtype=tf.float32),)) +def func(x): + return x - if __name__ == '__main__': - func() - + number = tf.constant(([1.0, 1.0],[2.0,2.0])) + func(number) \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py index ccbd1c5fc..4919ccd07 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py @@ -1,11 +1,8 @@ import tensorflow as tf - -@tf.function(experimental_implements="google.matmul_low_rank_matrix") -def func(): - pass - +@tf.function(input_signature=[]) +def func(x): + return x if __name__ == '__main__': - func() - + func(tf.constant(2.)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py index 6c9135806..0b0820d5f 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py @@ -1,11 +1,8 @@ import tensorflow as tf - -@tf.function(jit_compile=True) -def func(): - print("Tracing") - +@tf.function(input_signature=[tf.TensorSpec([], tf.float32)]) +def func(x): + return x if __name__ == '__main__': - func() - + func(tf.constant(2.)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py index 56d547fea..5ca325d8a 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py @@ -1,7 +1,7 @@ import tensorflow as tf -@tf.function(reduce_retracing=True) +@tf.function(autograph=False) def func(): pass diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py index 03cee7678..a31334d45 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py @@ -1,11 +1,10 @@ import tensorflow as tf - -@tf.function(autograph=False) + +@tf.function(autograph=True) def func(): - print("Testing") + pass if __name__ == '__main__': - func() - + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py index 2a176ee4c..22987f2df 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py @@ -1,12 +1,10 @@ import tensorflow as tf -@tf.function -def test(x): - return x - +@tf.function(jit_compile=True) +def func(): + pass + if __name__ == '__main__': - x = tf.constant(1) - test(x) - + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py index 11139cb78..c8637e8b8 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py @@ -1,13 +1,10 @@ import tensorflow as tf -@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),), autograph=False) -def func(x): - print('Tracing with', x) - return x - +@tf.function(jit_compile=False) +def func(): + pass + if __name__ == '__main__': - number = tf.constant([1.0, 1.0]) - func(number) - + func() diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index d02cb0f60..2c4d7e522 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -845,16 +845,125 @@ public void testComputeParameters12() throws Exception { // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("None", args.getInputSignatureArg()); + // } + + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + // */ + // @Test + // public void testDecoratorArguments2() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); // } + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + // */ + // @Test + // public void testDecoratorArguments3() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("tf.TensorSpec(shape=(2, 2), dtype=tf.float32),)", args.getInputSignatureArg()); + // } + + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + // */ + // @Test + // public void testDecoratorArguments4() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("[]", args.getInputSignatureArg()); + // } + + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + // */ + // @Test + // public void testDecoratorArguments5() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("[tf.TensorSpec([], tf.float32)]", args.getInputSignatureArg()); + // } + /** - * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + * Test for #136. This simply tests whether we can get the tf.function argument autograph. */ @Test - public void testDecoratorArguments2() throws Exception { + public void testDecoratorArguments6() throws Exception { Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("False", args.getAutoGraphArg()); + } + /** + * Test for #136. This simply tests whether we can get the tf.function argument autograph. + */ + @Test + public void testDecoratorArguments7() throws Exception { + Set functions = this.getFunctions(); assertNotNull(functions); assertEquals(1, functions.size()); Function function = functions.iterator().next(); @@ -865,17 +974,17 @@ public void testDecoratorArguments2() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("tf.autograph.experimental.Feature.EQUALITY_OPERATORS", args.getExperimentalAutographOptArg()); + assertEquals("True", args.getAutoGraphArg()); } /** - * Test for #136. This simply tests whether we can get the tf.function argument experimental_follow_type_hints. + * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. */ @Test - public void testDecoratorArguments3() throws Exception { + public void testDecoratorArguments8() throws Exception { Set functions = this.getFunctions(); assertNotNull(functions); assertEquals(1, functions.size()); @@ -887,17 +996,101 @@ public void testDecoratorArguments3() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - && args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getExperimentalFollowTypeHintsArg()); + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("True", args.getJitCompileArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. + */ + @Test + public void testDecoratorArguments9() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("False", args.getJitCompileArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. + */ + @Test + public void testDecoratorArguments10() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("None", args.getJitCompileArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument reduce_retracing. + */ + @Test + public void testDecoratorArguments11() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("True", args.getReduceRetracingArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument reduce_retracing. + */ + @Test + public void testDecoratorArguments12() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("False", args.getReduceRetracingArg()); } // /** // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. // */ // @Test - // public void testDecoratorArguments4() throws Exception { + // public void testDecoratorArguments13() throws Exception { // Set functions = this.getFunctions(); // assertNotNull(functions); // assertEquals(1, functions.size()); @@ -915,12 +1108,57 @@ public void testDecoratorArguments3() throws Exception { // assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); // } + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + // */ + // @Test + // public void testDecoratorArguments14() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("google.embedded_matmul", args.getExperimentalImplementsArg()); + // } + + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + // */ + // @Test + // public void testDecoratorArguments15() throws Exception { + // Set functions = this.getFunctions(); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("None", args.getExperimentalImplementsArg()); + // } + /** - * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options */ @Test - public void testDecoratorArguments5() throws Exception { + public void testDecoratorArguments16() throws Exception { Set functions = this.getFunctions(); + assertNotNull(functions); assertEquals(1, functions.size()); Function function = functions.iterator().next(); @@ -931,38 +1169,66 @@ public void testDecoratorArguments5() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getJitCompileArg()); + assertEquals("tf.autograph.experimental.Feature.EQUALITY_OPERATORS", args.getExperimentalAutographOptArg()); } /** - * Test for #136. This simply tests whether we can get the tf.function argument reduce_retracing. + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options */ @Test - public void testDecoratorArguments6() throws Exception { + public void testDecoratorArguments17() throws Exception { Set functions = this.getFunctions(); + assertNotNull(functions); assertEquals(1, functions.size()); Function function = functions.iterator().next(); assertNotNull(function); + assertTrue(function.isHybrid()); + Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getReduceRetracingArg()); + assertEquals("tf.autograph.experimental.Feature.ALL", args.getExperimentalAutographOptArg()); } + // /** + // * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + // */ + // @Test + // public void testDecoratorArguments18() throws Exception { + // Set functions = this.getFunctions(); + // + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); + // + // assertTrue(function.isHybrid()); + // + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); + // + // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", + // args.getExperimentalAutographOptArg()); + // } + /** - * Test for #136. This simply tests whether we can get the tf.function argument autograph. + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options */ @Test - public void testDecoratorArguments7() throws Exception { + public void testDecoratorArguments19() throws Exception { Set functions = this.getFunctions(); + assertNotNull(functions); assertEquals(1, functions.size()); Function function = functions.iterator().next(); @@ -973,17 +1239,83 @@ public void testDecoratorArguments7() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("False", args.getAutoGraphArg()); + assertEquals("None", args.getExperimentalAutographOptArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_follow_type_hints. + */ + @Test + public void testDecoratorArguments20() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && args.hasExperimentalFollowTypeHintsParam()) + assertEquals("True", args.getExperimentalFollowTypeHintsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_follow_type_hints. + */ + @Test + public void testDecoratorArguments21() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && args.hasExperimentalFollowTypeHintsParam()) + assertEquals("False", args.getExperimentalFollowTypeHintsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_follow_type_hints. + */ + @Test + public void testDecoratorArguments22() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && args.hasExperimentalFollowTypeHintsParam()) + assertEquals("None", args.getExperimentalFollowTypeHintsArg()); } /** * Test for #136. This simply tests whether we can identify when there are no tf.function args. */ @Test - public void testDecoratorArguments8() throws Exception { + public void testDecoratorArguments23() throws Exception { Set functions = this.getFunctions(); assertNotNull(functions); assertEquals(1, functions.size()); @@ -1004,7 +1336,7 @@ public void testDecoratorArguments8() throws Exception { // * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. // */ // @Test - // public void testDecoratorArguments9() throws Exception { + // public void testDecoratorArguments24() throws Exception { // Set functions = this.getFunctions(); // assertNotNull(functions); // assertEquals(1, functions.size()); @@ -1028,7 +1360,7 @@ public void testDecoratorArguments8() throws Exception { * Test for #136. Test custom decorator with the same parameter names as tf.function. */ @Test - public void testDecoratorArguments10() throws Exception { + public void testDecoratorArguments25() throws Exception { Set functions = this.getFunctions(); assertNotNull(functions); assertEquals(1, functions.size()); @@ -1052,7 +1384,7 @@ public void testDecoratorArguments10() throws Exception { * only count the parameters from the tf.function decorator. */ @Test - public void testDecoratorArguments11() throws Exception { + public void testDecoratorArguments26() throws Exception { Set functions = this.getFunctions(); assertNotNull(functions); assertEquals(1, functions.size()); @@ -1079,7 +1411,7 @@ public void testDecoratorArguments11() throws Exception { * Test for #136. Tests two different tf.functions. Should only count the parameters of the last one. */ @Test - public void testDecoratorArguments12() throws Exception { + public void testDecoratorArguments27() throws Exception { Set functions = this.getFunctions(); assertNotNull(functions); assertEquals(1, functions.size()); From d6b110cbab95caaa0e6f1d0da0b3968e78a985c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 1 Feb 2023 16:06:26 -0500 Subject: [PATCH 10/70] Fixing trailing whitespace of tests --- .../HybridizeFunction/testDecoratorArguments/in/A.py | 1 + .../HybridizeFunction/testDecoratorArguments10/in/A.py | 2 +- .../HybridizeFunction/testDecoratorArguments11/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments12/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments13/in/A.py | 2 +- .../HybridizeFunction/testDecoratorArguments14/in/A.py | 2 +- .../HybridizeFunction/testDecoratorArguments15/in/A.py | 2 +- .../HybridizeFunction/testDecoratorArguments16/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments17/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments18/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments19/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments20/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments21/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments22/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments23/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments25/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments25/in/custom.py | 2 +- .../HybridizeFunction/testDecoratorArguments26/in/A.py | 2 +- .../HybridizeFunction/testDecoratorArguments26/in/custom.py | 2 +- .../HybridizeFunction/testDecoratorArguments27/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments7/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments8/in/A.py | 4 ++-- .../HybridizeFunction/testDecoratorArguments9/in/A.py | 4 ++-- 23 files changed, 38 insertions(+), 37 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py index 0b74fa6d9..700a01ab3 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py @@ -5,6 +5,7 @@ def func(x): return x + if __name__ == '__main__': number = tf.constant([1.0, 1.0]) func(number) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py index 31b29a7f0..1457b526b 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py @@ -7,4 +7,4 @@ def func(): if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py index 56d547fea..4901c4d95 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py index 5d50229e5..0c360ead3 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py index 425fb101e..a92f73e29 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py index d3bc1edbb..862cdbcab 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py index e550407e9..58b7a6750 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments15/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py index e9b7f7db1..98d3e3cc5 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py index d59b57c62..8c3cb4143 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py index c40b2c9b8..88bd51931 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py index 2b49f866c..a1a14268f 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments19/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py index e523599eb..1618ed3d7 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py index 05385048f..136ed83a3 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments21/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py index 92fa92e1c..2c21453e1 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments22/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py index 094d0e246..12d835033 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments23/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py index 4fe4dc22b..79ab565ca 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/A.py @@ -1,11 +1,11 @@ import custom + @custom.decorator(input_signature=None) def func(x): print('Tracing with', x) return x - + if __name__ == '__main__': func(1) - \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py index 81a5551d2..041bb974b 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/custom.py @@ -8,4 +8,4 @@ def wrapper(*args, **kwargs): return decorated - return decorator \ No newline at end of file + return decorator diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py index 98c9365a1..2b39f30c1 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/A.py @@ -9,4 +9,4 @@ def func(): if __name__ == '__main__': - func() \ No newline at end of file + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py index 81a5551d2..041bb974b 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/custom.py @@ -8,4 +8,4 @@ def wrapper(*args, **kwargs): return decorated - return decorator \ No newline at end of file + return decorator diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py index 7d9eb9885..981dfe88e 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments27/in/A.py @@ -6,6 +6,6 @@ def func(x): return x - + if __name__ == '__main__': - func(tf.constant(1)) \ No newline at end of file + func(tf.constant(1)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py index a31334d45..619ec3d9c 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py index 22987f2df..e300f8147 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py index c8637e8b8..4e80146ad 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py @@ -5,6 +5,6 @@ def func(): pass - + if __name__ == '__main__': - func() + func() From 26fd8f12bbad65cc3ecb99a0cbc080d1b79b66b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 1 Feb 2023 20:49:21 -0500 Subject: [PATCH 11/70] Fix to test --- .../HybridizeFunction/testDecoratorArguments16/in/A.py | 2 +- .../HybridizeFunction/testDecoratorArguments17/in/A.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py index 98d3e3cc5..b21991d11 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py @@ -1,7 +1,7 @@ import tensorflow as tf -@tf.function(experimental_autograph_options="tf.autograph.experimental.Feature.EQUALITY_OPERATORS") +@tf.function(experimental_autograph_options=tf.autograph.experimental.Feature.EQUALITY_OPERATORS) def func(): pass diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py index 8c3cb4143..15284b7da 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments17/in/A.py @@ -1,7 +1,7 @@ import tensorflow as tf -@tf.function(experimental_autograph_options="tf.autograph.experimental.Feature.ALL") +@tf.function(experimental_autograph_options=tf.autograph.experimental.Feature.ALL) def func(): pass From 9a4cb623ff98335971f802e07e14b9e35e7e7441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 1 Feb 2023 20:58:24 -0500 Subject: [PATCH 12/70] adding other params --- .../hybridize/core/analysis/Function.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 58c5cb628..337a8f5ae 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -383,6 +383,24 @@ public String getJitCompileArg() { public String getReduceRetracingArg() { return this.reduceRetracingParamValue; } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_compile. + * + * @return String of this {@link decoratorType} parameter experimental_compile. + */ + public String getExperimentalCompileArg() { + return this.jitCompileParamValue; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_relax_shapes. + * + * @return String of this {@link Function} parameter experimental_relax_shapes. + */ + public String getExperimentalRelaxShapeArg() { + return this.reduceRetracingParamValue; + } } private static final String TF_FUNCTION_FQN = "tensorflow.python.eager.def_function.function"; From d0d087506c0a1bd4826c73db10c4c4539cf52d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 1 Feb 2023 22:47:03 -0500 Subject: [PATCH 13/70] Progress --- .../hybridize/core/analysis/Function.java | 49 +++-- .../HybridizeFunctionRefactoringTest.java | 192 +++++++++--------- 2 files changed, 132 insertions(+), 109 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 337a8f5ae..d1eea7d80 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -16,6 +16,7 @@ import org.python.pydev.parser.jython.ast.FunctionDef; import org.python.pydev.parser.jython.ast.Name; import org.python.pydev.parser.jython.ast.NameTok; +import org.python.pydev.parser.jython.ast.Str; import org.python.pydev.parser.jython.ast.argumentsType; import org.python.pydev.parser.jython.ast.decoratorsType; import org.python.pydev.parser.jython.ast.exprType; @@ -177,26 +178,36 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (name.id.equals(FUNC)) { // Found parameter func this.funcParamExists = true; - Name value = (Name) keyword.value; - this.funcParamValue = value.id; + // Name of function. + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.funcParamValue = value.id; + } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature this.inputSignatureParamExists = true; - // Tuple value = (Tuple) keyword.value; - // this.inputSignatureParamValue = value.id; + // TODO: Nested sequence of tf.TensorSpecs + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.inputSignatureParamValue = value.id; + } } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph this.autoGraphParamExists = true; - Name value = (Name) keyword.value; - this.autoGraphParamValue = value.id; + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.autoGraphParamValue = value.id; + } // The version of the API we are using allows // parameter names jit_compile and // deprecated name experimental_compile } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; - Name value = (Name) keyword.value; - this.jitCompileParamValue = value.id; + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.jitCompileParamValue = value.id; + } // The version of the API we are using allows // parameter names reduce_retracing // and deprecated name experimental_relax_shapes @@ -204,16 +215,26 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Found parameter reduce_retracing // or experimental_relax_shapes this.reduceRetracingParamExists = true; - Name value = (Name) keyword.value; - this.reduceRetracingParamValue = value.id; + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.reduceRetracingParamValue = value.id; + } } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements this.experimentalImplementsParamExists = true; - // this.experimentalImplementsParamValue = value.id; + if (keyword.value instanceof Str) { + Str value = (Str) keyword.value; + this.experimentalImplementsParamValue = value.s; + } + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentalImplementsParamValue = value.id; + } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options this.experimentalAutographOptionsParamExists = true; StringBuilder argument = new StringBuilder(); + // TODO: Tuple of multiple options if (keyword.value instanceof Attribute) { Attribute attr = (Attribute) keyword.value; while (attr.value instanceof Attribute) { @@ -232,8 +253,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints this.experimentaFollowTypeHintsParamExists = true; - Name value = (Name) keyword.value; - this.experimentaFollowTypeHintsParamValue = value.id; + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentaFollowTypeHintsParamValue = value.id; + } } } } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 2c4d7e522..c9079bda3 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -826,27 +826,27 @@ public void testComputeParameters12() throws Exception { } - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - // */ - // @Test - // public void testDecoratorArguments() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("None", args.getInputSignatureArg()); - // } + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("None", args.getInputSignatureArg()); + } // /** // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. @@ -1086,71 +1086,71 @@ public void testDecoratorArguments12() throws Exception { assertEquals("False", args.getReduceRetracingArg()); } - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. - // */ - // @Test - // public void testDecoratorArguments13() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); - // } + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + */ + @Test + public void testDecoratorArguments13() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. - // */ - // @Test - // public void testDecoratorArguments14() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("google.embedded_matmul", args.getExperimentalImplementsArg()); - // } + assertTrue(function.isHybrid()); - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. - // */ - // @Test - // public void testDecoratorArguments15() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("None", args.getExperimentalImplementsArg()); - // } + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("google.matmul_low_rank_matrix", args.getExperimentalImplementsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + */ + @Test + public void testDecoratorArguments14() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("google.embedded_matmul", args.getExperimentalImplementsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_implements. + */ + @Test + public void testDecoratorArguments15() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("None", args.getExperimentalImplementsArg()); + } /** * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options @@ -1205,21 +1205,21 @@ public void testDecoratorArguments17() throws Exception { // public void testDecoratorArguments18() throws Exception { // Set functions = this.getFunctions(); // - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); + // assertNotNull(functions); + // assertEquals(1, functions.size()); + // Function function = functions.iterator().next(); + // assertNotNull(function); // - // assertTrue(function.isHybrid()); + // assertTrue(function.isHybrid()); // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); + // Function.HybridizationParameters args = function.getHybridizationParameters(); + // assertNotNull(args); // - // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", - // args.getExperimentalAutographOptArg()); + // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + // && !args.hasExperimentalFollowTypeHintsParam()) + // assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", + // args.getExperimentalAutographOptArg()); // } /** From 015965a6393071a5d986edc596bd73e399bc13f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 2 Feb 2023 18:08:24 -0500 Subject: [PATCH 14/70] Modifying test resource --- .../hybridize/tests/HybridizeFunctionRefactoringTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index c9079bda3..f4d807c27 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1127,7 +1127,7 @@ public void testDecoratorArguments14() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("google.embedded_matmul", args.getExperimentalImplementsArg()); + assertEquals("embedded_matmul", args.getExperimentalImplementsArg()); } /** From 61023516b6e9c1b9d9e749dfd735b15039c4390e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 2 Feb 2023 18:17:55 -0500 Subject: [PATCH 15/70] Modifying test resource --- .../HybridizeFunction/testDecoratorArguments14/in/A.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py index 862cdbcab..0a6cf5e04 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments14/in/A.py @@ -1,7 +1,7 @@ import tensorflow as tf -@tf.function(experimental_implements="google.embedded_matmul") +@tf.function(experimental_implements="embedded_matmul") def func(): pass From a62af558c39e6ce4bbb1fa49b64fce1201be6987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Sun, 5 Feb 2023 18:41:24 -0500 Subject: [PATCH 16/70] Renaming variable --- .../hunter/hybridize/core/analysis/Function.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index d1eea7d80..da98dba0f 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -226,7 +226,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep Str value = (Str) keyword.value; this.experimentalImplementsParamValue = value.s; } - if (keyword.value instanceof Name) { + else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; this.experimentalImplementsParamValue = value.id; } @@ -236,17 +236,17 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep StringBuilder argument = new StringBuilder(); // TODO: Tuple of multiple options if (keyword.value instanceof Attribute) { - Attribute attr = (Attribute) keyword.value; - while (attr.value instanceof Attribute) { - NameTok valueAttribute = (NameTok) attr.attr; + Attribute keywordAttribute = (Attribute) keyword.value; + while (keywordAttribute.value instanceof Attribute) { + NameTok valueAttribute = (NameTok) keywordAttribute.attr; argument.insert(0, valueAttribute.id); argument.insert(0, "."); - attr = (Attribute) attr.value; + keywordAttribute = (Attribute) keywordAttribute.value; } - this.experimentalAutographOptionsParamValue = ((Name) attr.value).id + "." + ((NameTok) attr.attr).id - + argument.toString(); + this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." + + ((NameTok) keywordAttribute.attr).id + argument.toString(); } - if (keyword.value instanceof Name) { + else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; this.experimentalAutographOptionsParamValue = value.id; } From f7a93733d944254f5fb96b52b3500724c1d1793e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Sun, 5 Feb 2023 18:42:15 -0500 Subject: [PATCH 17/70] Formatting --- .../edu/cuny/hunter/hybridize/core/analysis/Function.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index da98dba0f..ef6bf5de6 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -225,8 +225,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Str) { Str value = (Str) keyword.value; this.experimentalImplementsParamValue = value.s; - } - else if (keyword.value instanceof Name) { + } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; this.experimentalImplementsParamValue = value.id; } @@ -245,8 +244,7 @@ else if (keyword.value instanceof Name) { } this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." + ((NameTok) keywordAttribute.attr).id + argument.toString(); - } - else if (keyword.value instanceof Name) { + } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; this.experimentalAutographOptionsParamValue = value.id; } From c9ee308d177d0f537e59f2546874aaa7e5d2883f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Feb 2023 01:24:12 -0500 Subject: [PATCH 18/70] Adding exceptions --- .../hybridize/core/analysis/Function.java | 130 ++++++++++++------ ...HybridizeFunctionRefactoringProcessor.java | 2 +- .../hunter/hybridize/core/utils/Util.java | 2 +- .../HybridizeFunctionRefactoringWizard.java | 2 +- 4 files changed, 92 insertions(+), 44 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index ef6bf5de6..7fb0aad0f 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -143,7 +143,7 @@ public class HybridizationParameters { */ private String reduceRetracingParamValue; - public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { + public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException, IllegalArgumentException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); decoratorsType[] decoratorArray = functionDefinition.getFunctionDef().decs; @@ -178,25 +178,42 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (name.id.equals(FUNC)) { // Found parameter func this.funcParamExists = true; - // Name of function. - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.funcParamValue = value.id; + try { + // Example of value: Name of function or None + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.funcParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature this.inputSignatureParamExists = true; // TODO: Nested sequence of tf.TensorSpecs - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.inputSignatureParamValue = value.id; + try { + // Example of value: None + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.inputSignatureParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph this.autoGraphParamExists = true; - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.autoGraphParamValue = value.id; + try { + // Example of value: True, False + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.autoGraphParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } // The version of the API we are using allows // parameter names jit_compile and @@ -204,9 +221,15 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.jitCompileParamValue = value.id; + // Example of value: True, False, None + try { + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.jitCompileParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } // The version of the API we are using allows // parameter names reduce_retracing @@ -215,45 +238,70 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Found parameter reduce_retracing // or experimental_relax_shapes this.reduceRetracingParamExists = true; - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.reduceRetracingParamValue = value.id; + try { + // Example of value: True, False + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.reduceRetracingParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements this.experimentalImplementsParamExists = true; - if (keyword.value instanceof Str) { - Str value = (Str) keyword.value; - this.experimentalImplementsParamValue = value.s; - } else if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.experimentalImplementsParamValue = value.id; + try { + // Example of value: "google.matmul_low_rank_matrix" + if (keyword.value instanceof Str) { + Str value = (Str) keyword.value; + this.experimentalImplementsParamValue = value.s; + // Example of value: None + } else if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentalImplementsParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options this.experimentalAutographOptionsParamExists = true; - StringBuilder argument = new StringBuilder(); - // TODO: Tuple of multiple options - if (keyword.value instanceof Attribute) { - Attribute keywordAttribute = (Attribute) keyword.value; - while (keywordAttribute.value instanceof Attribute) { - NameTok valueAttribute = (NameTok) keywordAttribute.attr; - argument.insert(0, valueAttribute.id); - argument.insert(0, "."); - keywordAttribute = (Attribute) keywordAttribute.value; + try { + StringBuilder argument = new StringBuilder(); + // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS + if (keyword.value instanceof Attribute) { + Attribute keywordAttribute = (Attribute) keyword.value; + while (keywordAttribute.value instanceof Attribute) { + NameTok valueAttribute = (NameTok) keywordAttribute.attr; + argument.insert(0, valueAttribute.id); + argument.insert(0, "."); + keywordAttribute = (Attribute) keywordAttribute.value; + } + this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." + + ((NameTok) keywordAttribute.attr).id + argument.toString(); + // Example of value: None + } else if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentalAutographOptionsParamValue = value.id; } - this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." - + ((NameTok) keywordAttribute.attr).id + argument.toString(); - } else if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.experimentalAutographOptionsParamValue = value.id; + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints this.experimentaFollowTypeHintsParamExists = true; - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.experimentaFollowTypeHintsParamValue = value.id; + try { + // Example of value: True, False, None + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentaFollowTypeHintsParamValue = value.id; + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Unable to process your decorators arguments: " + keyword.value.toString(), e); } } } @@ -465,7 +513,7 @@ public String getExperimentalRelaxShapeArg() { */ private IPythonNature nature; - public Function(FunctionDefinition fd, IProgressMonitor monitor) throws BadLocationException { + public Function(FunctionDefinition fd, IProgressMonitor monitor) throws BadLocationException, IllegalArgumentException { this.functionDefinition = fd; // Find out if it's hybrid via the tf.function decorator. diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java index 007fb24da..2fd49a7f7 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java @@ -54,7 +54,7 @@ public HybridizeFunctionRefactoringProcessor() { } public HybridizeFunctionRefactoringProcessor(Set functionDefinitions, IProgressMonitor monitor) - throws TooManyMatchesException, BadLocationException { + throws TooManyMatchesException, BadLocationException, IllegalArgumentException { // Force the use of typeshed. It's an experimental feature of PyDev. InterpreterGeneralPreferences.FORCE_USE_TYPESHED = Boolean.TRUE; diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java index b7416e998..04304d26e 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java @@ -14,7 +14,7 @@ public class Util { public static Refactoring createRefactoring(Set functionDefinitions, IProgressMonitor monitor) - throws TooManyMatchesException, BadLocationException { + throws TooManyMatchesException, BadLocationException, IllegalArgumentException { HybridizeFunctionRefactoringProcessor processor = new HybridizeFunctionRefactoringProcessor(functionDefinitions, monitor); return new ProcessorBasedRefactoring(processor); } diff --git a/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java b/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java index 0a6d42cb3..769b49ea8 100644 --- a/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java +++ b/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java @@ -64,7 +64,7 @@ protected void setProcessor(RefactoringProcessor processor) { } public static void startRefactoring(Set functionDefinitions, Shell shell, IProgressMonitor monitor) - throws TooManyMatchesException, BadLocationException { + throws TooManyMatchesException, BadLocationException, IllegalArgumentException { Refactoring refactoring = edu.cuny.hunter.hybridize.core.utils.Util.createRefactoring(functionDefinitions, monitor); RefactoringWizard wizard = new HybridizeFunctionRefactoringWizard(refactoring); From 0ab5892d295b0f8379bf1d3bed0c1659f1c61657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Feb 2023 11:48:44 -0500 Subject: [PATCH 19/70] Add more info to exception --- .../hybridize/core/analysis/Function.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 7fb0aad0f..49a3e83ea 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -186,7 +186,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } catch (Exception e) { throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + "Unable to process " + FUNC + " arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature @@ -200,7 +200,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } catch (Exception e) { throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + "Unable to process " + INPUT_SIGNATURE + " arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph @@ -213,12 +213,12 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } catch (Exception e) { throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + "Unable to process " + AUTOGRAPH + " arguments: " + keyword.value.toString(), e); } // The version of the API we are using allows // parameter names jit_compile and // deprecated name experimental_compile - } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { + } else if (name.id.equals(JIT_COMPILE) || name.id.equals(JIT_COMPILE)) { // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; // Example of value: True, False, None @@ -228,8 +228,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.jitCompileParamValue = value.id; } } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + throw new IllegalArgumentException("Unable to process " + JIT_COMPILE + "/" + JIT_COMPILE + + " arguments: " + keyword.value.toString(), e); } // The version of the API we are using allows // parameter names reduce_retracing @@ -245,8 +245,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.reduceRetracingParamValue = value.id; } } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + throw new IllegalArgumentException("Unable to process " + REDUCE_RETRACING + "/" + + EXPERIMENTAL_RELAX_SHAPES + " arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements @@ -263,7 +263,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } catch (Exception e) { throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + "Unable to process " + EXPERIMENTAL_IMPLEMENTS + " arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options @@ -287,8 +287,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.experimentalAutographOptionsParamValue = value.id; } } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + + " arguments: " + keyword.value.toString(), e); } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints @@ -300,8 +300,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.experimentaFollowTypeHintsParamValue = value.id; } } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process your decorators arguments: " + keyword.value.toString(), e); + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + + " arguments: " + keyword.value.toString(), e); } } } From db5147f347911dceac8ecd6618816e686eb58f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Feb 2023 11:55:57 -0500 Subject: [PATCH 20/70] Adding new line to test resource --- .../resources/HybridizeFunction/testDecoratorArguments3/in/A.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py index ff293572a..47e13d135 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py @@ -7,4 +7,4 @@ def func(x): if __name__ == '__main__': number = tf.constant(([1.0, 1.0],[2.0,2.0])) - func(number) \ No newline at end of file + func(number) From b9bd9beb7f68f8eb33830716de3859a9e599f3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Feb 2023 12:35:52 -0500 Subject: [PATCH 21/70] Restructuring exceptions --- .../hybridize/core/analysis/Function.java | 157 ++++++++---------- ...HybridizeFunctionRefactoringProcessor.java | 2 +- .../hunter/hybridize/core/utils/Util.java | 2 +- .../HybridizeFunctionRefactoringWizard.java | 2 +- 4 files changed, 72 insertions(+), 91 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 49a3e83ea..1962ccfe4 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -143,7 +143,7 @@ public class HybridizationParameters { */ private String reduceRetracingParamValue; - public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException, IllegalArgumentException { + public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); decoratorsType[] decoratorArray = functionDefinition.getFunctionDef().decs; @@ -178,42 +178,34 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (name.id.equals(FUNC)) { // Found parameter func this.funcParamExists = true; - try { - // Example of value: Name of function or None - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.funcParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process " + FUNC + " arguments: " + keyword.value.toString(), e); + // Example of value: Name of function or None + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.funcParamValue = value.id; + } else { + throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature this.inputSignatureParamExists = true; // TODO: Nested sequence of tf.TensorSpecs - try { - // Example of value: None - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.inputSignatureParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process " + INPUT_SIGNATURE + " arguments: " + keyword.value.toString(), e); + // Example of value: None + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.inputSignatureParamValue = value.id; + + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph this.autoGraphParamExists = true; - try { - // Example of value: True, False - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.autoGraphParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process " + AUTOGRAPH + " arguments: " + keyword.value.toString(), e); + // Example of value: True, False + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.autoGraphParamValue = value.id; + } else { + throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); } // The version of the API we are using allows // parameter names jit_compile and @@ -222,14 +214,12 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; // Example of value: True, False, None - try { - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.jitCompileParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException("Unable to process " + JIT_COMPILE + "/" + JIT_COMPILE - + " arguments: " + keyword.value.toString(), e); + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.jitCompileParamValue = value.id; + } else { + throw new IllegalArgumentException( + "Unable to process " + JIT_COMPILE + "/" + JIT_COMPILE + " argument."); } // The version of the API we are using allows // parameter names reduce_retracing @@ -238,70 +228,61 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Found parameter reduce_retracing // or experimental_relax_shapes this.reduceRetracingParamExists = true; - try { - // Example of value: True, False - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.reduceRetracingParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException("Unable to process " + REDUCE_RETRACING + "/" - + EXPERIMENTAL_RELAX_SHAPES + " arguments: " + keyword.value.toString(), e); + // Example of value: True, False + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.reduceRetracingParamValue = value.id; + } else { + throw new IllegalArgumentException( + "Unable to process " + REDUCE_RETRACING + "/" + EXPERIMENTAL_RELAX_SHAPES + " argument."); } } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements this.experimentalImplementsParamExists = true; - try { - // Example of value: "google.matmul_low_rank_matrix" - if (keyword.value instanceof Str) { - Str value = (Str) keyword.value; - this.experimentalImplementsParamValue = value.s; - // Example of value: None - } else if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.experimentalImplementsParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException( - "Unable to process " + EXPERIMENTAL_IMPLEMENTS + " arguments: " + keyword.value.toString(), e); + // Example of value: "google.matmul_low_rank_matrix" + if (keyword.value instanceof Str) { + Str value = (Str) keyword.value; + this.experimentalImplementsParamValue = value.s; + // Example of value: None + } else if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentalImplementsParamValue = value.id; + } else { + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options this.experimentalAutographOptionsParamExists = true; - try { - StringBuilder argument = new StringBuilder(); - // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS - if (keyword.value instanceof Attribute) { - Attribute keywordAttribute = (Attribute) keyword.value; - while (keywordAttribute.value instanceof Attribute) { - NameTok valueAttribute = (NameTok) keywordAttribute.attr; - argument.insert(0, valueAttribute.id); - argument.insert(0, "."); - keywordAttribute = (Attribute) keywordAttribute.value; - } - this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." - + ((NameTok) keywordAttribute.attr).id + argument.toString(); - // Example of value: None - } else if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.experimentalAutographOptionsParamValue = value.id; + StringBuilder argument = new StringBuilder(); + // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS + if (keyword.value instanceof Attribute) { + Attribute keywordAttribute = (Attribute) keyword.value; + while (keywordAttribute.value instanceof Attribute) { + NameTok valueAttribute = (NameTok) keywordAttribute.attr; + argument.insert(0, valueAttribute.id); + argument.insert(0, "."); + keywordAttribute = (Attribute) keywordAttribute.value; } - } catch (Exception e) { - throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS - + " arguments: " + keyword.value.toString(), e); + this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." + + ((NameTok) keywordAttribute.attr).id + argument.toString(); + // Example of value: None + } else if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentalAutographOptionsParamValue = value.id; + } else { + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " arguments"); } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints this.experimentaFollowTypeHintsParamExists = true; - try { - // Example of value: True, False, None - if (keyword.value instanceof Name) { - Name value = (Name) keyword.value; - this.experimentaFollowTypeHintsParamValue = value.id; - } - } catch (Exception e) { - throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS - + " arguments: " + keyword.value.toString(), e); + // Example of value: True, False, None + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + this.experimentaFollowTypeHintsParamValue = value.id; + } else { + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " arguments"); } } } @@ -513,7 +494,7 @@ public String getExperimentalRelaxShapeArg() { */ private IPythonNature nature; - public Function(FunctionDefinition fd, IProgressMonitor monitor) throws BadLocationException, IllegalArgumentException { + public Function(FunctionDefinition fd, IProgressMonitor monitor) throws BadLocationException { this.functionDefinition = fd; // Find out if it's hybrid via the tf.function decorator. diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java index 2fd49a7f7..007fb24da 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/refactorings/HybridizeFunctionRefactoringProcessor.java @@ -54,7 +54,7 @@ public HybridizeFunctionRefactoringProcessor() { } public HybridizeFunctionRefactoringProcessor(Set functionDefinitions, IProgressMonitor monitor) - throws TooManyMatchesException, BadLocationException, IllegalArgumentException { + throws TooManyMatchesException, BadLocationException { // Force the use of typeshed. It's an experimental feature of PyDev. InterpreterGeneralPreferences.FORCE_USE_TYPESHED = Boolean.TRUE; diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java index 04304d26e..b7416e998 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/utils/Util.java @@ -14,7 +14,7 @@ public class Util { public static Refactoring createRefactoring(Set functionDefinitions, IProgressMonitor monitor) - throws TooManyMatchesException, BadLocationException, IllegalArgumentException { + throws TooManyMatchesException, BadLocationException { HybridizeFunctionRefactoringProcessor processor = new HybridizeFunctionRefactoringProcessor(functionDefinitions, monitor); return new ProcessorBasedRefactoring(processor); } diff --git a/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java b/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java index 769b49ea8..0a6d42cb3 100644 --- a/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java +++ b/edu.cuny.hunter.hybridize.ui/src/edu/cuny/hunter/hybridize/ui/wizards/HybridizeFunctionRefactoringWizard.java @@ -64,7 +64,7 @@ protected void setProcessor(RefactoringProcessor processor) { } public static void startRefactoring(Set functionDefinitions, Shell shell, IProgressMonitor monitor) - throws TooManyMatchesException, BadLocationException, IllegalArgumentException { + throws TooManyMatchesException, BadLocationException { Refactoring refactoring = edu.cuny.hunter.hybridize.core.utils.Util.createRefactoring(functionDefinitions, monitor); RefactoringWizard wizard = new HybridizeFunctionRefactoringWizard(refactoring); From 9db53968999d39df6004df25f30a67a28cf0d4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Feb 2023 12:37:20 -0500 Subject: [PATCH 22/70] Adding new line to test resource --- .../HybridizeFunction/testDecoratorArguments24/in/A.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py index 00fd848d6..2ea60445d 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments24/in/A.py @@ -9,4 +9,4 @@ def func(x): if __name__ == '__main__': number = tf.constant([1.0, 1.0]) - func(number) \ No newline at end of file + func(number) From ec84857972327f47f1c10514152549a1c5bccbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Feb 2023 12:38:57 -0500 Subject: [PATCH 23/70] Fixing variable name --- .../src/edu/cuny/hunter/hybridize/core/analysis/Function.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 1962ccfe4..7c4b78c02 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -210,7 +210,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // The version of the API we are using allows // parameter names jit_compile and // deprecated name experimental_compile - } else if (name.id.equals(JIT_COMPILE) || name.id.equals(JIT_COMPILE)) { + } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { // Found parameter jit_compile/experimental_compile this.jitCompileParamExists = true; // Example of value: True, False, None @@ -219,7 +219,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.jitCompileParamValue = value.id; } else { throw new IllegalArgumentException( - "Unable to process " + JIT_COMPILE + "/" + JIT_COMPILE + " argument."); + "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); } // The version of the API we are using allows // parameter names reduce_retracing From 74b4bc4d8e4785435c8ae5e9645707e574088f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 7 Feb 2023 15:44:47 -0500 Subject: [PATCH 24/70] Progress --- .../hybridize/core/analysis/Function.java | 174 ++++++++---- .../HybridizeFunctionRefactoringTest.java | 266 +++++++++--------- 2 files changed, 247 insertions(+), 193 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 7c4b78c02..48a3f686d 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -3,6 +3,7 @@ import static org.eclipse.core.runtime.Platform.getLog; import java.io.File; +import java.util.ArrayList; import java.util.Objects; import org.eclipse.core.runtime.ILog; @@ -14,9 +15,12 @@ import org.python.pydev.parser.jython.ast.Attribute; import org.python.pydev.parser.jython.ast.Call; import org.python.pydev.parser.jython.ast.FunctionDef; +import org.python.pydev.parser.jython.ast.List; import org.python.pydev.parser.jython.ast.Name; import org.python.pydev.parser.jython.ast.NameTok; +import org.python.pydev.parser.jython.ast.Num; import org.python.pydev.parser.jython.ast.Str; +import org.python.pydev.parser.jython.ast.Tuple; import org.python.pydev.parser.jython.ast.argumentsType; import org.python.pydev.parser.jython.ast.decoratorsType; import org.python.pydev.parser.jython.ast.exprType; @@ -63,46 +67,6 @@ public class HybridizationParameters { private static final String FUNC = "func"; - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter autograph. - */ - private boolean autoGraphParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter experimental_follow_type_hints. - */ - private boolean experimentaFollowTypeHintsParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter experimental_autograph_options. - */ - private boolean experimentalAutographOptionsParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter experimental_implements. - */ - private boolean experimentalImplementsParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter func. - */ - private boolean funcParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter input_signature. - */ - private boolean inputSignatureParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter jit_compile. - */ - private boolean jitCompileParamExists; - - /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter reduce_retracing. - */ - private boolean reduceRetracingParamExists; - /** * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. */ @@ -143,6 +107,45 @@ public class HybridizationParameters { */ private String reduceRetracingParamValue; + final class TensorSpec { + private String shape; + private String dtype; + + public TensorSpec() { + this.shape = ""; + this.dtype = ""; // Default value + } + + public TensorSpec(String s, String d) { + this.shape = s; + this.dtype = d; + } + + public String getShape() { + return this.shape; + } + + public String getDType() { + return this.dtype; + } + + public void setShape(String s) { + this.shape = s; + } + + public void setDType(String d) { + this.dtype = d; + } + + @Override + public String toString() { + if (this.dtype.isEmpty() && this.shape.isEmpty()) + return "tf.TensorSpec([])"; + else + return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; + } + } + public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); decoratorsType[] decoratorArray = functionDefinition.getFunctionDef().decs; @@ -177,7 +180,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep NameTok name = (NameTok) keyword.arg; if (name.id.equals(FUNC)) { // Found parameter func - this.funcParamExists = true; // Example of value: Name of function or None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -187,19 +189,56 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature - this.inputSignatureParamExists = true; + LOG.info(keyword.value.toString()); // TODO: Nested sequence of tf.TensorSpecs + // Example of value: None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; this.inputSignatureParamValue = value.id; - + // Example: (tf.TensorSpec(shape=[None], dtype=tf.float32),) + } else if (keyword.value instanceof Tuple) { + Tuple value = (Tuple) keyword.value; + exprType[] valueElements = value.elts; + this.inputSignatureParamValue += "("; + ArrayList tensorSpecList = new ArrayList<>(); + for (exprType expr : valueElements) { + if (expr instanceof Call) { + Call callTuple = (Call) expr; + keywordType[] keywordsCall = callTuple.keywords; + TensorSpec tensor = new TensorSpec(); + for (keywordType kywrds : keywordsCall) { + if (kywrds.value instanceof Tuple) + tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); + if (kywrds.value instanceof List) + tensor.setShape(processTupleOrList(((List) kywrds.value).elts)); + if (kywrds.value instanceof Attribute) { + Attribute attrValue = (Attribute) kywrds.value; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } + } + tensorSpecList.add(tensor); + } + } + this.inputSignatureParamValue = "("; + int count = 0; + for (TensorSpec tensor : tensorSpecList) { + if (count == 0) + this.inputSignatureParamValue += tensor.toString(); + else + this.inputSignatureParamValue += ", " + tensor.toString(); + count++; + } + if (value.endsWithComma) + this.inputSignatureParamValue += ",)"; + else + this.inputSignatureParamValue += ")"; } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } + LOG.info(inputSignatureParamValue); } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph - this.autoGraphParamExists = true; // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -211,8 +250,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // parameter names jit_compile and // deprecated name experimental_compile } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { - // Found parameter jit_compile/experimental_compile - this.jitCompileParamExists = true; + // Found parameter jit_compile or experimental_compile // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -225,9 +263,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // parameter names reduce_retracing // and deprecated name experimental_relax_shapes } else if (name.id.equals(REDUCE_RETRACING) || name.id.equals(EXPERIMENTAL_RELAX_SHAPES)) { - // Found parameter reduce_retracing - // or experimental_relax_shapes - this.reduceRetracingParamExists = true; + // Found parameter reduce_retracing or experimental_relax_shapes // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -238,7 +274,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements - this.experimentalImplementsParamExists = true; // Example of value: "google.matmul_low_rank_matrix" if (keyword.value instanceof Str) { Str value = (Str) keyword.value; @@ -252,7 +287,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options - this.experimentalAutographOptionsParamExists = true; StringBuilder argument = new StringBuilder(); // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS if (keyword.value instanceof Attribute) { @@ -275,7 +309,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints - this.experimentaFollowTypeHintsParamExists = true; // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -290,13 +323,34 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } // else, tf.function is used without parameters. } + private String processTupleOrList(exprType[] exprTupleOrList) { + int count = 0; + String tempString = ""; + + for (exprType expr : exprTupleOrList) { + if (expr instanceof Num) { + if (count == 0) + tempString += ((Num) expr).num; + else + tempString += ", " + ((Num) expr).num; + count++; + } + if (expr instanceof Name) + tempString = ((Name) expr).id; + } + + return tempString; + + } + /** * True iff this {@link Function}'s {@link decoratorsType} has parameter autograph. * * @return True iff this {@link decoratorType} has parameter autograph. */ public boolean hasAutoGraphParam() { - return this.autoGraphParamExists; + return (this.autoGraphParamValue != null); + } /** @@ -305,7 +359,7 @@ public boolean hasAutoGraphParam() { * @return True iff this {@link decoratorType} has parameter experimental_autograph_options. */ public boolean hasExperimentalAutographOptParam() { - return this.experimentalAutographOptionsParamExists; + return (this.experimentalAutographOptionsParamValue != null); } /** @@ -314,7 +368,7 @@ public boolean hasExperimentalAutographOptParam() { * @return True iff this {@link decoratorType} has parameter experimental_implements. */ public boolean hasExperimentalImplementsParam() { - return this.experimentalImplementsParamExists; + return (this.experimentalImplementsParamValue != null); } /** @@ -323,7 +377,7 @@ public boolean hasExperimentalImplementsParam() { * @return True iff this {@link decoratorType} has parameter experimental_follow_type_hints. */ public boolean hasExperimentalFollowTypeHintsParam() { - return this.experimentaFollowTypeHintsParamExists; + return (this.experimentaFollowTypeHintsParamValue != null); } /** @@ -332,7 +386,7 @@ public boolean hasExperimentalFollowTypeHintsParam() { * @return True iff this {@link decoratorType} has parameter func. */ public boolean hasFuncParam() { - return this.funcParamExists; + return (this.funcParamValue != null); } /** @@ -341,7 +395,7 @@ public boolean hasFuncParam() { * @return True iff this {@link decoratorType} has parameter input_signature. */ public boolean hasInputSignatureParam() { - return this.inputSignatureParamExists; + return (this.inputSignatureParamValue != null); } /** @@ -350,7 +404,7 @@ public boolean hasInputSignatureParam() { * @return True iff this {@link decoratorType} has parameter jit_compile. */ public boolean hasJitCompileParam() { - return this.jitCompileParamExists; + return (this.jitCompileParamValue != null); } /** @@ -359,7 +413,7 @@ public boolean hasJitCompileParam() { * @return True iff this {@link Function} has parameter reduce_retracing. */ public boolean hasReduceRetracingParam() { - return this.reduceRetracingParamExists; + return (this.reduceRetracingParamValue != null); } /** diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index f4d807c27..1260de552 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -848,93 +848,93 @@ public void testDecoratorArguments() throws Exception { assertEquals("None", args.getInputSignatureArg()); } - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - // */ - // @Test - // public void testDecoratorArguments2() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - // } - - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - // */ - // @Test - // public void testDecoratorArguments3() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("tf.TensorSpec(shape=(2, 2), dtype=tf.float32),)", args.getInputSignatureArg()); - // } - - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - // */ - // @Test - // public void testDecoratorArguments4() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("[]", args.getInputSignatureArg()); - // } - - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument input_signature. - // */ - // @Test - // public void testDecoratorArguments5() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("[tf.TensorSpec([], tf.float32)]", args.getInputSignatureArg()); - // } + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments2() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments3() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("tf.TensorSpec(shape=(2, 2), dtype=tf.float32),)", args.getInputSignatureArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments4() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("[]", args.getInputSignatureArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments5() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("[tf.TensorSpec([], tf.float32)]", args.getInputSignatureArg()); + } /** * Test for #136. This simply tests whether we can get the tf.function argument autograph. @@ -1198,29 +1198,29 @@ public void testDecoratorArguments17() throws Exception { assertEquals("tf.autograph.experimental.Feature.ALL", args.getExperimentalAutographOptArg()); } - // /** - // * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options - // */ - // @Test - // public void testDecoratorArguments18() throws Exception { - // Set functions = this.getFunctions(); - // - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) - // assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", - // args.getExperimentalAutographOptArg()); - // } + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + */ + @Test + public void testDecoratorArguments18() throws Exception { + Set functions = this.getFunctions(); + + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", + args.getExperimentalAutographOptArg()); + } /** * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options @@ -1332,29 +1332,29 @@ public void testDecoratorArguments23() throws Exception { && args.getExperimentalAutographOptArg() == null && args.getExperimentalFollowTypeHintsArg() == null); } - // /** - // * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. - // */ - // @Test - // public void testDecoratorArguments24() throws Exception { - // Set functions = this.getFunctions(); - // assertNotNull(functions); - // assertEquals(1, functions.size()); - // Function function = functions.iterator().next(); - // assertNotNull(function); - // - // assertTrue(function.isHybrid()); - // - // Function.HybridizationParameters args = function.getHybridizationParameters(); - // assertNotNull(args); - // - // if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() - // && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - // && !args.hasExperimentalFollowTypeHintsParam()) { - // assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - // assertEquals("False", args.getAutoGraphArg()); - // } - // } + /** + * Test for #136. This simply tests whether we can get tf.function arguments when we have multiple. + */ + @Test + public void testDecoratorArguments24() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + assertEquals("False", args.getAutoGraphArg()); + } + } /** * Test for #136. Test custom decorator with the same parameter names as tf.function. From e12fb167488fa118effcd5fb52b29f968a9171d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 7 Feb 2023 15:51:33 -0500 Subject: [PATCH 25/70] Removing unnecessary else --- .../src/edu/cuny/hunter/hybridize/core/analysis/Function.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 48a3f686d..64b0c2f49 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -141,8 +141,7 @@ public void setDType(String d) { public String toString() { if (this.dtype.isEmpty() && this.shape.isEmpty()) return "tf.TensorSpec([])"; - else - return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; + return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; } } From 7aef65b26164a7ccf7925f7eef0ca9c938721574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 7 Feb 2023 22:17:36 -0500 Subject: [PATCH 26/70] Progress --- .../HybridizeFunction/testDecoratorArguments4/in/A.py | 11 +++++++---- .../tests/HybridizeFunctionRefactoringTest.java | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py index 4919ccd07..538aaf788 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py @@ -1,8 +1,11 @@ import tensorflow as tf -@tf.function(input_signature=[]) -def func(x): - return x + +@tf.function(input_signature=(tf.TensorSpec([]), tf.TensorSpec([]))) +def func_2(tensor, integer): + return tensor + integer + if __name__ == '__main__': - func(tf.constant(2.)) + input = tf.constant(0.0) + func_2(input, 2) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 1260de552..0b7ddeecb 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -889,7 +889,7 @@ public void testDecoratorArguments3() throws Exception { if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("tf.TensorSpec(shape=(2, 2), dtype=tf.float32),)", args.getInputSignatureArg()); + assertEquals("tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getInputSignatureArg()); } /** @@ -911,7 +911,7 @@ public void testDecoratorArguments4() throws Exception { if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("[]", args.getInputSignatureArg()); + assertEquals("(tf.TensorSpec([]), tf.TensorSpec([]))", args.getInputSignatureArg()); } /** From 9f49fea7f7562370bba093acb4e5cf7884d47be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 7 Feb 2023 22:26:10 -0500 Subject: [PATCH 27/70] Update --- .../hybridize/tests/HybridizeFunctionRefactoringTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 0b7ddeecb..f6e7ecf63 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -889,7 +889,7 @@ public void testDecoratorArguments3() throws Exception { if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getInputSignatureArg()); + assertEquals("(tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getInputSignatureArg()); } /** From 279089bc3aae84e28147746fee47d6551983e72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 8 Feb 2023 12:17:37 -0500 Subject: [PATCH 28/70] Progress --- .../hybridize/core/analysis/Function.java | 135 +++++++++++------- .../hybridize/core/analysis/TensorSpec.java | 56 ++++++++ 2 files changed, 139 insertions(+), 52 deletions(-) create mode 100644 edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 64b0c2f49..8766617ed 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -107,44 +107,6 @@ public class HybridizationParameters { */ private String reduceRetracingParamValue; - final class TensorSpec { - private String shape; - private String dtype; - - public TensorSpec() { - this.shape = ""; - this.dtype = ""; // Default value - } - - public TensorSpec(String s, String d) { - this.shape = s; - this.dtype = d; - } - - public String getShape() { - return this.shape; - } - - public String getDType() { - return this.dtype; - } - - public void setShape(String s) { - this.shape = s; - } - - public void setDType(String d) { - this.dtype = d; - } - - @Override - public String toString() { - if (this.dtype.isEmpty() && this.shape.isEmpty()) - return "tf.TensorSpec([])"; - return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; - } - } - public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); decoratorsType[] decoratorArray = functionDefinition.getFunctionDef().decs; @@ -199,13 +161,30 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } else if (keyword.value instanceof Tuple) { Tuple value = (Tuple) keyword.value; exprType[] valueElements = value.elts; - this.inputSignatureParamValue += "("; ArrayList tensorSpecList = new ArrayList<>(); for (exprType expr : valueElements) { if (expr instanceof Call) { Call callTuple = (Call) expr; - keywordType[] keywordsCall = callTuple.keywords; TensorSpec tensor = new TensorSpec(); + // Positional arguments + exprType[] tensorArgs = callTuple.args; + for (exprType tensorArg : tensorArgs) { + if (tensorArg instanceof Tuple) { + tensor.setShape(processTupleOrList(((Tuple) tensorArg).elts)); + tensor.setShapeKeyword(false); + } + if (tensorArg instanceof List) { + tensor.setShape(processTupleOrList(((List) tensorArg).elts)); + tensor.setShapeKeyword(false); + } + if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + tensor.setDTypeKeyword(false); + } + } + // Keyword arguments + keywordType[] keywordsCall = callTuple.keywords; for (keywordType kywrds : keywordsCall) { if (kywrds.value instanceof Tuple) tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); @@ -219,19 +198,49 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep tensorSpecList.add(tensor); } } - this.inputSignatureParamValue = "("; - int count = 0; - for (TensorSpec tensor : tensorSpecList) { - if (count == 0) - this.inputSignatureParamValue += tensor.toString(); - else - this.inputSignatureParamValue += ", " + tensor.toString(); - count++; + this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, value); + } else if (keyword.value instanceof List) { + List value = (List) keyword.value; + exprType[] valueElements = value.elts; + ArrayList tensorSpecList = new ArrayList<>(); + for (exprType expr : valueElements) { + if (expr instanceof Call) { + Call callTuple = (Call) expr; + TensorSpec tensor = new TensorSpec(); + + // Positional arguments + exprType[] tensorArgs = callTuple.args; + for (exprType tensorArg : tensorArgs) { + if (tensorArg instanceof Tuple) { + tensor.setShape(processTupleOrList(((Tuple) tensorArg).elts)); + tensor.setShapeKeyword(false); + } + if (tensorArg instanceof List) { + tensor.setShape(processTupleOrList(((List) tensorArg).elts)); + tensor.setShapeKeyword(false); + } + if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + tensor.setDTypeKeyword(false); + } + } + // Keyword Arguments + keywordType[] keywordsCall = callTuple.keywords; + for (keywordType kywrds : keywordsCall) { + if (kywrds.value instanceof Tuple) + tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); + if (kywrds.value instanceof List) + tensor.setShape(processTupleOrList(((List) kywrds.value).elts)); + if (kywrds.value instanceof Attribute) { + Attribute attrValue = (Attribute) kywrds.value; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } + } + tensorSpecList.add(tensor); + } } - if (value.endsWithComma) - this.inputSignatureParamValue += ",)"; - else - this.inputSignatureParamValue += ")"; + this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, null); } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } @@ -326,6 +335,7 @@ private String processTupleOrList(exprType[] exprTupleOrList) { int count = 0; String tempString = ""; + tempString = "("; for (exprType expr : exprTupleOrList) { if (expr instanceof Num) { if (count == 0) @@ -342,6 +352,27 @@ private String processTupleOrList(exprType[] exprTupleOrList) { } + private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList, Tuple value) { + String tempString = ""; + + tempString = "("; + int count = 0; + for (TensorSpec tensor : tensorSpecList) { + if (count == 0) + tempString += tensor.toString(); + else + tempString += ", " + tensor.toString(); + count++; + } + if (value.endsWithComma) + tempString += ",)"; + else + tempString += ")"; + + return tempString; + + } + /** * True iff this {@link Function}'s {@link decoratorsType} has parameter autograph. * diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java new file mode 100644 index 000000000..a8bf3147d --- /dev/null +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -0,0 +1,56 @@ +package edu.cuny.hunter.hybridize.core.analysis; + +public class TensorSpec { + private String shape; + private String dtype; + private boolean shapeKeyword; + private boolean dtypeKeyword; + + public TensorSpec() { + this.shape = ""; + this.dtype = ""; + this.shapeKeyword = true; + this.dtypeKeyword = true; + + } + + public TensorSpec(String s, String d) { + this.shape = s; + this.dtype = d; + } + + public String getShape() { + return this.shape; + } + + public String getDType() { + return this.dtype; + } + + public void setShape(String s) { + this.shape = s; + } + + public void setDType(String d) { + this.dtype = d; + } + + public void setShapeKeyword(boolean s) { + this.shapeKeyword = s; + } + + public void setDTypeKeyword(boolean d) { + this.dtypeKeyword = d; + } + + @Override + public String toString() { + if (this.dtype.isEmpty() && this.shape.isEmpty()) + return "tf.TensorSpec([])"; + if (!this.shapeKeyword && !this.dtypeKeyword) + return "tf.TensorSpec([" + this.shape + "]" + ", " + this.dtype + ")"; + if (!this.shapeKeyword && this.dtypeKeyword) + return "tf.TensorSpec([" + this.shape + "]" + ", dtype=" + this.dtype + ")"; + return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; + } +} \ No newline at end of file From ef5d5bb6ed063f276af914ac0fcfaedb691f570f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 8 Feb 2023 12:32:30 -0500 Subject: [PATCH 29/70] Progress --- .../cuny/hunter/hybridize/core/analysis/Function.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 8766617ed..e47dceb0c 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -198,7 +198,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep tensorSpecList.add(tensor); } } - this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, value); + this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, value.endsWithComma); } else if (keyword.value instanceof List) { List value = (List) keyword.value; exprType[] valueElements = value.elts; @@ -240,7 +240,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep tensorSpecList.add(tensor); } } - this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, null); + this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, false); } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } @@ -335,7 +335,6 @@ private String processTupleOrList(exprType[] exprTupleOrList) { int count = 0; String tempString = ""; - tempString = "("; for (exprType expr : exprTupleOrList) { if (expr instanceof Num) { if (count == 0) @@ -352,7 +351,7 @@ private String processTupleOrList(exprType[] exprTupleOrList) { } - private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList, Tuple value) { + private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList, boolean comma) { String tempString = ""; tempString = "("; @@ -364,7 +363,7 @@ private String createTupleOrListOfTensorSpec(ArrayList tensorSpecLis tempString += ", " + tensor.toString(); count++; } - if (value.endsWithComma) + if (comma) tempString += ",)"; else tempString += ")"; From 64bd2b625d92d673b23f809f9777d7a5ab9052dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 8 Feb 2023 15:16:16 -0500 Subject: [PATCH 30/70] progress --- .../hybridize/core/analysis/Function.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index e47dceb0c..ceb9a98ed 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -198,7 +198,13 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep tensorSpecList.add(tensor); } } - this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, value.endsWithComma); + this.inputSignatureParamValue = "(" + createTupleOrListOfTensorSpec(tensorSpecList); + + if (value.endsWithComma) + this.inputSignatureParamValue += ",)"; + else + this.inputSignatureParamValue += ")"; + } else if (keyword.value instanceof List) { List value = (List) keyword.value; exprType[] valueElements = value.elts; @@ -240,11 +246,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep tensorSpecList.add(tensor); } } - this.inputSignatureParamValue = createTupleOrListOfTensorSpec(tensorSpecList, false); + this.inputSignatureParamValue = "[" + createTupleOrListOfTensorSpec(tensorSpecList) + "]"; } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } - LOG.info(inputSignatureParamValue); } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph // Example of value: True, False @@ -351,10 +356,9 @@ private String processTupleOrList(exprType[] exprTupleOrList) { } - private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList, boolean comma) { + private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList) { String tempString = ""; - tempString = "("; int count = 0; for (TensorSpec tensor : tensorSpecList) { if (count == 0) @@ -363,13 +367,8 @@ private String createTupleOrListOfTensorSpec(ArrayList tensorSpecLis tempString += ", " + tensor.toString(); count++; } - if (comma) - tempString += ",)"; - else - tempString += ")"; return tempString; - } /** From f53e997a30b608cf31ae29b96a7e8ce1b5694bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 8 Feb 2023 16:06:26 -0500 Subject: [PATCH 31/70] Progress --- .../hybridize/core/analysis/Function.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index ceb9a98ed..8911a7241 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -300,18 +300,26 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { // Found parameter experimental_autograph_options - StringBuilder argument = new StringBuilder(); // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS if (keyword.value instanceof Attribute) { Attribute keywordAttribute = (Attribute) keyword.value; - while (keywordAttribute.value instanceof Attribute) { - NameTok valueAttribute = (NameTok) keywordAttribute.attr; - argument.insert(0, valueAttribute.id); - argument.insert(0, "."); - keywordAttribute = (Attribute) keywordAttribute.value; + this.experimentalAutographOptionsParamValue = processAttribute(keywordAttribute); + } else if (keyword.value instanceof Tuple) { + Tuple keywordTuple = (Tuple) keyword.value; + exprType[] keywordExpr = keywordTuple.elts; + String finalTuple = ""; + int count = 0; + for (exprType expr : keywordExpr) { + if (expr instanceof Attribute) { + Attribute keywordAttribute = (Attribute) expr; + if (count == 0) + finalTuple += processAttribute(keywordAttribute); + else + finalTuple += ", " + processAttribute(keywordAttribute); + } + count++; } - this.experimentalAutographOptionsParamValue = ((Name) keywordAttribute.value).id + "." - + ((NameTok) keywordAttribute.attr).id + argument.toString(); + this.experimentalAutographOptionsParamValue = "(" + finalTuple + ")"; // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -320,6 +328,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " arguments"); } + LOG.info(this.experimentalAutographOptionsParamValue); } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints // Example of value: True, False, None @@ -356,6 +365,20 @@ private String processTupleOrList(exprType[] exprTupleOrList) { } + private String processAttribute(Attribute keywordAttribute) { + StringBuilder argument = new StringBuilder(); + Attribute tempAttr = keywordAttribute; + + while (tempAttr.value instanceof Attribute) { + NameTok valueAttribute = (NameTok) tempAttr.attr; + argument.insert(0, valueAttribute.id); + argument.insert(0, "."); + tempAttr = (Attribute) tempAttr.value; + } + + return ((Name) tempAttr.value).id + "." + ((NameTok) tempAttr.attr).id + argument.toString(); + } + private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList) { String tempString = ""; From 1df7219e7cf34898b61a249b0e3316d458de02ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 8 Feb 2023 17:16:34 -0500 Subject: [PATCH 32/70] Cleanup --- .../hybridize/core/analysis/Function.java | 127 +++++++----------- .../testDecoratorArguments4/in/A.py | 4 +- 2 files changed, 48 insertions(+), 83 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 8911a7241..58f1f734d 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -150,9 +150,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature - LOG.info(keyword.value.toString()); - // TODO: Nested sequence of tf.TensorSpecs - // Example of value: None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; @@ -161,91 +158,16 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } else if (keyword.value instanceof Tuple) { Tuple value = (Tuple) keyword.value; exprType[] valueElements = value.elts; - ArrayList tensorSpecList = new ArrayList<>(); - for (exprType expr : valueElements) { - if (expr instanceof Call) { - Call callTuple = (Call) expr; - TensorSpec tensor = new TensorSpec(); - // Positional arguments - exprType[] tensorArgs = callTuple.args; - for (exprType tensorArg : tensorArgs) { - if (tensorArg instanceof Tuple) { - tensor.setShape(processTupleOrList(((Tuple) tensorArg).elts)); - tensor.setShapeKeyword(false); - } - if (tensorArg instanceof List) { - tensor.setShape(processTupleOrList(((List) tensorArg).elts)); - tensor.setShapeKeyword(false); - } - if (tensorArg instanceof Attribute) { - Attribute attrValue = (Attribute) tensorArg; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - tensor.setDTypeKeyword(false); - } - } - // Keyword arguments - keywordType[] keywordsCall = callTuple.keywords; - for (keywordType kywrds : keywordsCall) { - if (kywrds.value instanceof Tuple) - tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); - if (kywrds.value instanceof List) - tensor.setShape(processTupleOrList(((List) kywrds.value).elts)); - if (kywrds.value instanceof Attribute) { - Attribute attrValue = (Attribute) kywrds.value; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - } - } - tensorSpecList.add(tensor); - } - } + ArrayList tensorSpecList = processTensorSpecs(valueElements); this.inputSignatureParamValue = "(" + createTupleOrListOfTensorSpec(tensorSpecList); - if (value.endsWithComma) this.inputSignatureParamValue += ",)"; else this.inputSignatureParamValue += ")"; - } else if (keyword.value instanceof List) { List value = (List) keyword.value; exprType[] valueElements = value.elts; - ArrayList tensorSpecList = new ArrayList<>(); - for (exprType expr : valueElements) { - if (expr instanceof Call) { - Call callTuple = (Call) expr; - TensorSpec tensor = new TensorSpec(); - - // Positional arguments - exprType[] tensorArgs = callTuple.args; - for (exprType tensorArg : tensorArgs) { - if (tensorArg instanceof Tuple) { - tensor.setShape(processTupleOrList(((Tuple) tensorArg).elts)); - tensor.setShapeKeyword(false); - } - if (tensorArg instanceof List) { - tensor.setShape(processTupleOrList(((List) tensorArg).elts)); - tensor.setShapeKeyword(false); - } - if (tensorArg instanceof Attribute) { - Attribute attrValue = (Attribute) tensorArg; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - tensor.setDTypeKeyword(false); - } - } - // Keyword Arguments - keywordType[] keywordsCall = callTuple.keywords; - for (keywordType kywrds : keywordsCall) { - if (kywrds.value instanceof Tuple) - tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); - if (kywrds.value instanceof List) - tensor.setShape(processTupleOrList(((List) kywrds.value).elts)); - if (kywrds.value instanceof Attribute) { - Attribute attrValue = (Attribute) kywrds.value; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - } - } - tensorSpecList.add(tensor); - } - } + ArrayList tensorSpecList = processTensorSpecs(valueElements); this.inputSignatureParamValue = "[" + createTupleOrListOfTensorSpec(tensorSpecList) + "]"; } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); @@ -304,6 +226,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Attribute) { Attribute keywordAttribute = (Attribute) keyword.value; this.experimentalAutographOptionsParamValue = processAttribute(keywordAttribute); + // Example of value: (tf.autograph.experimental.Feature.EQUALITY_OPERATORS, + // tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS) } else if (keyword.value instanceof Tuple) { Tuple keywordTuple = (Tuple) keyword.value; exprType[] keywordExpr = keywordTuple.elts; @@ -328,7 +252,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " arguments"); } - LOG.info(this.experimentalAutographOptionsParamValue); } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints // Example of value: True, False, None @@ -379,6 +302,48 @@ private String processAttribute(Attribute keywordAttribute) { return ((Name) tempAttr.value).id + "." + ((NameTok) tempAttr.attr).id + argument.toString(); } + private ArrayList processTensorSpecs(exprType[] valueElements) { + ArrayList tensorSpecList = new ArrayList<>(); + for (exprType expr : valueElements) { + if (expr instanceof Call) { + Call callTuple = (Call) expr; + TensorSpec tensor = new TensorSpec(); + + // Positional arguments + exprType[] tensorArgs = callTuple.args; + for (exprType tensorArg : tensorArgs) { + if (tensorArg instanceof Tuple) { + tensor.setShape(processTupleOrList(((Tuple) tensorArg).elts)); + tensor.setShapeKeyword(false); + } + if (tensorArg instanceof List) { + tensor.setShape(processTupleOrList(((List) tensorArg).elts)); + tensor.setShapeKeyword(false); + } + if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + tensor.setDTypeKeyword(false); + } + } + // Keyword Arguments + keywordType[] keywordsCall = callTuple.keywords; + for (keywordType kywrds : keywordsCall) { + if (kywrds.value instanceof Tuple) + tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); + if (kywrds.value instanceof List) + tensor.setShape(processTupleOrList(((List) kywrds.value).elts)); + if (kywrds.value instanceof Attribute) { + Attribute attrValue = (Attribute) kywrds.value; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } + } + tensorSpecList.add(tensor); + } + } + return tensorSpecList; + } + private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList) { String tempString = ""; diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py index 538aaf788..285bdb91e 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py @@ -2,10 +2,10 @@ @tf.function(input_signature=(tf.TensorSpec([]), tf.TensorSpec([]))) -def func_2(tensor, integer): +def func(tensor, integer): return tensor + integer if __name__ == '__main__': input = tf.constant(0.0) - func_2(input, 2) + func(input, 2) From 1b2ac89db462cf576b3bc659c3b8166e533d9579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 11:17:56 -0500 Subject: [PATCH 33/70] making sure we are only checking literals --- .../hybridize/core/analysis/Function.java | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 58f1f734d..a06116d52 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -144,7 +144,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: Name of function or None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.funcParamValue = value.id; + if (value.id == "None") // Checking only literals + this.funcParamValue = value.id; + else + throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); } else { throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); } @@ -153,7 +156,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.inputSignatureParamValue = value.id; + if (value.id == "None") // Checking only literals + this.inputSignatureParamValue = value.id; + else + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); // Example: (tf.TensorSpec(shape=[None], dtype=tf.float32),) } else if (keyword.value instanceof Tuple) { Tuple value = (Tuple) keyword.value; @@ -177,7 +183,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.autoGraphParamValue = value.id; + if (value.id == "True" || value.id == "False") // Checking only literals + this.autoGraphParamValue = value.id; + else + throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); } else { throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); } @@ -189,7 +198,11 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.jitCompileParamValue = value.id; + if (value.id == "True" || value.id == "False" || value.id == "None") // Checking only literals + this.jitCompileParamValue = value.id; + else + throw new IllegalArgumentException( + "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); } else { throw new IllegalArgumentException( "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); @@ -202,7 +215,11 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.reduceRetracingParamValue = value.id; + if (value.id == "True" || value.id == "False") // Checking only literals + this.reduceRetracingParamValue = value.id; + else + throw new IllegalArgumentException( + "Unable to process " + REDUCE_RETRACING + "/" + EXPERIMENTAL_RELAX_SHAPES + " argument."); } else { throw new IllegalArgumentException( "Unable to process " + REDUCE_RETRACING + "/" + EXPERIMENTAL_RELAX_SHAPES + " argument."); @@ -216,7 +233,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.experimentalImplementsParamValue = value.id; + if (value.id == "None") // Checking only literals + this.experimentalImplementsParamValue = value.id; + else + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } else { throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } @@ -247,7 +267,11 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.experimentalAutographOptionsParamValue = value.id; + if (value.id == "None") // Checking only literals + this.experimentalAutographOptionsParamValue = value.id; + else + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); } else { throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " arguments"); @@ -257,7 +281,11 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - this.experimentaFollowTypeHintsParamValue = value.id; + if (value.id == "None" || value.id == "True" || value.id == "False") // Checking only literals + this.experimentaFollowTypeHintsParamValue = value.id; + else + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); } else { throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " arguments"); From c4184d4eaf4d67d9cc22f31f5f5299662dae596f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 11:28:12 -0500 Subject: [PATCH 34/70] Reorganization --- .../hunter/hybridize/core/analysis/Function.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index a06116d52..a92c5fbc1 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -170,6 +170,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.inputSignatureParamValue += ",)"; else this.inputSignatureParamValue += ")"; + // Example: [tf.TensorSpec(shape=[None], dtype=tf.float32)] } else if (keyword.value instanceof List) { List value = (List) keyword.value; exprType[] valueElements = value.elts; @@ -356,13 +357,13 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { } // Keyword Arguments keywordType[] keywordsCall = callTuple.keywords; - for (keywordType kywrds : keywordsCall) { - if (kywrds.value instanceof Tuple) - tensor.setShape(processTupleOrList(((Tuple) kywrds.value).elts)); - if (kywrds.value instanceof List) - tensor.setShape(processTupleOrList(((List) kywrds.value).elts)); - if (kywrds.value instanceof Attribute) { - Attribute attrValue = (Attribute) kywrds.value; + for (keywordType keyword : keywordsCall) { + if (keyword.value instanceof Tuple) + tensor.setShape(processTupleOrList(((Tuple) keyword.value).elts)); + if (keyword.value instanceof List) + tensor.setShape(processTupleOrList(((List) keyword.value).elts)); + if (keyword.value instanceof Attribute) { + Attribute attrValue = (Attribute) keyword.value; tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); } } From d2ae4c9ea89e41c28b6977b759e5e7ce23b4e6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 11:34:12 -0500 Subject: [PATCH 35/70] Renaming --- .../hybridize/core/analysis/Function.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index a92c5fbc1..63cbd2777 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -246,7 +246,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS if (keyword.value instanceof Attribute) { Attribute keywordAttribute = (Attribute) keyword.value; - this.experimentalAutographOptionsParamValue = processAttribute(keywordAttribute); + this.experimentalAutographOptionsParamValue = processAttributeForAutographOptions(keywordAttribute); // Example of value: (tf.autograph.experimental.Feature.EQUALITY_OPERATORS, // tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS) } else if (keyword.value instanceof Tuple) { @@ -258,9 +258,9 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (expr instanceof Attribute) { Attribute keywordAttribute = (Attribute) expr; if (count == 0) - finalTuple += processAttribute(keywordAttribute); + finalTuple += processAttributeForAutographOptions(keywordAttribute); else - finalTuple += ", " + processAttribute(keywordAttribute); + finalTuple += ", " + processAttributeForAutographOptions(keywordAttribute); } count++; } @@ -297,7 +297,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } // else, tf.function is used without parameters. } - private String processTupleOrList(exprType[] exprTupleOrList) { + private String processTupleOrListForShape(exprType[] exprTupleOrList) { int count = 0; String tempString = ""; @@ -309,15 +309,19 @@ private String processTupleOrList(exprType[] exprTupleOrList) { tempString += ", " + ((Num) expr).num; count++; } - if (expr instanceof Name) - tempString = ((Name) expr).id; + if (expr instanceof Name) { + if (((Name) expr).id == "None") // Checking only literals + tempString = ((Name) expr).id; + else + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } } return tempString; } - private String processAttribute(Attribute keywordAttribute) { + private String processAttributeForAutographOptions(Attribute keywordAttribute) { StringBuilder argument = new StringBuilder(); Attribute tempAttr = keywordAttribute; @@ -342,11 +346,11 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { exprType[] tensorArgs = callTuple.args; for (exprType tensorArg : tensorArgs) { if (tensorArg instanceof Tuple) { - tensor.setShape(processTupleOrList(((Tuple) tensorArg).elts)); + tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); tensor.setShapeKeyword(false); } if (tensorArg instanceof List) { - tensor.setShape(processTupleOrList(((List) tensorArg).elts)); + tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); tensor.setShapeKeyword(false); } if (tensorArg instanceof Attribute) { @@ -359,9 +363,9 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { keywordType[] keywordsCall = callTuple.keywords; for (keywordType keyword : keywordsCall) { if (keyword.value instanceof Tuple) - tensor.setShape(processTupleOrList(((Tuple) keyword.value).elts)); + tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); if (keyword.value instanceof List) - tensor.setShape(processTupleOrList(((List) keyword.value).elts)); + tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); if (keyword.value instanceof Attribute) { Attribute attrValue = (Attribute) keyword.value; tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); From b48960de38f32997a16d4ad3935f2a76b3ffff60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 11:54:17 -0500 Subject: [PATCH 36/70] Adding documentation --- .../hybridize/core/analysis/Function.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 63cbd2777..676e29ade 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -297,6 +297,11 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } // else, tf.function is used without parameters. } + /** + * Parses expressions to return a string of the shape of a TensorSpec for input signature. + * + * @return String of TensorSpec shape. + */ private String processTupleOrListForShape(exprType[] exprTupleOrList) { int count = 0; String tempString = ""; @@ -321,6 +326,11 @@ private String processTupleOrListForShape(exprType[] exprTupleOrList) { } + /** + * Parses attributes to return a string of the autograph options. + * + * @return String of autograph options that contains various attributes. + */ private String processAttributeForAutographOptions(Attribute keywordAttribute) { StringBuilder argument = new StringBuilder(); Attribute tempAttr = keywordAttribute; @@ -335,6 +345,11 @@ private String processAttributeForAutographOptions(Attribute keywordAttribute) { return ((Name) tempAttr.value).id + "." + ((NameTok) tempAttr.attr).id + argument.toString(); } + /** + * Parses expressions to retrieve information about the TensorSpecs for input signature. + * + * @return Array of TensorSpecs with the parsed information. + */ private ArrayList processTensorSpecs(exprType[] valueElements) { ArrayList tensorSpecList = new ArrayList<>(); for (exprType expr : valueElements) { @@ -372,11 +387,18 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { } } tensorSpecList.add(tensor); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } } return tensorSpecList; } + /** + * Gets the array of Tensorspecs and returns the tuple or list of them, if necessary. + * + * @return String of nested TensorSpecs. + */ private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList) { String tempString = ""; From 1eb72744082c017f653828cb4b2011077fe20cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 12:05:17 -0500 Subject: [PATCH 37/70] Adding a test where there should be an exception --- .../testDecoratorArguments28/in/A.py | 11 +++++++++ .../in/requirements.txt | 1 + .../HybridizeFunctionRefactoringTest.java | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/requirements.txt diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py new file mode 100644 index 000000000..c109431e6 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + +var = True + +@tf.function(jit_compile=var) +def func(x): + return x + + +if __name__ == '__main__': + func(tf.constant(1)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index f6e7ecf63..7a67fd90e 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1431,6 +1431,30 @@ public void testDecoratorArguments27() throws Exception { } } + + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments28() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("var", args.getJitCompileArg()); + } + + } /** * This simply tests whether we have the correct qualified name. From 9195db7fcf5acacdc02e9900c2cab2694a993c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 12:10:10 -0500 Subject: [PATCH 38/70] Formatting --- .../hybridize/tests/HybridizeFunctionRefactoringTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 7a67fd90e..279047575 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1431,7 +1431,7 @@ public void testDecoratorArguments27() throws Exception { } } - + /** * Test for #136. Tests non-literal value in the tf.function decorator argument. */ From eba973658898d8648c85f007b25403495744221d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 12:25:47 -0500 Subject: [PATCH 39/70] Test --- .../tests/HybridizeFunctionRefactoringTest.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 279047575..d6ed3db7d 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1438,22 +1438,6 @@ public void testDecoratorArguments27() throws Exception { @Test(expected = IllegalArgumentException.class) public void testDecoratorArguments28() throws Exception { Set functions = this.getFunctions(); - assertNotNull(functions); - assertEquals(1, functions.size()); - Function function = functions.iterator().next(); - assertNotNull(function); - - assertTrue(function.isHybrid()); - - Function.HybridizationParameters args = function.getHybridizationParameters(); - assertNotNull(args); - - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() - && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() - && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("var", args.getJitCompileArg()); - } - } /** From dd826115c43d5478b08c0b85e5012261620897de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 12:43:32 -0500 Subject: [PATCH 40/70] Revert "Test" This reverts commit eba973658898d8648c85f007b25403495744221d. --- .../tests/HybridizeFunctionRefactoringTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index d6ed3db7d..279047575 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1438,6 +1438,22 @@ public void testDecoratorArguments27() throws Exception { @Test(expected = IllegalArgumentException.class) public void testDecoratorArguments28() throws Exception { Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("var", args.getJitCompileArg()); + } + } /** From df9766472f4a0a1c773791a82f1e7f1da70e3093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 12:44:42 -0500 Subject: [PATCH 41/70] Update --- .../hybridize/tests/HybridizeFunctionRefactoringTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 279047575..03702aa33 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1433,7 +1433,8 @@ public void testDecoratorArguments27() throws Exception { } /** - * Test for #136. Tests non-literal value in the tf.function decorator argument. + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. */ @Test(expected = IllegalArgumentException.class) public void testDecoratorArguments28() throws Exception { @@ -1451,7 +1452,7 @@ public void testDecoratorArguments28() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("var", args.getJitCompileArg()); + assertEquals("True", args.getJitCompileArg()); } } From 54d78be7d1f795df255127e3b0b8acb0c8c92382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 13:05:16 -0500 Subject: [PATCH 42/70] Adding new tests --- .../hybridize/core/analysis/Function.java | 28 ++++++---- .../testDecoratorArguments29/.DS_Store | Bin 0 -> 6148 bytes .../testDecoratorArguments29/in/A.py | 13 +++++ .../in/requirements.txt | 1 + .../testDecoratorArguments30/.DS_Store | Bin 0 -> 6148 bytes .../testDecoratorArguments30/in/A.py | 13 +++++ .../in/requirements.txt | 1 + .../HybridizeFunctionRefactoringTest.java | 50 ++++++++++++++++++ 8 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/.DS_Store create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/.DS_Store create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/requirements.txt diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 676e29ade..b296dc57d 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -286,7 +286,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep this.experimentaFollowTypeHintsParamValue = value.id; else throw new IllegalArgumentException( - "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); + "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " argument."); } else { throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " arguments"); @@ -313,13 +313,13 @@ private String processTupleOrListForShape(exprType[] exprTupleOrList) { else tempString += ", " + ((Num) expr).num; count++; - } - if (expr instanceof Name) { + } else if (expr instanceof Name) { if (((Name) expr).id == "None") // Checking only literals tempString = ((Name) expr).id; else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - } + } else + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } return tempString; @@ -339,7 +339,10 @@ private String processAttributeForAutographOptions(Attribute keywordAttribute) { NameTok valueAttribute = (NameTok) tempAttr.attr; argument.insert(0, valueAttribute.id); argument.insert(0, "."); - tempAttr = (Attribute) tempAttr.value; + if (tempAttr.value instanceof Attribute) + tempAttr = (Attribute) tempAttr.value; + else + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); } return ((Name) tempAttr.value).id + "." + ((NameTok) tempAttr.attr).id + argument.toString(); @@ -363,27 +366,30 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { if (tensorArg instanceof Tuple) { tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); tensor.setShapeKeyword(false); - } - if (tensorArg instanceof List) { + } else if (tensorArg instanceof List) { tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); tensor.setShapeKeyword(false); - } - if (tensorArg instanceof Attribute) { + } else if (tensorArg instanceof Attribute) { Attribute attrValue = (Attribute) tensorArg; tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); tensor.setDTypeKeyword(false); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } + } // Keyword Arguments keywordType[] keywordsCall = callTuple.keywords; for (keywordType keyword : keywordsCall) { if (keyword.value instanceof Tuple) tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); - if (keyword.value instanceof List) + else if (keyword.value instanceof List) tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); - if (keyword.value instanceof Attribute) { + else if (keyword.value instanceof Attribute) { Attribute attrValue = (Attribute) keyword.value; tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } } tensorSpecList.add(tensor); diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/.DS_Store b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3c3e89ed3cf78d3a0695d6f9b7e8d5c8fcd17fd3 GIT binary patch literal 6148 zcmeHKQA@)x5Kgw~GKSCxg*^s*9XPisiZ7+kKVU^4RAx(u7HcBwW*^3&&-#b_CH@}o zk`$coSw!w2`R;OeN%KK-31f^0^JJefk1-~oA#zmK2oA4x)m$(l$2sCm$DqH*&spkx ze;x4KYb<3dF7oHE-=EKVy$@ciH#Rn#qAA+qHhj=UIE!ZUJcy>(XkBQX#g!h#m+7P! zd)ud4&7xFIrY0dxCJ=ISm8wJ+fu5@*H@Ts8h?Z!Lz0P7W92|9J|DeC@%EfWN*OkM; z;d0p$JG*-)=i|rhN$FQhCI_yKY&opp4HUDNmvE{wt?t3DVyhTJVt^PR28aP-z|{uP zCMt*lVt^R<#sHoV5*niKu(W874(RaujQ$293h4NjK$H%BhowdEfN+}%Xj8d+VsM)d z(XkBQX#g!h#m+7P! zd)ud4&7xFIrY0dxCJ=ISm8wJ+fu5@*H@Ts8h?Z!Lz0P7W92|9J|DeC@%EfWN*OkM; z;d0p$JG*-)=i|rhN$FQhCI_yKY&opp4HUDNmvE{wt?t3DVyhTJVt^PR28aP-z|{uP zCMt*lVt^R<#sHoV5*niKu(W874(RaujQ$293h4NjK$H%BhowdEfN+}%Xj8d+VsM)d z functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getJitCompileArg()); + } + + } + + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments30() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("True", args.getJitCompileArg()); + } + + } + /** * This simply tests whether we have the correct qualified name. */ From 10cb16b1283d7ae6598ece7dc481ddd90248b7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 15:36:53 -0500 Subject: [PATCH 43/70] Removing unnecesary files, and adding new line --- .../testDecoratorArguments29/.DS_Store | Bin 6148 -> 0 bytes .../testDecoratorArguments30/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/.DS_Store delete mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/.DS_Store diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/.DS_Store b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/.DS_Store deleted file mode 100644 index 3c3e89ed3cf78d3a0695d6f9b7e8d5c8fcd17fd3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKQA@)x5Kgw~GKSCxg*^s*9XPisiZ7+kKVU^4RAx(u7HcBwW*^3&&-#b_CH@}o zk`$coSw!w2`R;OeN%KK-31f^0^JJefk1-~oA#zmK2oA4x)m$(l$2sCm$DqH*&spkx ze;x4KYb<3dF7oHE-=EKVy$@ciH#Rn#qAA+qHhj=UIE!ZUJcy>(XkBQX#g!h#m+7P! zd)ud4&7xFIrY0dxCJ=ISm8wJ+fu5@*H@Ts8h?Z!Lz0P7W92|9J|DeC@%EfWN*OkM; z;d0p$JG*-)=i|rhN$FQhCI_yKY&opp4HUDNmvE{wt?t3DVyhTJVt^PR28aP-z|{uP zCMt*lVt^R<#sHoV5*niKu(W874(RaujQ$293h4NjK$H%BhowdEfN+}%Xj8d+VsM)d z(XkBQX#g!h#m+7P! zd)ud4&7xFIrY0dxCJ=ISm8wJ+fu5@*H@Ts8h?Z!Lz0P7W92|9J|DeC@%EfWN*OkM; z;d0p$JG*-)=i|rhN$FQhCI_yKY&opp4HUDNmvE{wt?t3DVyhTJVt^PR28aP-z|{uP zCMt*lVt^R<#sHoV5*niKu(W874(RaujQ$293h4NjK$H%BhowdEfN+}%Xj8d+VsM)d z Date: Fri, 10 Feb 2023 15:38:59 -0500 Subject: [PATCH 44/70] Adding newline --- .../src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index a8bf3147d..0b511e7c2 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -53,4 +53,4 @@ public String toString() { return "tf.TensorSpec([" + this.shape + "]" + ", dtype=" + this.dtype + ")"; return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; } -} \ No newline at end of file +} From fc90f504d16923bfd89e146c8a58ad14271bf409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Feb 2023 16:35:12 -0500 Subject: [PATCH 45/70] Update --- .../hybridize/tests/HybridizeFunctionRefactoringTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 8aa69e9b8..3878a32e8 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1502,7 +1502,7 @@ public void testDecoratorArguments30() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("True", args.getJitCompileArg()); + assertEquals("(tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getJitCompileArg()); } } From ecffbc587755a16ca37e6209fc0f87fd6969aa0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 13 Feb 2023 22:54:26 -0500 Subject: [PATCH 46/70] Adding more tests --- .../testDecoratorArguments28/in/A.py | 8 +- .../testDecoratorArguments29/in/A.py | 6 +- .../testDecoratorArguments30/in/A.py | 8 +- .../testDecoratorArguments31/in/A.py | 11 ++ .../in/requirements.txt | 1 + .../testDecoratorArguments32/in/A.py | 11 ++ .../in/requirements.txt | 1 + .../testDecoratorArguments33/in/A.py | 12 ++ .../in/requirements.txt | 1 + .../testDecoratorArguments34/in/A.py | 12 ++ .../in/requirements.txt | 1 + .../testDecoratorArguments35/in/A.py | 11 ++ .../in/requirements.txt | 1 + .../HybridizeFunctionRefactoringTest.java | 128 +++++++++++++++++- 14 files changed, 197 insertions(+), 15 deletions(-) create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/requirements.txt create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/requirements.txt diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py index c109431e6..f03f6d91f 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py @@ -1,11 +1,13 @@ import tensorflow as tf -var = True +var = (tf.TensorSpec(shape=[None], dtype=tf.float32),) -@tf.function(jit_compile=var) + +@tf.function(input_signature=var) def func(x): return x if __name__ == '__main__': - func(tf.constant(1)) + number = tf.constant([1.0, 1.0]) + func(number) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py index f03f6d91f..9dc80af51 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py @@ -1,13 +1,13 @@ import tensorflow as tf -var = (tf.TensorSpec(shape=[None], dtype=tf.float32),) +var = (2, 2) -@tf.function(input_signature=var) +@tf.function(input_signature=(tf.TensorSpec(shape=var, dtype=tf.float32),)) def func(x): return x if __name__ == '__main__': - number = tf.constant([1.0, 1.0]) + number = tf.constant(([1.0, 1.0], [2.0, 2.0])) func(number) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py index 9dc80af51..9ec26538d 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py @@ -1,13 +1,11 @@ import tensorflow as tf -var = (2, 2) +var = False - -@tf.function(input_signature=(tf.TensorSpec(shape=var, dtype=tf.float32),)) +@tf.function(autograph=var) def func(x): return x if __name__ == '__main__': - number = tf.constant(([1.0, 1.0], [2.0, 2.0])) - func(number) + func(tf.constant(1)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/A.py new file mode 100644 index 000000000..4b1acf378 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + +var = False + +@tf.function(jit_compile=var) +def func(x): + return x + + +if __name__ == '__main__': + func(tf.constant(1)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments31/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/A.py new file mode 100644 index 000000000..18f7354fb --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + +var = False + +@tf.function(reduce_retracing=var) +def func(x): + return x + + +if __name__ == '__main__': + func(tf.constant(1)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments32/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/A.py new file mode 100644 index 000000000..14d52c436 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/A.py @@ -0,0 +1,12 @@ +import tensorflow as tf + +var = "embedded_matmul" + + +@tf.function(experimental_implements=var) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments33/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/A.py new file mode 100644 index 000000000..c6f58a6a7 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/A.py @@ -0,0 +1,12 @@ +import tensorflow as tf + +var = (tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS) + + +@tf.function(experimental_autograph_options=var) +def func(): + pass + + +if __name__ == '__main__': + func() diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments34/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py new file mode 100644 index 000000000..03e5168fc --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + +var = False + +@tf.function(experimental_follow_type_hints=var) +def func(): + pass + + +if __name__ == '__main__': + func() \ No newline at end of file diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/requirements.txt new file mode 100644 index 000000000..b154f958f --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 3878a32e8..b6d526e57 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1449,10 +1449,10 @@ public void testDecoratorArguments28() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("True", args.getJitCompileArg()); + assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getJitCompileArg()); } } @@ -1477,7 +1477,7 @@ public void testDecoratorArguments29() throws Exception { if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getJitCompileArg()); + assertEquals("(tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getJitCompileArg()); } } @@ -1499,12 +1499,132 @@ public void testDecoratorArguments30() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("False", args.getAutoGraphArg()); + } + } + + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments31() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getJitCompileArg()); + assertEquals("False", args.getJitCompileArg()); + } + } + + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments32() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("False", args.getReduceRetracingArg()); + } + } + + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments33() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("embedded_matmul", args.getExperimentalImplementsArg()); } + } + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments34() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", + args.getExperimentalAutographOptArg()); + } + } + + /** + * Test for #136. Tests non-literal value in the tf.function decorator argument. We can remove the expected exception once we don't + * check for literals only. + */ + @Test(expected = IllegalArgumentException.class) + public void testDecoratorArguments35() throws Exception { + Set functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && args.hasExperimentalFollowTypeHintsParam()) { + assertEquals("True", args.getExperimentalFollowTypeHintsArg()); + } } /** From 3577a3935996c99a1e83b62d303a2ab238c88b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 13 Feb 2023 22:58:12 -0500 Subject: [PATCH 47/70] Trailing whitespace fix --- .../HybridizeFunction/testDecoratorArguments35/in/A.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py index 03e5168fc..a4f493ffe 100644 --- a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments35/in/A.py @@ -1,6 +1,6 @@ import tensorflow as tf -var = False +var = False @tf.function(experimental_follow_type_hints=var) def func(): From 0c72e7de802d2c104f06182d9a6f199c48fd2e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 14 Feb 2023 12:20:34 -0500 Subject: [PATCH 48/70] Adding comments --- .../hybridize/core/analysis/Function.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index b296dc57d..7b734015f 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -68,42 +68,47 @@ public class HybridizationParameters { private static final String FUNC = "func"; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. + * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. The values could be True or False. */ private String autoGraphParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. + * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. The values could be None, False + * or True. */ private String experimentaFollowTypeHintsParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. + * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. The values could be an optional + * tuple or value of tf.autograph.experimental.Feature values or None. */ private String experimentalAutographOptionsParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. + * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. The value could be None or a name of a + * "known" function this implements. */ private String experimentalImplementsParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter func. + * Value of this {@link Function}'s {@link decoratorsType} parameter func. The value could be None, or the function name to be + * compiled. */ private String funcParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. + * Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. The value could be None, or a possibly nested + * sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function */ private String inputSignatureParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. + * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. The values could be None, False or True. */ private String jitCompileParamValue; /** - * Value of this {@link Function}'s {@link decoratorsType} has parameter reduce_retracing. + * Value of this {@link Function}'s {@link decoratorsType} has parameter reduce_retracing. The values could be False or True. */ private String reduceRetracingParamValue; @@ -360,7 +365,7 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { Call callTuple = (Call) expr; TensorSpec tensor = new TensorSpec(); - // Positional arguments + // Positional arguments for TensorSpecs exprType[] tensorArgs = callTuple.args; for (exprType tensorArg : tensorArgs) { if (tensorArg instanceof Tuple) { @@ -378,7 +383,7 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { } } - // Keyword Arguments + // Keyword Arguments for TensorSpecs keywordType[] keywordsCall = callTuple.keywords; for (keywordType keyword : keywordsCall) { if (keyword.value instanceof Tuple) From 94733e63c24a0cab4ab2b99ea5e33519af3f150a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Tue, 14 Feb 2023 17:54:31 -0500 Subject: [PATCH 49/70] Make sure we are dealing with TensorSpec (input_signature) --- .../hybridize/core/analysis/Function.java | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 7b734015f..3b4600f24 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -363,41 +363,46 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { for (exprType expr : valueElements) { if (expr instanceof Call) { Call callTuple = (Call) expr; - TensorSpec tensor = new TensorSpec(); - - // Positional arguments for TensorSpecs - exprType[] tensorArgs = callTuple.args; - for (exprType tensorArg : tensorArgs) { - if (tensorArg instanceof Tuple) { - tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof List) { - tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof Attribute) { - Attribute attrValue = (Attribute) tensorArg; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - tensor.setDTypeKeyword(false); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - } - } - // Keyword Arguments for TensorSpecs - keywordType[] keywordsCall = callTuple.keywords; - for (keywordType keyword : keywordsCall) { - if (keyword.value instanceof Tuple) - tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); - else if (keyword.value instanceof List) - tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); - else if (keyword.value instanceof Attribute) { - Attribute attrValue = (Attribute) keyword.value; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + if (((NameTok) ((Attribute) callTuple.func).attr).id.equals("TensorSpec")) { + TensorSpec tensor = new TensorSpec(); + + // Positional arguments for TensorSpecs + exprType[] tensorArgs = callTuple.args; + for (exprType tensorArg : tensorArgs) { + if (tensorArg instanceof Tuple) { + tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); + tensor.setShapeKeyword(false); + } else if (tensorArg instanceof List) { + tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); + tensor.setShapeKeyword(false); + } else if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + tensor.setDTypeKeyword(false); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } + // Keyword Arguments for TensorSpecs + keywordType[] keywordsCall = callTuple.keywords; + for (keywordType keyword : keywordsCall) { + if (keyword.value instanceof Tuple) + tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); + else if (keyword.value instanceof List) + tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); + else if (keyword.value instanceof Attribute) { + Attribute attrValue = (Attribute) keyword.value; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } + tensorSpecList.add(tensor); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } - tensorSpecList.add(tensor); } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } From 41bfe8de3c378bd59f04e7c55f057588db9f213c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 15 Feb 2023 10:36:35 -0500 Subject: [PATCH 50/70] Revert "Make sure we are dealing with TensorSpec (input_signature)" This reverts commit 94733e63c24a0cab4ab2b99ea5e33519af3f150a. --- .../hybridize/core/analysis/Function.java | 69 +++++++++---------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 3b4600f24..7b734015f 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -363,46 +363,41 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { for (exprType expr : valueElements) { if (expr instanceof Call) { Call callTuple = (Call) expr; - - if (((NameTok) ((Attribute) callTuple.func).attr).id.equals("TensorSpec")) { - TensorSpec tensor = new TensorSpec(); - - // Positional arguments for TensorSpecs - exprType[] tensorArgs = callTuple.args; - for (exprType tensorArg : tensorArgs) { - if (tensorArg instanceof Tuple) { - tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof List) { - tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof Attribute) { - Attribute attrValue = (Attribute) tensorArg; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - tensor.setDTypeKeyword(false); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - } - + TensorSpec tensor = new TensorSpec(); + + // Positional arguments for TensorSpecs + exprType[] tensorArgs = callTuple.args; + for (exprType tensorArg : tensorArgs) { + if (tensorArg instanceof Tuple) { + tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); + tensor.setShapeKeyword(false); + } else if (tensorArg instanceof List) { + tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); + tensor.setShapeKeyword(false); + } else if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + tensor.setDTypeKeyword(false); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } - // Keyword Arguments for TensorSpecs - keywordType[] keywordsCall = callTuple.keywords; - for (keywordType keyword : keywordsCall) { - if (keyword.value instanceof Tuple) - tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); - else if (keyword.value instanceof List) - tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); - else if (keyword.value instanceof Attribute) { - Attribute attrValue = (Attribute) keyword.value; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - } + + } + // Keyword Arguments for TensorSpecs + keywordType[] keywordsCall = callTuple.keywords; + for (keywordType keyword : keywordsCall) { + if (keyword.value instanceof Tuple) + tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); + else if (keyword.value instanceof List) + tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); + else if (keyword.value instanceof Attribute) { + Attribute attrValue = (Attribute) keyword.value; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } - tensorSpecList.add(tensor); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } + tensorSpecList.add(tensor); } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } From 90036393a728a73e5fe98efc480e1aa557f2cda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 24 Feb 2023 13:14:07 -0500 Subject: [PATCH 51/70] Revert "Revert "Make sure we are dealing with TensorSpec (input_signature)"" This reverts commit 41bfe8de3c378bd59f04e7c55f057588db9f213c. --- .../hybridize/core/analysis/Function.java | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 7b734015f..3b4600f24 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -363,41 +363,46 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { for (exprType expr : valueElements) { if (expr instanceof Call) { Call callTuple = (Call) expr; - TensorSpec tensor = new TensorSpec(); - - // Positional arguments for TensorSpecs - exprType[] tensorArgs = callTuple.args; - for (exprType tensorArg : tensorArgs) { - if (tensorArg instanceof Tuple) { - tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof List) { - tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof Attribute) { - Attribute attrValue = (Attribute) tensorArg; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - tensor.setDTypeKeyword(false); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - } - } - // Keyword Arguments for TensorSpecs - keywordType[] keywordsCall = callTuple.keywords; - for (keywordType keyword : keywordsCall) { - if (keyword.value instanceof Tuple) - tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); - else if (keyword.value instanceof List) - tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); - else if (keyword.value instanceof Attribute) { - Attribute attrValue = (Attribute) keyword.value; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - } else { - throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + if (((NameTok) ((Attribute) callTuple.func).attr).id.equals("TensorSpec")) { + TensorSpec tensor = new TensorSpec(); + + // Positional arguments for TensorSpecs + exprType[] tensorArgs = callTuple.args; + for (exprType tensorArg : tensorArgs) { + if (tensorArg instanceof Tuple) { + tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); + tensor.setShapeKeyword(false); + } else if (tensorArg instanceof List) { + tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); + tensor.setShapeKeyword(false); + } else if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + tensor.setDTypeKeyword(false); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } + // Keyword Arguments for TensorSpecs + keywordType[] keywordsCall = callTuple.keywords; + for (keywordType keyword : keywordsCall) { + if (keyword.value instanceof Tuple) + tensor.setShape(processTupleOrListForShape(((Tuple) keyword.value).elts)); + else if (keyword.value instanceof List) + tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); + else if (keyword.value instanceof Attribute) { + Attribute attrValue = (Attribute) keyword.value; + tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } + tensorSpecList.add(tensor); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } - tensorSpecList.add(tensor); } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } From 6fd42b2d666baa3f898c2f5c04f6399844d78efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 24 Feb 2023 13:15:11 -0500 Subject: [PATCH 52/70] Fix build --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 939927e8a..7d7dbbd8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,9 @@ before_install: - sudo update-alternatives --auto python3 - sudo apt install -y python3.10-distutils - curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 + - export PATH=`echo $PATH | tr ":" "\n" | grep -v "/opt/pyenv/shims" | tr "\n" ":"` + - export PATH=`echo $PATH | tr ":" "\n" | grep -v "/home/travis/.phpenv/shims" | tr "\n" ":"` + - PATH="$PATH:/usr/bin/python3" services: - xvfb install: From 1682088e82194727731746098d89b4f9f82602bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Sun, 26 Feb 2023 20:23:26 -0500 Subject: [PATCH 53/70] Adding comments --- .../hybridize/core/analysis/TensorSpec.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index 0b511e7c2..099b41ed8 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -1,9 +1,28 @@ package edu.cuny.hunter.hybridize.core.analysis; +/** + * A representation of a tf.Tensorspec which describes a tf.Tensor + */ public class TensorSpec { + + /** + * Shape of the tensor being described by {@link TensorSpec}. + */ private String shape; + + /** + * Type of the tensor being described by {@link TensorSpec}. + */ private String dtype; + + /** + * True if the {@link TensorSpec} is using keyword arguments for the shape. + */ private boolean shapeKeyword; + + /** + * True if the {@link TensorSpec} is using keyword arguments for the type. + */ private boolean dtypeKeyword; public TensorSpec() { From ece25223f353a942afba4ac437c8c2ff34bcec3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 6 Mar 2023 13:07:08 -0500 Subject: [PATCH 54/70] Update --- .../hybridize/core/analysis/Function.java | 4 ++-- .../hybridize/core/analysis/TensorSpec.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 3b4600f24..cd98d99d5 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -468,7 +468,7 @@ public boolean hasExperimentalFollowTypeHintsParam() { } /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter has parameter func. + * True iff this {@link Function}'s {@link decoratorsType} has parameter func. * * @return True iff this {@link decoratorType} has parameter func. */ @@ -540,7 +540,7 @@ public String getExperimentalFollowTypeHintsArg() { } /** - * Value of {@link Function}'s {@link decoratorsType} parameter has parameter func. + * Value of {@link Function}'s {@link decoratorsType} parameter func. * * @return String of this {@link decoratorType} parameter func. */ diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index 099b41ed8..4434c98f7 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -38,26 +38,48 @@ public TensorSpec(String s, String d) { this.dtype = d; } + /** + * Shape of {@link TensorSpec}. + * + * @return String of this {@link TensorSpec} shape. + */ public String getShape() { return this.shape; } + /** + * Dtype of {@link TensorSpec}. + * + * @return String of this {@link TensorSpec} dtype. + */ public String getDType() { return this.dtype; } + /** + * Set shape of {@link TensorSpec}. + */ public void setShape(String s) { this.shape = s; } + /** + * Set dtype of {@link TensorSpec}. + */ public void setDType(String d) { this.dtype = d; } + /** + * Set if the type of the argument for shape of {@link TensorSpec} is a keyword. + */ public void setShapeKeyword(boolean s) { this.shapeKeyword = s; } + /** + * Set if the type of the argument for dtype of {@link TensorSpec} is a keyword. + */ public void setDTypeKeyword(boolean d) { this.dtypeKeyword = d; } From 93f4e9cba344cffe9e88e4019130ef8406de8a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 9 Mar 2023 16:34:49 -0500 Subject: [PATCH 55/70] Restructuring --- .../hybridize/core/analysis/Function.java | 153 +++++++++--------- 1 file changed, 72 insertions(+), 81 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index cd98d99d5..e85da01e6 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -70,47 +70,47 @@ public class HybridizationParameters { /** * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. The values could be True or False. */ - private String autoGraphParamValue; + private boolean autoGraphParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. The values could be None, False * or True. */ - private String experimentaFollowTypeHintsParamValue; + private Boolean experimentaFollowTypeHintsParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. The values could be an optional * tuple or value of tf.autograph.experimental.Feature values or None. */ - private String experimentalAutographOptionsParamValue; + private String experimentalAutographOptionsParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. The value could be None or a name of a * "known" function this implements. */ - private String experimentalImplementsParamValue; + private String experimentalImplementsParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter func. The value could be None, or the function name to be * compiled. */ - private String funcParamValue; + private String funcParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. The value could be None, or a possibly nested * sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function */ - private String inputSignatureParamValue; + private ArrayList inputSignatureParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. The values could be None, False or True. */ - private String jitCompileParamValue; + private Boolean jitCompileParam; /** * Value of this {@link Function}'s {@link decoratorsType} has parameter reduce_retracing. The values could be False or True. */ - private String reduceRetracingParamValue; + private boolean reduceRetracingParam; public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); @@ -150,7 +150,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.funcParamValue = value.id; + this.funcParam = value.id; else throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); } else { @@ -162,7 +162,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.inputSignatureParamValue = value.id; + this.inputSignatureParam = null; else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); // Example: (tf.TensorSpec(shape=[None], dtype=tf.float32),) @@ -170,17 +170,13 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep Tuple value = (Tuple) keyword.value; exprType[] valueElements = value.elts; ArrayList tensorSpecList = processTensorSpecs(valueElements); - this.inputSignatureParamValue = "(" + createTupleOrListOfTensorSpec(tensorSpecList); - if (value.endsWithComma) - this.inputSignatureParamValue += ",)"; - else - this.inputSignatureParamValue += ")"; + this.inputSignatureParam = tensorSpecList; // Example: [tf.TensorSpec(shape=[None], dtype=tf.float32)] } else if (keyword.value instanceof List) { List value = (List) keyword.value; exprType[] valueElements = value.elts; ArrayList tensorSpecList = processTensorSpecs(valueElements); - this.inputSignatureParamValue = "[" + createTupleOrListOfTensorSpec(tensorSpecList) + "]"; + this.inputSignatureParam = tensorSpecList; } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } @@ -189,8 +185,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "True" || value.id == "False") // Checking only literals - this.autoGraphParamValue = value.id; + if (value.id == "True")// Checking only literals + this.autoGraphParam = true; + else if (value.id == "False") + this.autoGraphParam = false; else throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); } else { @@ -204,8 +202,12 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "True" || value.id == "False" || value.id == "None") // Checking only literals - this.jitCompileParamValue = value.id; + if (value.id == "True") // Checking only literals + this.jitCompileParam = true; + else if (value.id == "False") + this.jitCompileParam = false; + else if (value.id == "None") + this.jitCompileParam = null; else throw new IllegalArgumentException( "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); @@ -221,8 +223,10 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "True" || value.id == "False") // Checking only literals - this.reduceRetracingParamValue = value.id; + if (value.id == "True") // Checking only literals + this.reduceRetracingParam = true; + else if (value.id == "False") // Checking only literals + this.reduceRetracingParam = false; else throw new IllegalArgumentException( "Unable to process " + REDUCE_RETRACING + "/" + EXPERIMENTAL_RELAX_SHAPES + " argument."); @@ -235,12 +239,12 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: "google.matmul_low_rank_matrix" if (keyword.value instanceof Str) { Str value = (Str) keyword.value; - this.experimentalImplementsParamValue = value.s; + this.experimentalImplementsParam = value.s; // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.experimentalImplementsParamValue = value.id; + this.experimentalImplementsParam = value.id; else throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } else { @@ -251,7 +255,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS if (keyword.value instanceof Attribute) { Attribute keywordAttribute = (Attribute) keyword.value; - this.experimentalAutographOptionsParamValue = processAttributeForAutographOptions(keywordAttribute); + this.experimentalAutographOptionsParam = processAttributeForAutographOptions(keywordAttribute); // Example of value: (tf.autograph.experimental.Feature.EQUALITY_OPERATORS, // tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS) } else if (keyword.value instanceof Tuple) { @@ -269,12 +273,12 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } count++; } - this.experimentalAutographOptionsParamValue = "(" + finalTuple + ")"; + this.experimentalAutographOptionsParam = "(" + finalTuple + ")"; // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.experimentalAutographOptionsParamValue = value.id; + this.experimentalAutographOptionsParam = value.id; else throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); @@ -287,8 +291,12 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "None" || value.id == "True" || value.id == "False") // Checking only literals - this.experimentaFollowTypeHintsParamValue = value.id; + if (value.id == "None") // Checking only literals + this.experimentaFollowTypeHintsParam = null; + else if (value.id == "True") // Checking only literals + this.experimentaFollowTypeHintsParam = true; + else if (value.id == "False") // Checking only literals + this.experimentaFollowTypeHintsParam = false; else throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " argument."); @@ -410,33 +418,14 @@ else if (keyword.value instanceof Attribute) { return tensorSpecList; } - /** - * Gets the array of Tensorspecs and returns the tuple or list of them, if necessary. - * - * @return String of nested TensorSpecs. - */ - private String createTupleOrListOfTensorSpec(ArrayList tensorSpecList) { - String tempString = ""; - - int count = 0; - for (TensorSpec tensor : tensorSpecList) { - if (count == 0) - tempString += tensor.toString(); - else - tempString += ", " + tensor.toString(); - count++; - } - - return tempString; - } - /** * True iff this {@link Function}'s {@link decoratorsType} has parameter autograph. * * @return True iff this {@link decoratorType} has parameter autograph. */ public boolean hasAutoGraphParam() { - return (this.autoGraphParamValue != null); + // False is the default value + return (this.autoGraphParam != false); } @@ -446,7 +435,7 @@ public boolean hasAutoGraphParam() { * @return True iff this {@link decoratorType} has parameter experimental_autograph_options. */ public boolean hasExperimentalAutographOptParam() { - return (this.experimentalAutographOptionsParamValue != null); + return (this.experimentalAutographOptionsParam != null); } /** @@ -455,7 +444,7 @@ public boolean hasExperimentalAutographOptParam() { * @return True iff this {@link decoratorType} has parameter experimental_implements. */ public boolean hasExperimentalImplementsParam() { - return (this.experimentalImplementsParamValue != null); + return (this.experimentalImplementsParam != null); } /** @@ -464,7 +453,7 @@ public boolean hasExperimentalImplementsParam() { * @return True iff this {@link decoratorType} has parameter experimental_follow_type_hints. */ public boolean hasExperimentalFollowTypeHintsParam() { - return (this.experimentaFollowTypeHintsParamValue != null); + return (this.experimentaFollowTypeHintsParam != null); } /** @@ -473,7 +462,7 @@ public boolean hasExperimentalFollowTypeHintsParam() { * @return True iff this {@link decoratorType} has parameter func. */ public boolean hasFuncParam() { - return (this.funcParamValue != null); + return (this.funcParam != null); } /** @@ -482,7 +471,7 @@ public boolean hasFuncParam() { * @return True iff this {@link decoratorType} has parameter input_signature. */ public boolean hasInputSignatureParam() { - return (this.inputSignatureParamValue != null); + return (this.inputSignatureParam != null); } /** @@ -491,7 +480,8 @@ public boolean hasInputSignatureParam() { * @return True iff this {@link decoratorType} has parameter jit_compile. */ public boolean hasJitCompileParam() { - return (this.jitCompileParamValue != null); + // None is the default value + return (this.jitCompileParam != null); } /** @@ -500,16 +490,17 @@ public boolean hasJitCompileParam() { * @return True iff this {@link Function} has parameter reduce_retracing. */ public boolean hasReduceRetracingParam() { - return (this.reduceRetracingParamValue != null); + // False is the default value + return (this.reduceRetracingParam != false); } /** * Value of {@link Function}'s {@link decoratorsType} parameter autograph. * - * @return String of this {@link decoratorType} parameter autograph. + * @return boolean of this {@link decoratorType} parameter autograph. */ - public String getAutoGraphArg() { - return this.autoGraphParamValue; + public boolean getAutoGraphArg() { + return this.autoGraphParam; } /** @@ -518,7 +509,7 @@ public String getAutoGraphArg() { * @return String of this {@link decoratorType} parameter experimental_autograph_options. */ public String getExperimentalAutographOptArg() { - return this.experimentalAutographOptionsParamValue; + return this.experimentalAutographOptionsParam; } /** @@ -527,16 +518,16 @@ public String getExperimentalAutographOptArg() { * @return String of this {@link decoratorType} parameter experimental_implements. */ public String getExperimentalImplementsArg() { - return this.experimentalImplementsParamValue; + return this.experimentalImplementsParam; } /** * Value of {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. * - * @return String of this {@link decoratorType} parameter experimental_follow_type_hints. + * @return Boolean of this {@link decoratorType} parameter experimental_follow_type_hints. */ - public String getExperimentalFollowTypeHintsArg() { - return this.experimentaFollowTypeHintsParamValue; + public Boolean getExperimentalFollowTypeHintsArg() { + return this.experimentaFollowTypeHintsParam; } /** @@ -545,52 +536,52 @@ public String getExperimentalFollowTypeHintsArg() { * @return String of this {@link decoratorType} parameter func. */ public String getFuncArg() { - return this.funcParamValue; + return this.funcParam; } /** * Value of {@link Function}'s {@link decoratorsType} parameter input_signature. * - * @return String of this {@link decoratorType} parameter input_signature. + * @return ArrayList of TensorSpecs of this {@link decoratorType} parameter input_signature. */ - public String getInputSignatureArg() { - return this.inputSignatureParamValue; + public ArrayList getInputSignatureArg() { + return this.inputSignatureParam; } /** * Value of {@link Function}'s {@link decoratorsType} parameter jit_compile. * - * @return String of this {@link decoratorType} parameter jit_compile. + * @return Boolean of this {@link decoratorType} parameter jit_compile. */ - public String getJitCompileArg() { - return this.jitCompileParamValue; + public Boolean getJitCompileArg() { + return this.jitCompileParam; } /** * Value of {@link Function}'s {@link decoratorsType} parameter reduce_retracing. * - * @return String of this {@link Function} parameter reduce_retracing. + * @return boolean of this {@link Function} parameter reduce_retracing. */ - public String getReduceRetracingArg() { - return this.reduceRetracingParamValue; + public boolean getReduceRetracingArg() { + return this.reduceRetracingParam; } /** * Value of {@link Function}'s {@link decoratorsType} parameter experimental_compile. * - * @return String of this {@link decoratorType} parameter experimental_compile. + * @return Boolean of this {@link decoratorType} parameter experimental_compile. */ - public String getExperimentalCompileArg() { - return this.jitCompileParamValue; + public Boolean getExperimentalCompileArg() { + return this.jitCompileParam; } /** * Value of {@link Function}'s {@link decoratorsType} parameter experimental_relax_shapes. * - * @return String of this {@link Function} parameter experimental_relax_shapes. + * @return boolean of this {@link Function} parameter experimental_relax_shapes. */ - public String getExperimentalRelaxShapeArg() { - return this.reduceRetracingParamValue; + public boolean getExperimentalRelaxShapeArg() { + return this.reduceRetracingParam; } } From af61fe572db8fb46d7bf8f85058b4d027dd3b932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 9 Mar 2023 16:53:08 -0500 Subject: [PATCH 56/70] Restructure --- .../hybridize/core/analysis/Function.java | 23 ++++++++-- .../HybridizeFunctionRefactoringTest.java | 46 +++++++++---------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index e85da01e6..a25b964cb 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -150,7 +150,8 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.funcParam = value.id; + // Default value + this.funcParam = null; else throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); } else { @@ -162,6 +163,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals + // Default value this.inputSignatureParam = null; else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); @@ -186,6 +188,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "True")// Checking only literals + // Default value this.autoGraphParam = true; else if (value.id == "False") this.autoGraphParam = false; @@ -207,6 +210,7 @@ else if (value.id == "False") else if (value.id == "False") this.jitCompileParam = false; else if (value.id == "None") + // Default value this.jitCompileParam = null; else throw new IllegalArgumentException( @@ -226,6 +230,7 @@ else if (value.id == "None") if (value.id == "True") // Checking only literals this.reduceRetracingParam = true; else if (value.id == "False") // Checking only literals + // Default value this.reduceRetracingParam = false; else throw new IllegalArgumentException( @@ -244,7 +249,8 @@ else if (value.id == "False") // Checking only literals } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.experimentalImplementsParam = value.id; + // Default value + this.experimentalImplementsParam = null; else throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } else { @@ -278,7 +284,8 @@ else if (value.id == "False") // Checking only literals } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals - this.experimentalAutographOptionsParam = value.id; + // Default value + this.experimentalAutographOptionsParam = null; else throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); @@ -292,6 +299,7 @@ else if (value.id == "False") // Checking only literals if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "None") // Checking only literals + // Default value this.experimentaFollowTypeHintsParam = null; else if (value.id == "True") // Checking only literals this.experimentaFollowTypeHintsParam = true; @@ -424,8 +432,8 @@ else if (keyword.value instanceof Attribute) { * @return True iff this {@link decoratorType} has parameter autograph. */ public boolean hasAutoGraphParam() { - // False is the default value - return (this.autoGraphParam != false); + // True is the default value + return (this.autoGraphParam != true); } @@ -435,6 +443,7 @@ public boolean hasAutoGraphParam() { * @return True iff this {@link decoratorType} has parameter experimental_autograph_options. */ public boolean hasExperimentalAutographOptParam() { + // None is the default value return (this.experimentalAutographOptionsParam != null); } @@ -444,6 +453,7 @@ public boolean hasExperimentalAutographOptParam() { * @return True iff this {@link decoratorType} has parameter experimental_implements. */ public boolean hasExperimentalImplementsParam() { + // None is the default value return (this.experimentalImplementsParam != null); } @@ -453,6 +463,7 @@ public boolean hasExperimentalImplementsParam() { * @return True iff this {@link decoratorType} has parameter experimental_follow_type_hints. */ public boolean hasExperimentalFollowTypeHintsParam() { + // None is the default value return (this.experimentaFollowTypeHintsParam != null); } @@ -462,6 +473,7 @@ public boolean hasExperimentalFollowTypeHintsParam() { * @return True iff this {@link decoratorType} has parameter func. */ public boolean hasFuncParam() { + // None is the default value return (this.funcParam != null); } @@ -471,6 +483,7 @@ public boolean hasFuncParam() { * @return True iff this {@link decoratorType} has parameter input_signature. */ public boolean hasInputSignatureParam() { + // None is the default value return (this.inputSignatureParam != null); } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index b6d526e57..81f0af9e9 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -845,7 +845,7 @@ public void testDecoratorArguments() throws Exception { if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("None", args.getInputSignatureArg()); + assertEquals(null, args.getInputSignatureArg()); } /** @@ -955,7 +955,7 @@ public void testDecoratorArguments6() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("False", args.getAutoGraphArg()); + assertEquals(false, args.getAutoGraphArg()); } /** @@ -977,7 +977,7 @@ public void testDecoratorArguments7() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getAutoGraphArg()); + assertEquals(true, args.getAutoGraphArg()); } /** @@ -999,7 +999,7 @@ public void testDecoratorArguments8() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getJitCompileArg()); + assertEquals(true, args.getJitCompileArg()); } /** @@ -1021,7 +1021,7 @@ public void testDecoratorArguments9() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("False", args.getJitCompileArg()); + assertEquals(false, args.getJitCompileArg()); } /** @@ -1043,7 +1043,7 @@ public void testDecoratorArguments10() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("None", args.getJitCompileArg()); + assertEquals(null, args.getJitCompileArg()); } /** @@ -1063,7 +1063,7 @@ public void testDecoratorArguments11() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getReduceRetracingArg()); + assertEquals(true, args.getReduceRetracingArg()); } /** @@ -1083,7 +1083,7 @@ public void testDecoratorArguments12() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("False", args.getReduceRetracingArg()); + assertEquals(false, args.getReduceRetracingArg()); } /** @@ -1149,7 +1149,7 @@ public void testDecoratorArguments15() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("None", args.getExperimentalImplementsArg()); + assertEquals(null, args.getExperimentalImplementsArg()); } /** @@ -1242,7 +1242,7 @@ public void testDecoratorArguments19() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("None", args.getExperimentalAutographOptArg()); + assertEquals(null, args.getExperimentalAutographOptArg()); } /** @@ -1264,7 +1264,7 @@ public void testDecoratorArguments20() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) - assertEquals("True", args.getExperimentalFollowTypeHintsArg()); + assertEquals(true, args.getExperimentalFollowTypeHintsArg()); } /** @@ -1286,7 +1286,7 @@ public void testDecoratorArguments21() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) - assertEquals("False", args.getExperimentalFollowTypeHintsArg()); + assertEquals(false, args.getExperimentalFollowTypeHintsArg()); } /** @@ -1308,7 +1308,7 @@ public void testDecoratorArguments22() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) - assertEquals("None", args.getExperimentalFollowTypeHintsArg()); + assertEquals(null, args.getExperimentalFollowTypeHintsArg()); } /** @@ -1327,8 +1327,8 @@ public void testDecoratorArguments23() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - assertTrue(args.getFuncArg() == null && args.getInputSignatureArg() == null & args.getAutoGraphArg() == null - && args.getJitCompileArg() == null && args.getReduceRetracingArg() == null && args.getExperimentalImplementsArg() == null + assertTrue(args.getFuncArg() == null && args.getInputSignatureArg() == null & args.getAutoGraphArg() == false + && args.getJitCompileArg() == null && args.getReduceRetracingArg() == false && args.getExperimentalImplementsArg() == null && args.getExperimentalAutographOptArg() == null && args.getExperimentalFollowTypeHintsArg() == null); } @@ -1352,7 +1352,7 @@ public void testDecoratorArguments24() throws Exception { && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); - assertEquals("False", args.getAutoGraphArg()); + assertEquals(false, args.getAutoGraphArg()); } } @@ -1401,7 +1401,7 @@ public void testDecoratorArguments26() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("False", args.getAutoGraphArg()); + assertEquals(false, args.getAutoGraphArg()); assertTrue(args.getInputSignatureArg() == null); } @@ -1426,8 +1426,8 @@ public void testDecoratorArguments27() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("True", args.getJitCompileArg()); - assertTrue(args.getAutoGraphArg() == null); + assertEquals(true, args.getJitCompileArg()); + assertTrue(args.getAutoGraphArg() == false); } } @@ -1502,7 +1502,7 @@ public void testDecoratorArguments30() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("False", args.getAutoGraphArg()); + assertEquals(false, args.getAutoGraphArg()); } } @@ -1526,7 +1526,7 @@ public void testDecoratorArguments31() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("False", args.getJitCompileArg()); + assertEquals(false, args.getJitCompileArg()); } } @@ -1550,7 +1550,7 @@ public void testDecoratorArguments32() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("False", args.getReduceRetracingArg()); + assertEquals(false, args.getReduceRetracingArg()); } } @@ -1623,7 +1623,7 @@ public void testDecoratorArguments35() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("True", args.getExperimentalFollowTypeHintsArg()); + assertEquals(true, args.getExperimentalFollowTypeHintsArg()); } } From 247e1d69fe35483917204fe8ed917779ebfdfe64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 9 Mar 2023 17:15:03 -0500 Subject: [PATCH 57/70] Restructure --- .../hybridize/core/analysis/Function.java | 13 ++---- .../hybridize/core/analysis/TensorSpec.java | 37 --------------- .../HybridizeFunctionRefactoringTest.java | 46 ++++++++++++++++--- 3 files changed, 43 insertions(+), 53 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index a25b964cb..96d0f438d 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -386,20 +386,15 @@ private ArrayList processTensorSpecs(exprType[] valueElements) { // Positional arguments for TensorSpecs exprType[] tensorArgs = callTuple.args; for (exprType tensorArg : tensorArgs) { - if (tensorArg instanceof Tuple) { + if (tensorArg instanceof Tuple) tensor.setShape(processTupleOrListForShape(((Tuple) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof List) { + else if (tensorArg instanceof List) tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); - tensor.setShapeKeyword(false); - } else if (tensorArg instanceof Attribute) { + else if (tensorArg instanceof Attribute) { Attribute attrValue = (Attribute) tensorArg; tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); - tensor.setDTypeKeyword(false); - } else { + } else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - } - } // Keyword Arguments for TensorSpecs keywordType[] keywordsCall = callTuple.keywords; diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index 4434c98f7..b6aed923d 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -15,22 +15,9 @@ public class TensorSpec { */ private String dtype; - /** - * True if the {@link TensorSpec} is using keyword arguments for the shape. - */ - private boolean shapeKeyword; - - /** - * True if the {@link TensorSpec} is using keyword arguments for the type. - */ - private boolean dtypeKeyword; - public TensorSpec() { this.shape = ""; this.dtype = ""; - this.shapeKeyword = true; - this.dtypeKeyword = true; - } public TensorSpec(String s, String d) { @@ -70,28 +57,4 @@ public void setDType(String d) { this.dtype = d; } - /** - * Set if the type of the argument for shape of {@link TensorSpec} is a keyword. - */ - public void setShapeKeyword(boolean s) { - this.shapeKeyword = s; - } - - /** - * Set if the type of the argument for dtype of {@link TensorSpec} is a keyword. - */ - public void setDTypeKeyword(boolean d) { - this.dtypeKeyword = d; - } - - @Override - public String toString() { - if (this.dtype.isEmpty() && this.shape.isEmpty()) - return "tf.TensorSpec([])"; - if (!this.shapeKeyword && !this.dtypeKeyword) - return "tf.TensorSpec([" + this.shape + "]" + ", " + this.dtype + ")"; - if (!this.shapeKeyword && this.dtypeKeyword) - return "tf.TensorSpec([" + this.shape + "]" + ", dtype=" + this.dtype + ")"; - return "tf.TensorSpec(shape=[" + this.shape + "]" + ", dtype=" + this.dtype + ")"; - } } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 81f0af9e9..b9e23a904 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -90,6 +90,7 @@ import edu.cuny.hunter.hybridize.core.analysis.Function; import edu.cuny.hunter.hybridize.core.analysis.FunctionDefinition; import edu.cuny.hunter.hybridize.core.analysis.FunctionExtractor; +import edu.cuny.hunter.hybridize.core.analysis.TensorSpec; import edu.cuny.hunter.hybridize.core.analysis.Util; import edu.cuny.hunter.hybridize.core.refactorings.HybridizeFunctionRefactoringProcessor; import edu.cuny.hunter.hybridize.core.utils.RefactoringAvailabilityTester; @@ -864,10 +865,14 @@ public void testDecoratorArguments2() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec("None", "tf.float32"); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); } /** @@ -886,10 +891,14 @@ public void testDecoratorArguments3() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec("2, 2", "tf.float32"); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("(tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getInputSignatureArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); } /** @@ -908,10 +917,17 @@ public void testDecoratorArguments4() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec(); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + tensors.add(tensor); + + System.out.println("Size tensors : " + Integer.toString(tensors.size())); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("(tf.TensorSpec([]), tf.TensorSpec([]))", args.getInputSignatureArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); } /** @@ -930,10 +946,14 @@ public void testDecoratorArguments5() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec("", "tf.float32"); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("[tf.TensorSpec([], tf.float32)]", args.getInputSignatureArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); } /** @@ -1348,10 +1368,14 @@ public void testDecoratorArguments24() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec("None", "tf.float32"); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getInputSignatureArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); assertEquals(false, args.getAutoGraphArg()); } } @@ -1449,10 +1473,14 @@ public void testDecoratorArguments28() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec("None", "tf.float32"); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.TensorSpec(shape=[None], dtype=tf.float32),)", args.getJitCompileArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); } } @@ -1474,10 +1502,14 @@ public void testDecoratorArguments29() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + TensorSpec tensor = new TensorSpec("2, 2", "tf.float32"); + ArrayList tensors = new ArrayList(); + tensors.add(tensor); + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.TensorSpec(shape=[2, 2], dtype=tf.float32),)", args.getJitCompileArg()); + assertTrue(tensors.equals(args.getInputSignatureArg())); } } From 9b764d992f05102b1d48d6661ae7041e0e8c78f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 9 Mar 2023 17:17:24 -0500 Subject: [PATCH 58/70] Remove redundancy --- .../tests/HybridizeFunctionRefactoringTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index b9e23a904..e561485dd 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -866,7 +866,7 @@ public void testDecoratorArguments2() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec("None", "tf.float32"); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -892,7 +892,7 @@ public void testDecoratorArguments3() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec("2, 2", "tf.float32"); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -918,7 +918,7 @@ public void testDecoratorArguments4() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec(); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); tensors.add(tensor); @@ -947,7 +947,7 @@ public void testDecoratorArguments5() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec("", "tf.float32"); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1369,7 +1369,7 @@ public void testDecoratorArguments24() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec("None", "tf.float32"); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1474,7 +1474,7 @@ public void testDecoratorArguments28() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec("None", "tf.float32"); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1503,7 +1503,7 @@ public void testDecoratorArguments29() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec("2, 2", "tf.float32"); - ArrayList tensors = new ArrayList(); + ArrayList tensors = new ArrayList<>(); tensors.add(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() From bc3ff06559d6367c1d2f49a88b59ab04026db501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Mar 2023 14:13:21 -0500 Subject: [PATCH 59/70] Restructuring --- .../hybridize/core/analysis/Function.java | 5 +++-- .../hybridize/core/analysis/TensorSpec.java | 22 +++++++++++++++++++ .../HybridizeFunctionRefactoringTest.java | 5 +++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 96d0f438d..43f75a0e2 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -68,9 +68,10 @@ public class HybridizationParameters { private static final String FUNC = "func"; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. The values could be True or False. + * Value of this {@link Function}'s {@link decoratorsType} parameter autograph. The values could be True or False. Setting it as + * true because that is the default value of autograph. */ - private boolean autoGraphParam; + private boolean autoGraphParam = true; /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. The values could be None, False diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index b6aed923d..d6b7163a3 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -1,5 +1,7 @@ package edu.cuny.hunter.hybridize.core.analysis; +import java.util.Objects; + /** * A representation of a tf.Tensorspec which describes a tf.Tensor */ @@ -57,4 +59,24 @@ public void setDType(String d) { this.dtype = d; } + @Override + public int hashCode() { + return Objects.hash(shape, dtype); + } + + @Override + public boolean equals(Object tensorObject) { + + if (tensorObject == this) { + return true; + } + + if (!(tensorObject instanceof TensorSpec)) { + return false; + } + + TensorSpec tensor = (TensorSpec) tensorObject; + + return shape.equals(tensor.shape) && dtype.equals(tensor.dtype); + } } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index e561485dd..ef6a7f1ce 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -1347,7 +1347,8 @@ public void testDecoratorArguments23() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - assertTrue(args.getFuncArg() == null && args.getInputSignatureArg() == null & args.getAutoGraphArg() == false + // Default values + assertTrue(args.getFuncArg() == null && args.getInputSignatureArg() == null & args.getAutoGraphArg() == true && args.getJitCompileArg() == null && args.getReduceRetracingArg() == false && args.getExperimentalImplementsArg() == null && args.getExperimentalAutographOptArg() == null && args.getExperimentalFollowTypeHintsArg() == null); } @@ -1451,7 +1452,7 @@ public void testDecoratorArguments27() throws Exception { && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { assertEquals(true, args.getJitCompileArg()); - assertTrue(args.getAutoGraphArg() == false); + assertTrue(args.getAutoGraphArg() == true); // default value of autograph } } From cb23e2fdf0d36727fc55753cb23366ce3d598f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 10 Mar 2023 17:12:02 -0500 Subject: [PATCH 60/70] Adding more information --- .../edu/cuny/hunter/hybridize/core/analysis/Function.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 43f75a0e2..96b3e8e20 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -75,7 +75,7 @@ public class HybridizationParameters { /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. The values could be None, False - * or True. + * or True. null represents the value of None. */ private Boolean experimentaFollowTypeHintsParam; @@ -99,12 +99,13 @@ public class HybridizationParameters { /** * Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. The value could be None, or a possibly nested - * sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function + * sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function. */ private ArrayList inputSignatureParam; /** - * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. The values could be None, False or True. + * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. The values could be None, False or True. null + * represents the value of None. */ private Boolean jitCompileParam; From 79d0ff3947c0a866907a90555bdd7e5d8b2248cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Mon, 13 Mar 2023 12:05:43 -0400 Subject: [PATCH 61/70] update --- .../hybridize/tests/HybridizeFunctionRefactoringTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index ef6a7f1ce..8e1f4bff5 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -922,8 +922,6 @@ public void testDecoratorArguments4() throws Exception { tensors.add(tensor); tensors.add(tensor); - System.out.println("Size tensors : " + Integer.toString(tensors.size())); - if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) From 9163368a396e3108700da9aa211a27f0f1d47160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 22 Mar 2023 09:58:44 -0400 Subject: [PATCH 62/70] Fixing asserts --- .../HybridizeFunctionRefactoringTest.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 294079720..a4780b7f9 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -846,7 +846,7 @@ public void testDecoratorArguments() throws Exception { if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(null, args.getInputSignatureArg()); + assertNull(args.getInputSignatureArg()); } /** @@ -973,7 +973,7 @@ public void testDecoratorArguments6() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(false, args.getAutoGraphArg()); + assertFalse(args.getAutoGraphArg()); } /** @@ -995,7 +995,7 @@ public void testDecoratorArguments7() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(true, args.getAutoGraphArg()); + assertTrue(args.getAutoGraphArg()); } /** @@ -1017,7 +1017,7 @@ public void testDecoratorArguments8() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(true, args.getJitCompileArg()); + assertTrue(args.getJitCompileArg()); } /** @@ -1039,7 +1039,7 @@ public void testDecoratorArguments9() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(false, args.getJitCompileArg()); + assertFalse(args.getJitCompileArg()); } /** @@ -1061,7 +1061,7 @@ public void testDecoratorArguments10() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(null, args.getJitCompileArg()); + assertNull(args.getJitCompileArg()); } /** @@ -1081,7 +1081,7 @@ public void testDecoratorArguments11() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(true, args.getReduceRetracingArg()); + assertTrue(args.getReduceRetracingArg()); } /** @@ -1101,7 +1101,7 @@ public void testDecoratorArguments12() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(false, args.getReduceRetracingArg()); + assertFalse(args.getReduceRetracingArg()); } /** @@ -1167,7 +1167,7 @@ public void testDecoratorArguments15() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(null, args.getExperimentalImplementsArg()); + assertNull(args.getExperimentalImplementsArg()); } /** @@ -1260,7 +1260,7 @@ public void testDecoratorArguments19() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals(null, args.getExperimentalAutographOptArg()); + assertNull(args.getExperimentalAutographOptArg()); } /** @@ -1282,7 +1282,7 @@ public void testDecoratorArguments20() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) - assertEquals(true, args.getExperimentalFollowTypeHintsArg()); + assertTrue(args.getExperimentalFollowTypeHintsArg()); } /** @@ -1304,7 +1304,7 @@ public void testDecoratorArguments21() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) - assertEquals(false, args.getExperimentalFollowTypeHintsArg()); + assertFalse(args.getExperimentalFollowTypeHintsArg()); } /** @@ -1326,7 +1326,7 @@ public void testDecoratorArguments22() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) - assertEquals(null, args.getExperimentalFollowTypeHintsArg()); + assertNull(args.getExperimentalFollowTypeHintsArg()); } /** @@ -1375,7 +1375,7 @@ public void testDecoratorArguments24() throws Exception { && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { assertTrue(tensors.equals(args.getInputSignatureArg())); - assertEquals(false, args.getAutoGraphArg()); + assertFalse(args.getAutoGraphArg()); } } @@ -1424,7 +1424,7 @@ public void testDecoratorArguments26() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals(false, args.getAutoGraphArg()); + assertFalse(args.getAutoGraphArg()); assertTrue(args.getInputSignatureArg() == null); } @@ -1449,8 +1449,8 @@ public void testDecoratorArguments27() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals(true, args.getJitCompileArg()); - assertTrue(args.getAutoGraphArg() == true); // default value of autograph + assertTrue(args.getJitCompileArg()); + assertTrue(args.getAutoGraphArg()); // default value of autograph } } @@ -1533,7 +1533,7 @@ public void testDecoratorArguments30() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals(false, args.getAutoGraphArg()); + assertFalse(args.getAutoGraphArg()); } } @@ -1557,7 +1557,7 @@ public void testDecoratorArguments31() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals(false, args.getJitCompileArg()); + assertFalse(args.getJitCompileArg()); } } @@ -1581,7 +1581,7 @@ public void testDecoratorArguments32() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals(false, args.getReduceRetracingArg()); + assertFalse(args.getReduceRetracingArg()); } } @@ -1654,7 +1654,7 @@ public void testDecoratorArguments35() throws Exception { if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() && args.hasExperimentalFollowTypeHintsParam()) { - assertEquals(true, args.getExperimentalFollowTypeHintsArg()); + assertTrue(args.getExperimentalFollowTypeHintsArg()); } } From d845f0a5798cfba778aebe28f2bbd01006244110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 22 Mar 2023 21:48:45 -0400 Subject: [PATCH 63/70] Progress --- .../hybridize/core/analysis/Function.java | 129 ++++++++---------- .../hybridize/core/analysis/TensorSpec.java | 13 +- .../HybridizeFunctionRefactoringTest.java | 60 ++++---- 3 files changed, 99 insertions(+), 103 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 41964e9ae..9a1a5ade0 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -38,10 +38,14 @@ */ public class Function extends RefactorableProgramEntity { + public enum TfAutographExperimentalFeature { + ALL, AUTO_CONTROL_DEPS, ASSERT_STATEMENTS, BUILTIN_FUNCTIONS, EQUALITY_OPERATORS, LISTS, NAME_SCOPES + } + /** * Parameters that may be passed to a tf.fuction decorator. Parameter descriptions found at: - * https://tensorflow.org/versions/r2.9/api_docs/python/tf/function Note: We are also parsing the deprecated parameters specified in - * the documentation. Users can still use these deprecated parameters. Therefore we need to be able to account for them. Please refer to + * https://tensorflow.org/versions/r2.9/api_docs/python/tf/function Note: We are also parsing the deprecated parameters specified in the + * documentation. Users can still use these deprecated parameters. Therefore we need to be able to account for them. Please refer to * https://github.com/ponder-lab/Hybridize-Functions-Refactoring/wiki/tf.function-parameter's-version-information to see more * information about the tf.function parameters according to the versions. */ @@ -81,9 +85,10 @@ public class HybridizationParameters { /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. The values could be an optional - * tuple or value of tf.autograph.experimental.Feature values or None. + * tuple or value of tf.autograph.experimental.Feature values (tf.autograph.experimental.Feature.EQUALITY_OPERATORS)or + * None. */ - private String experimentalAutographOptionsParam; + private java.util.List experimentalAutographOptionsParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. The value could be None or a name of a @@ -101,7 +106,7 @@ public class HybridizationParameters { * Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. The value could be None, or a possibly nested * sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function. */ - private ArrayList inputSignatureParam; + private java.util.List inputSignatureParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter jit_compile. The values could be None, False or True. null @@ -164,10 +169,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "None") // Checking only literals - // Default value - this.inputSignatureParam = null; - else + if (value.id != "None") // Checking only literals throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); // Example: (tf.TensorSpec(shape=[None], dtype=tf.float32),) } else if (keyword.value instanceof Tuple) { @@ -189,12 +191,9 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "True")// Checking only literals - // Default value - this.autoGraphParam = true; - else if (value.id == "False") + if (value.id == "False") this.autoGraphParam = false; - else + else if (value.id != "True") throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); } else { throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); @@ -211,10 +210,7 @@ else if (value.id == "False") this.jitCompileParam = true; else if (value.id == "False") this.jitCompileParam = false; - else if (value.id == "None") - // Default value - this.jitCompileParam = null; - else + else if (value.id != "None") throw new IllegalArgumentException( "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); } else { @@ -231,10 +227,7 @@ else if (value.id == "None") Name value = (Name) keyword.value; if (value.id == "True") // Checking only literals this.reduceRetracingParam = true; - else if (value.id == "False") // Checking only literals - // Default value - this.reduceRetracingParam = false; - else + else if (value.id != "False") // Checking only literals throw new IllegalArgumentException( "Unable to process " + REDUCE_RETRACING + "/" + EXPERIMENTAL_RELAX_SHAPES + " argument."); } else { @@ -250,45 +243,38 @@ else if (value.id == "False") // Checking only literals // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "None") // Checking only literals - // Default value - this.experimentalImplementsParam = null; - else + if (value.id != "None") // Checking only literals throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } else { throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_IMPLEMENTS + " argument."); } } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { + java.util.List autographExperimental = new ArrayList<>(); // Found parameter experimental_autograph_options // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS if (keyword.value instanceof Attribute) { Attribute keywordAttribute = (Attribute) keyword.value; - this.experimentalAutographOptionsParam = processAttributeForAutographOptions(keywordAttribute); + autographExperimental.add(processAttributeForAutographOptions(keywordAttribute)); + this.experimentalAutographOptionsParam = autographExperimental; // Example of value: (tf.autograph.experimental.Feature.EQUALITY_OPERATORS, // tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS) } else if (keyword.value instanceof Tuple) { Tuple keywordTuple = (Tuple) keyword.value; exprType[] keywordExpr = keywordTuple.elts; - String finalTuple = ""; - int count = 0; for (exprType expr : keywordExpr) { if (expr instanceof Attribute) { Attribute keywordAttribute = (Attribute) expr; - if (count == 0) - finalTuple += processAttributeForAutographOptions(keywordAttribute); - else - finalTuple += ", " + processAttributeForAutographOptions(keywordAttribute); + autographExperimental.add(processAttributeForAutographOptions(keywordAttribute)); + } else { + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " arguments"); } - count++; } - this.experimentalAutographOptionsParam = "(" + finalTuple + ")"; + this.experimentalAutographOptionsParam = autographExperimental; // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "None") // Checking only literals - // Default value - this.experimentalAutographOptionsParam = null; - else + if (value.id != "None") // Checking only literals throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); } else { @@ -300,14 +286,11 @@ else if (value.id == "False") // Checking only literals // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "None") // Checking only literals - // Default value - this.experimentaFollowTypeHintsParam = null; - else if (value.id == "True") // Checking only literals + if (value.id == "True") // Checking only literals this.experimentaFollowTypeHintsParam = true; else if (value.id == "False") // Checking only literals this.experimentaFollowTypeHintsParam = false; - else + else if (value.id != "None") throw new IllegalArgumentException( "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " argument."); } else { @@ -325,27 +308,20 @@ else if (value.id == "False") // Checking only literals * * @return String of TensorSpec shape. */ - private String processTupleOrListForShape(exprType[] exprTupleOrList) { - int count = 0; - String tempString = ""; + private java.util.List processTupleOrListForShape(exprType[] exprTupleOrList) { + java.util.List shape = new ArrayList<>(); for (exprType expr : exprTupleOrList) { if (expr instanceof Num) { - if (count == 0) - tempString += ((Num) expr).num; - else - tempString += ", " + ((Num) expr).num; - count++; + shape.add(((Num) expr).type); } else if (expr instanceof Name) { - if (((Name) expr).id == "None") // Checking only literals - tempString = ((Name) expr).id; - else + if (((Name) expr).id != "None") // Checking only literals throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } - return tempString; + return shape; } @@ -354,21 +330,34 @@ private String processTupleOrListForShape(exprType[] exprTupleOrList) { * * @return String of autograph options that contains various attributes. */ - private String processAttributeForAutographOptions(Attribute keywordAttribute) { - StringBuilder argument = new StringBuilder(); + private TfAutographExperimentalFeature processAttributeForAutographOptions(Attribute keywordAttribute) { + String attributeEnum; Attribute tempAttr = keywordAttribute; - while (tempAttr.value instanceof Attribute) { + if (tempAttr.value instanceof Attribute) { NameTok valueAttribute = (NameTok) tempAttr.attr; - argument.insert(0, valueAttribute.id); - argument.insert(0, "."); - if (tempAttr.value instanceof Attribute) - tempAttr = (Attribute) tempAttr.value; - else - throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); - } - - return ((Name) tempAttr.value).id + "." + ((NameTok) tempAttr.attr).id + argument.toString(); + attributeEnum = valueAttribute.id; + } else + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); + + LOG.info(attributeEnum); + + if (attributeEnum.equals("ALL")) + return TfAutographExperimentalFeature.ALL; + else if (attributeEnum.equals("AUTO_CONTROL_DEPS")) + return TfAutographExperimentalFeature.AUTO_CONTROL_DEPS; + else if (attributeEnum.equals("ASSERT_STATEMENTS")) + return TfAutographExperimentalFeature.ASSERT_STATEMENTS; + else if (attributeEnum.equals("BUILTIN_FUNCTIONS")) + return TfAutographExperimentalFeature.BUILTIN_FUNCTIONS; + else if (attributeEnum.equals("EQUALITY_OPERATORS")) + return TfAutographExperimentalFeature.EQUALITY_OPERATORS; + else if (attributeEnum.equals("LISTS")) + return TfAutographExperimentalFeature.LISTS; + else if (attributeEnum.equals("NAME_SCOPES")) + return TfAutographExperimentalFeature.NAME_SCOPES; + else + return null; } /** @@ -518,7 +507,7 @@ public boolean getAutoGraphArg() { * * @return String of this {@link decoratorType} parameter experimental_autograph_options. */ - public String getExperimentalAutographOptArg() { + public java.util.List getExperimentalAutographOptArg() { return this.experimentalAutographOptionsParam; } @@ -554,7 +543,7 @@ public String getFuncArg() { * * @return ArrayList of TensorSpecs of this {@link decoratorType} parameter input_signature. */ - public ArrayList getInputSignatureArg() { + public java.util.List getInputSignatureArg() { return this.inputSignatureParam; } diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index d6b7163a3..8c6d96c55 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -1,5 +1,6 @@ package edu.cuny.hunter.hybridize.core.analysis; +import java.util.List; import java.util.Objects; /** @@ -10,7 +11,7 @@ public class TensorSpec { /** * Shape of the tensor being described by {@link TensorSpec}. */ - private String shape; + private List shape; /** * Type of the tensor being described by {@link TensorSpec}. @@ -18,11 +19,11 @@ public class TensorSpec { private String dtype; public TensorSpec() { - this.shape = ""; + this.shape = null; this.dtype = ""; } - public TensorSpec(String s, String d) { + public TensorSpec(List s, String d) { this.shape = s; this.dtype = d; } @@ -30,9 +31,9 @@ public TensorSpec(String s, String d) { /** * Shape of {@link TensorSpec}. * - * @return String of this {@link TensorSpec} shape. + * @return List of dimensions (null if the shape is unspecified) of this {@link TensorSpec} shape. */ - public String getShape() { + public List getShape() { return this.shape; } @@ -48,7 +49,7 @@ public String getDType() { /** * Set shape of {@link TensorSpec}. */ - public void setShape(String s) { + public void setShape(List s) { this.shape = s; } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index a4780b7f9..fec2f6e63 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -88,6 +88,7 @@ import edu.cuny.citytech.refactoring.common.tests.RefactoringTest; import edu.cuny.hunter.hybridize.core.analysis.Function; +import edu.cuny.hunter.hybridize.core.analysis.Function.TfAutographExperimentalFeature; import edu.cuny.hunter.hybridize.core.analysis.FunctionDefinition; import edu.cuny.hunter.hybridize.core.analysis.FunctionExtractor; import edu.cuny.hunter.hybridize.core.analysis.TensorSpec; @@ -865,7 +866,7 @@ public void testDecoratorArguments2() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec("None", "tf.float32"); + TensorSpec tensor = new TensorSpec(null, "tf.float32"); ArrayList tensors = new ArrayList<>(); tensors.add(tensor); @@ -891,9 +892,10 @@ public void testDecoratorArguments3() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec("2, 2", "tf.float32"); - ArrayList tensors = new ArrayList<>(); - tensors.add(tensor); + List shape = Arrays.asList(2, 2); + + TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() @@ -918,9 +920,7 @@ public void testDecoratorArguments4() throws Exception { assertNotNull(args); TensorSpec tensor = new TensorSpec(); - ArrayList tensors = new ArrayList<>(); - tensors.add(tensor); - tensors.add(tensor); + List tensors = Arrays.asList(tensor, tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() @@ -944,9 +944,8 @@ public void testDecoratorArguments5() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec("", "tf.float32"); - ArrayList tensors = new ArrayList<>(); - tensors.add(tensor); + TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() @@ -1187,10 +1186,12 @@ public void testDecoratorArguments16() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + List feature = Arrays.asList(TfAutographExperimentalFeature.EQUALITY_OPERATORS); + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("tf.autograph.experimental.Feature.EQUALITY_OPERATORS", args.getExperimentalAutographOptArg()); + assertEquals(feature, args.getExperimentalAutographOptArg()); } /** @@ -1210,10 +1211,12 @@ public void testDecoratorArguments17() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + List feature = Arrays.asList(TfAutographExperimentalFeature.ALL); + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("tf.autograph.experimental.Feature.ALL", args.getExperimentalAutographOptArg()); + assertEquals(feature, args.getExperimentalAutographOptArg()); } /** @@ -1233,11 +1236,13 @@ public void testDecoratorArguments18() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + List feature = Arrays.asList(TfAutographExperimentalFeature.EQUALITY_OPERATORS, + TfAutographExperimentalFeature.BUILTIN_FUNCTIONS); + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) - assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", - args.getExperimentalAutographOptArg()); + assertEquals(feature, args.getExperimentalAutographOptArg()); } /** @@ -1367,9 +1372,8 @@ public void testDecoratorArguments24() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec("None", "tf.float32"); - ArrayList tensors = new ArrayList<>(); - tensors.add(tensor); + TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() @@ -1472,9 +1476,8 @@ public void testDecoratorArguments28() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec("None", "tf.float32"); - ArrayList tensors = new ArrayList<>(); - tensors.add(tensor); + TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() @@ -1501,9 +1504,10 @@ public void testDecoratorArguments29() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec("2, 2", "tf.float32"); - ArrayList tensors = new ArrayList<>(); - tensors.add(tensor); + List shape = Arrays.asList(2, 2); + + TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() @@ -1626,11 +1630,13 @@ public void testDecoratorArguments34() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); + List feature = Arrays.asList(TfAutographExperimentalFeature.EQUALITY_OPERATORS, + TfAutographExperimentalFeature.BUILTIN_FUNCTIONS); + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() && !args.hasExperimentalFollowTypeHintsParam()) { - assertEquals("(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS)", - args.getExperimentalAutographOptArg()); + assertEquals(feature, args.getExperimentalAutographOptArg()); } } @@ -2442,8 +2448,8 @@ public void testModel() throws Exception { } /** - * Test a model. No tf.function in this one. Use call instead of __call__. Ariadne doesn't support __call__. - * See https://github.com/wala/ML/issues/24. + * Test a model. No tf.function in this one. Use call instead of __call__. Ariadne doesn't support __call__. See + * https://github.com/wala/ML/issues/24. */ @Test public void testModel2() throws Exception { From 6a13a5e40bda0581a9cd1712c714045fb326e652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 22 Mar 2023 22:36:37 -0400 Subject: [PATCH 64/70] progress --- .../cuny/hunter/hybridize/core/analysis/TensorSpec.java | 3 ++- .../tests/HybridizeFunctionRefactoringTest.java | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index 8c6d96c55..9434d59b0 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -1,5 +1,6 @@ package edu.cuny.hunter.hybridize.core.analysis; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -19,7 +20,7 @@ public class TensorSpec { private String dtype; public TensorSpec() { - this.shape = null; + this.shape = new ArrayList<>(); this.dtype = ""; } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index fec2f6e63..a4cf010e0 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -866,7 +866,8 @@ public void testDecoratorArguments2() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List shape = new ArrayList<>(); + TensorSpec tensor = new TensorSpec(shape, "tf.float32"); ArrayList tensors = new ArrayList<>(); tensors.add(tensor); @@ -944,7 +945,8 @@ public void testDecoratorArguments5() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List shape = new ArrayList<>(); + TensorSpec tensor = new TensorSpec(shape, "tf.float32"); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1372,7 +1374,8 @@ public void testDecoratorArguments24() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List shape = new ArrayList<>(); + TensorSpec tensor = new TensorSpec(shape, "tf.float32"); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() From 4c79a5a9b572aa7152c59597a47663d0302c3c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Wed, 22 Mar 2023 22:59:40 -0400 Subject: [PATCH 65/70] Progress --- .../src/edu/cuny/hunter/hybridize/core/analysis/Function.java | 2 +- .../src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 9a1a5ade0..709edbed2 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -313,7 +313,7 @@ private java.util.List processTupleOrListForShape(exprType[] exprTupleO for (exprType expr : exprTupleOrList) { if (expr instanceof Num) { - shape.add(((Num) expr).type); + shape.add(Integer.parseInt(((Num) expr).num)); } else if (expr instanceof Name) { if (((Name) expr).id != "None") // Checking only literals throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index 9434d59b0..aac22cce3 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -20,6 +20,7 @@ public class TensorSpec { private String dtype; public TensorSpec() { + // Initialize to empty list this.shape = new ArrayList<>(); this.dtype = ""; } From 5d630942752be4a76855536871e76c013fe86ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Thu, 23 Mar 2023 15:27:11 -0400 Subject: [PATCH 66/70] Changing dtype --- .../hybridize/core/analysis/Function.java | 67 ++++++++++++++++++- .../hybridize/core/analysis/TensorSpec.java | 17 +++-- .../HybridizeFunctionRefactoringTest.java | 16 ++--- 3 files changed, 84 insertions(+), 16 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index 709edbed2..ef80eb4a8 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -29,6 +29,7 @@ import org.python.pydev.parser.visitors.TypeInfo; import edu.cuny.citytech.refactoring.common.core.RefactorableProgramEntity; +import edu.cuny.hunter.hybridize.core.analysis.TensorSpec.Dtype; /** * A representation of a Python function. @@ -360,6 +361,66 @@ else if (attributeEnum.equals("NAME_SCOPES")) return null; } + /** + * Classifies the dtype of TensorSpec to return a dtype of the TensorSpec autograph options. + * + * @return Dtype of TensorSpec. + */ + private Dtype determineDtypeForAutographOptions(String typeString) { + + if (typeString.equals("bfloat16")) + return Dtype.bfloat16; + else if (typeString.equals("bool")) + return Dtype.bool; + else if (typeString.equals("complex128")) + return Dtype.complex128; + else if (typeString.equals("complex64")) + return Dtype.complex64; + else if (typeString.equals("float16")) + return Dtype.float16; + else if (typeString.equals("float32")) + return Dtype.float32; + else if (typeString.equals("float64")) + return Dtype.float64; + else if (typeString.equals("half")) + return Dtype.half; + else if (typeString.equals("int16")) + return Dtype.int16; + else if (typeString.equals("int32")) + return Dtype.int32; + else if (typeString.equals("int64")) + return Dtype.int64; + else if (typeString.equals("int8")) + return Dtype.int8; + else if (typeString.equals("qint16")) + return Dtype.qint16; + else if (typeString.equals("qint32")) + return Dtype.qint32; + else if (typeString.equals("qint8")) + return Dtype.qint8; + else if (typeString.equals("quint16")) + return Dtype.quint16; + else if (typeString.equals("quint8")) + return Dtype.quint8; + else if (typeString.equals("resource")) + return Dtype.resource; + else if (typeString.equals("string")) + return Dtype.string; + else if (typeString.equals("uint16")) + return Dtype.uint16; + else if (typeString.equals("uint32")) + return Dtype.uint32; + else if (typeString.equals("uint64")) + return Dtype.uint64; + else if (typeString.equals("uint8")) + return Dtype.uint8; + else if (typeString.equals("variant")) + return Dtype.variant; + else + return null; + + } + /** * Parses expressions to retrieve information about the TensorSpecs for input signature. * @@ -383,7 +444,8 @@ else if (tensorArg instanceof List) tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); else if (tensorArg instanceof Attribute) { Attribute attrValue = (Attribute) tensorArg; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + Dtype dtype = determineDtypeForAutographOptions(((NameTok) attrValue.attr).id); + tensor.setDType(dtype); } else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } @@ -396,7 +458,8 @@ else if (keyword.value instanceof List) tensor.setShape(processTupleOrListForShape(((List) keyword.value).elts)); else if (keyword.value instanceof Attribute) { Attribute attrValue = (Attribute) keyword.value; - tensor.setDType(((Name) attrValue.value).id + "." + ((NameTok) attrValue.attr).id); + Dtype dtype = determineDtypeForAutographOptions(((NameTok) attrValue.attr).id); + tensor.setDType(dtype); } else { throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index aac22cce3..1a85e39f9 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -9,6 +9,11 @@ */ public class TensorSpec { + public enum Dtype { + float16, float32, float64, int32, int64, uint8, uint16, uint32, uint64, int16, int8, complex64, complex128, string, bool, qint8, + quint8, qint16, quint16, qint32, bfloat16, half, resource, variant + } + /** * Shape of the tensor being described by {@link TensorSpec}. */ @@ -17,15 +22,15 @@ public class TensorSpec { /** * Type of the tensor being described by {@link TensorSpec}. */ - private String dtype; + private Dtype dtype; public TensorSpec() { // Initialize to empty list this.shape = new ArrayList<>(); - this.dtype = ""; + this.dtype = Dtype.float32; } - public TensorSpec(List s, String d) { + public TensorSpec(List s, Dtype d) { this.shape = s; this.dtype = d; } @@ -42,9 +47,9 @@ public List getShape() { /** * Dtype of {@link TensorSpec}. * - * @return String of this {@link TensorSpec} dtype. + * @return Dtype of this {@link TensorSpec} dtype. */ - public String getDType() { + public Dtype getDType() { return this.dtype; } @@ -58,7 +63,7 @@ public void setShape(List s) { /** * Set dtype of {@link TensorSpec}. */ - public void setDType(String d) { + public void setDType(Dtype d) { this.dtype = d; } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index a4cf010e0..1ba2c3a22 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -92,6 +92,7 @@ import edu.cuny.hunter.hybridize.core.analysis.FunctionDefinition; import edu.cuny.hunter.hybridize.core.analysis.FunctionExtractor; import edu.cuny.hunter.hybridize.core.analysis.TensorSpec; +import edu.cuny.hunter.hybridize.core.analysis.TensorSpec.Dtype; import edu.cuny.hunter.hybridize.core.analysis.Util; import edu.cuny.hunter.hybridize.core.refactorings.HybridizeFunctionRefactoringProcessor; import edu.cuny.hunter.hybridize.core.utils.RefactoringAvailabilityTester; @@ -867,7 +868,7 @@ public void testDecoratorArguments2() throws Exception { assertNotNull(args); List shape = new ArrayList<>(); - TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); ArrayList tensors = new ArrayList<>(); tensors.add(tensor); @@ -894,8 +895,7 @@ public void testDecoratorArguments3() throws Exception { assertNotNull(args); List shape = Arrays.asList(2, 2); - - TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -946,7 +946,7 @@ public void testDecoratorArguments5() throws Exception { assertNotNull(args); List shape = new ArrayList<>(); - TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1375,7 +1375,7 @@ public void testDecoratorArguments24() throws Exception { assertNotNull(args); List shape = new ArrayList<>(); - TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1479,7 +1479,8 @@ public void testDecoratorArguments28() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - TensorSpec tensor = new TensorSpec(null, "tf.float32"); + List shape = new ArrayList<>(); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() @@ -1508,8 +1509,7 @@ public void testDecoratorArguments29() throws Exception { assertNotNull(args); List shape = Arrays.asList(2, 2); - - TensorSpec tensor = new TensorSpec(shape, "tf.float32"); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() From 0c345f006cc7527d7582f1c9f75ee2429596dde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 24 Mar 2023 11:55:05 -0400 Subject: [PATCH 67/70] fixing comments --- .../cuny/hunter/hybridize/core/analysis/Function.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index ef80eb4a8..cbd7a5c39 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -86,14 +86,14 @@ public class HybridizationParameters { /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. The values could be an optional - * tuple or value of tf.autograph.experimental.Feature values (tf.autograph.experimental.Feature.EQUALITY_OPERATORS)or - * None. + * tuple or value of tf.autograph.experimental.Feature values (e.g. + * tf.autograph.experimental.Feature.EQUALITY_OPERATORS) or None. */ private java.util.List experimentalAutographOptionsParam; /** * Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. The value could be None or a name of a - * "known" function this implements. + * "known" function this implements (e.g. embedded_matmul). */ private String experimentalImplementsParam; @@ -157,10 +157,7 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep // Example of value: Name of function or None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "None") // Checking only literals - // Default value - this.funcParam = null; - else + if (value.id != "None") // Checking only literals throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); } else { throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); From f2238cf80bb91f74a4c37516883782e2088adc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 31 Mar 2023 16:48:06 -0400 Subject: [PATCH 68/70] Remove unnecessary comments, update comments, change tensorspecs shape type --- .../hybridize/core/analysis/Function.java | 35 +++++++------------ .../hybridize/core/analysis/TensorSpec.java | 11 +++--- .../HybridizeFunctionRefactoringTest.java | 12 +++---- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java index cbd7a5c39..cf24b85b5 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java @@ -39,6 +39,10 @@ */ public class Function extends RefactorableProgramEntity { + /** + * Enumeration represents optional conversion options for tf.function argument experimental_autograph_options. + * https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/autograph/experimental/Feature + */ public enum TfAutographExperimentalFeature { ALL, AUTO_CONTROL_DEPS, ASSERT_STATEMENTS, BUILTIN_FUNCTIONS, EQUALITY_OPERATORS, LISTS, NAME_SCOPES } @@ -154,7 +158,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep NameTok name = (NameTok) keyword.arg; if (name.id.equals(FUNC)) { // Found parameter func - // Example of value: Name of function or None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id != "None") // Checking only literals @@ -164,18 +167,15 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature - // Example of value: None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id != "None") // Checking only literals throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); - // Example: (tf.TensorSpec(shape=[None], dtype=tf.float32),) } else if (keyword.value instanceof Tuple) { Tuple value = (Tuple) keyword.value; exprType[] valueElements = value.elts; ArrayList tensorSpecList = processTensorSpecs(valueElements); this.inputSignatureParam = tensorSpecList; - // Example: [tf.TensorSpec(shape=[None], dtype=tf.float32)] } else if (keyword.value instanceof List) { List value = (List) keyword.value; exprType[] valueElements = value.elts; @@ -186,7 +186,6 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep } } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph - // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "False") @@ -201,7 +200,6 @@ else if (value.id != "True") // deprecated name experimental_compile } else if (name.id.equals(JIT_COMPILE) || name.id.equals(EXPERIMENTAL_COMPILE)) { // Found parameter jit_compile or experimental_compile - // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "True") // Checking only literals @@ -220,7 +218,6 @@ else if (value.id != "None") // and deprecated name experimental_relax_shapes } else if (name.id.equals(REDUCE_RETRACING) || name.id.equals(EXPERIMENTAL_RELAX_SHAPES)) { // Found parameter reduce_retracing or experimental_relax_shapes - // Example of value: True, False if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id == "True") // Checking only literals @@ -234,11 +231,9 @@ else if (value.id != "False") // Checking only literals } } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements - // Example of value: "google.matmul_low_rank_matrix" if (keyword.value instanceof Str) { Str value = (Str) keyword.value; this.experimentalImplementsParam = value.s; - // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id != "None") // Checking only literals @@ -249,13 +244,11 @@ else if (value.id != "False") // Checking only literals } else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) { java.util.List autographExperimental = new ArrayList<>(); // Found parameter experimental_autograph_options - // Example of value: tf.autograph.experimental.Feature.EQUALITY_OPERATORS if (keyword.value instanceof Attribute) { Attribute keywordAttribute = (Attribute) keyword.value; autographExperimental.add(processAttributeForAutographOptions(keywordAttribute)); this.experimentalAutographOptionsParam = autographExperimental; // Example of value: (tf.autograph.experimental.Feature.EQUALITY_OPERATORS, - // tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS) } else if (keyword.value instanceof Tuple) { Tuple keywordTuple = (Tuple) keyword.value; exprType[] keywordExpr = keywordTuple.elts; @@ -269,7 +262,6 @@ else if (value.id != "False") // Checking only literals } } this.experimentalAutographOptionsParam = autographExperimental; - // Example of value: None } else if (keyword.value instanceof Name) { Name value = (Name) keyword.value; if (value.id != "None") // Checking only literals @@ -281,12 +273,11 @@ else if (value.id != "False") // Checking only literals } } else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) { // Found parameter experimental_follow_type_hints - // Example of value: True, False, None if (keyword.value instanceof Name) { Name value = (Name) keyword.value; - if (value.id == "True") // Checking only literals + if (value.id == "True") this.experimentaFollowTypeHintsParam = true; - else if (value.id == "False") // Checking only literals + else if (value.id == "False") this.experimentaFollowTypeHintsParam = false; else if (value.id != "None") throw new IllegalArgumentException( @@ -304,16 +295,18 @@ else if (value.id != "None") /** * Parses expressions to return a string of the shape of a TensorSpec for input signature. * - * @return String of TensorSpec shape. + * @return TensorSpec shape. */ - private java.util.List processTupleOrListForShape(exprType[] exprTupleOrList) { - java.util.List shape = new ArrayList<>(); + private java.util.List processTupleOrListForShape(exprType[] exprTupleOrList) { + java.util.List shape = new ArrayList<>(); for (exprType expr : exprTupleOrList) { if (expr instanceof Num) { shape.add(Integer.parseInt(((Num) expr).num)); } else if (expr instanceof Name) { - if (((Name) expr).id != "None") // Checking only literals + if (((Name) expr).id == "None") + shape.add((((Name) expr).id)); + else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); } else throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); @@ -326,7 +319,7 @@ private java.util.List processTupleOrListForShape(exprType[] exprTupleO /** * Parses attributes to return a string of the autograph options. * - * @return String of autograph options that contains various attributes. + * @return Autograph options that contains various attributes. */ private TfAutographExperimentalFeature processAttributeForAutographOptions(Attribute keywordAttribute) { String attributeEnum; @@ -338,8 +331,6 @@ private TfAutographExperimentalFeature processAttributeForAutographOptions(Attri } else throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); - LOG.info(attributeEnum); - if (attributeEnum.equals("ALL")) return TfAutographExperimentalFeature.ALL; else if (attributeEnum.equals("AUTO_CONTROL_DEPS")) diff --git a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java index 1a85e39f9..523b94f76 100644 --- a/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -9,6 +9,9 @@ */ public class TensorSpec { + /** + * Represents the type of the elements in a Tensor. + */ public enum Dtype { float16, float32, float64, int32, int64, uint8, uint16, uint32, uint64, int16, int8, complex64, complex128, string, bool, qint8, quint8, qint16, quint16, qint32, bfloat16, half, resource, variant @@ -17,7 +20,7 @@ public enum Dtype { /** * Shape of the tensor being described by {@link TensorSpec}. */ - private List shape; + private List shape; /** * Type of the tensor being described by {@link TensorSpec}. @@ -30,7 +33,7 @@ public TensorSpec() { this.dtype = Dtype.float32; } - public TensorSpec(List s, Dtype d) { + public TensorSpec(List s, Dtype d) { this.shape = s; this.dtype = d; } @@ -40,7 +43,7 @@ public TensorSpec(List s, Dtype d) { * * @return List of dimensions (null if the shape is unspecified) of this {@link TensorSpec} shape. */ - public List getShape() { + public List getShape() { return this.shape; } @@ -56,7 +59,7 @@ public Dtype getDType() { /** * Set shape of {@link TensorSpec}. */ - public void setShape(List s) { + public void setShape(List s) { this.shape = s; } diff --git a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java index 1ba2c3a22..4374f7d30 100644 --- a/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java +++ b/edu.cuny.hunter.hybridize.tests/test cases/edu/cuny/hunter/hybridize/tests/HybridizeFunctionRefactoringTest.java @@ -867,7 +867,7 @@ public void testDecoratorArguments2() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - List shape = new ArrayList<>(); + List shape = Arrays.asList("None"); TensorSpec tensor = new TensorSpec(shape, Dtype.float32); ArrayList tensors = new ArrayList<>(); tensors.add(tensor); @@ -894,7 +894,7 @@ public void testDecoratorArguments3() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - List shape = Arrays.asList(2, 2); + List shape = Arrays.asList(2, 2); TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); @@ -945,7 +945,7 @@ public void testDecoratorArguments5() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - List shape = new ArrayList<>(); + List shape = new ArrayList<>(); TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); @@ -1374,7 +1374,7 @@ public void testDecoratorArguments24() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - List shape = new ArrayList<>(); + List shape = Arrays.asList("None"); TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); @@ -1479,7 +1479,7 @@ public void testDecoratorArguments28() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - List shape = new ArrayList<>(); + List shape = new ArrayList<>(); TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); @@ -1508,7 +1508,7 @@ public void testDecoratorArguments29() throws Exception { Function.HybridizationParameters args = function.getHybridizationParameters(); assertNotNull(args); - List shape = Arrays.asList(2, 2); + List shape = Arrays.asList(2, 2); TensorSpec tensor = new TensorSpec(shape, Dtype.float32); List tensors = Arrays.asList(tensor); From 45bcfd2221e6170ef6d0480275e6fdec0d74ca3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 31 Mar 2023 17:03:45 -0400 Subject: [PATCH 69/70] Adding another test --- .DS_Store | Bin 0 -> 8196 bytes .../testDecoratorArguments36/in/A.py | 9 ++++++ .../in/requirements.txt | 1 + .../HybridizeFunctionRefactoringTest.java | 28 ++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 .DS_Store create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments36/in/A.py create mode 100644 edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments36/in/requirements.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..13eb1c05497568b91359294b0b5da21593ebb6fc GIT binary patch literal 8196 zcmeHM%Wl&^6ur}i#!-1>0a6w`EFrOqLTC^Vu?cwyMdBef1r~rp97nBH$Btr$P@+g) z!$0r~Z21!Yg%zATGgOI_E@%;=Vy-lE=5g}%UPg+J<&cz6w?9u)L+sz4Tb^3fMLKeU>GnA{0j`=&StTWxc61B$qfUBf&Y>L zem~eqj8%<^Liy@ICPM&V2F+4XMjRk*Y>icoi9%@#pDKC~+EnNeLnw3f+pG?(YD^R= za}vs&gdSPw2t~-zVP{Kq5>dm516^246vhYs}k zXgx$K{g8qZ(FLm0GkQupv`sCl(Q}kqs6V0-tlgCLmz4EYjOx-Dx;^9pz8sV=6E4N* z8OhoKIVgG1^XLOwSvN#Wf6=$NlJb4+SiX5&{)Q2yynp($-knJ_)U1AWhQ1fYSnXfu)d|KwUb2wv7_-N1*;EMAl z&%nIJ26l26tnA`x(~R)?&Fi9?5?&J functions = this.getFunctions(); + assertNotNull(functions); + assertEquals(1, functions.size()); + Function function = functions.iterator().next(); + assertNotNull(function); + + assertTrue(function.isHybrid()); + + Function.HybridizationParameters args = function.getHybridizationParameters(); + assertNotNull(args); + + List shape = Arrays.asList("None", 2); + TensorSpec tensor = new TensorSpec(shape, Dtype.float32); + List tensors = Arrays.asList(tensor); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertTrue(tensors.equals(args.getInputSignatureArg())); + assertFalse(args.getAutoGraphArg()); + } + } + /** * This simply tests whether we have the correct qualified name. */ From a8ddc4295ab8174f6eea8b3c0d0f81e314ea1c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tatiana=20Castro-V=C3=A9lez?= Date: Fri, 31 Mar 2023 17:04:36 -0400 Subject: [PATCH 70/70] remove file --- .DS_Store | Bin 8196 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 13eb1c05497568b91359294b0b5da21593ebb6fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHM%Wl&^6ur}i#!-1>0a6w`EFrOqLTC^Vu?cwyMdBef1r~rp97nBH$Btr$P@+g) z!$0r~Z21!Yg%zATGgOI_E@%;=Vy-lE=5g}%UPg+J<&cz6w?9u)L+sz4Tb^3fMLKeU>GnA{0j`=&StTWxc61B$qfUBf&Y>L zem~eqj8%<^Liy@ICPM&V2F+4XMjRk*Y>icoi9%@#pDKC~+EnNeLnw3f+pG?(YD^R= za}vs&gdSPw2t~-zVP{Kq5>dm516^246vhYs}k zXgx$K{g8qZ(FLm0GkQupv`sCl(Q}kqs6V0-tlgCLmz4EYjOx-Dx;^9pz8sV=6E4N* z8OhoKIVgG1^XLOwSvN#Wf6=$NlJb4+SiX5&{)Q2yynp($-knJ_)U1AWhQ1fYSnXfu)d|KwUb2wv7_-N1*;EMAl z&%nIJ26l26tnA`x(~R)?&Fi9?5?&J