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 121484ed..cf24b85b 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,7 +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; @@ -23,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. @@ -32,10 +39,18 @@ */ 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 + } + /** * 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. */ @@ -62,44 +77,52 @@ public class HybridizationParameters { private static final String FUNC = "func"; /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter autograph. + * 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 autoGraphParamExists; + private boolean autoGraphParam = true; /** - * True iff this {@link Function}'s {@link decoratorsType} has 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. null represents the value of None. */ - private boolean experimentaFollowTypeHintsParamExists; + private Boolean experimentaFollowTypeHintsParam; /** - * True iff this {@link Function}'s {@link decoratorsType} has 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 (e.g. + * tf.autograph.experimental.Feature.EQUALITY_OPERATORS) or None. */ - private boolean experimentalAutographOptionsParamExists; + private java.util.List experimentalAutographOptionsParam; /** - * True iff this {@link Function}'s {@link decoratorsType} has 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 (e.g. embedded_matmul). */ - private boolean experimentalImplementsParamExists; + private String experimentalImplementsParam; /** - * True iff this {@link Function}'s {@link decoratorsType} has 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 boolean funcParamExists; + private String funcParam; /** - * True iff this {@link Function}'s {@link decoratorsType} has 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 boolean inputSignatureParamExists; + private java.util.List inputSignatureParam; /** - * True iff this {@link Function}'s {@link decoratorsType} has parameter jit_compile. + * 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 jitCompileParamExists; + private Boolean jitCompileParam; /** - * True iff 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 boolean reduceRetracingParamExists; + private boolean reduceRetracingParam; public HybridizationParameters(IProgressMonitor monitor) throws BadLocationException { FunctionDefinition functionDefinition = Function.this.getFunctionDefinition(); @@ -133,49 +156,322 @@ 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)) + if (name.id.equals(FUNC)) { // Found parameter func - this.funcParamExists = true; - else if (name.id.equals(INPUT_SIGNATURE)) + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + if (value.id != "None") // Checking only literals + throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); + } else { + throw new IllegalArgumentException("Unable to process " + FUNC + " argument."); + } + } else if (name.id.equals(INPUT_SIGNATURE)) { // Found parameter input_signature - this.inputSignatureParamExists = true; - else if (name.id.equals(AUTOGRAPH)) + 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."); + } else if (keyword.value instanceof Tuple) { + Tuple value = (Tuple) keyword.value; + exprType[] valueElements = value.elts; + ArrayList tensorSpecList = processTensorSpecs(valueElements); + this.inputSignatureParam = tensorSpecList; + } else if (keyword.value instanceof List) { + List value = (List) keyword.value; + exprType[] valueElements = value.elts; + ArrayList tensorSpecList = processTensorSpecs(valueElements); + this.inputSignatureParam = tensorSpecList; + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } else if (name.id.equals(AUTOGRAPH)) { // Found parameter autograph - this.autoGraphParamExists = true; - // 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; - // 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; - else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + if (value.id == "False") + this.autoGraphParam = false; + else if (value.id != "True") + throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); + } else { + throw new IllegalArgumentException("Unable to process " + AUTOGRAPH + " argument."); + } + // 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 or experimental_compile + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + if (value.id == "True") // Checking only literals + this.jitCompileParam = true; + else if (value.id == "False") + this.jitCompileParam = false; + else if (value.id != "None") + throw new IllegalArgumentException( + "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); + } else { + throw new IllegalArgumentException( + "Unable to process " + JIT_COMPILE + "/" + EXPERIMENTAL_COMPILE + " argument."); + } + // 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 + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + if (value.id == "True") // Checking only literals + this.reduceRetracingParam = true; + else if (value.id != "False") // Checking only literals + 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."); + } + } else if (name.id.equals(EXPERIMENTAL_IMPLEMENTS)) { // Found parameter experimental_implements - this.experimentalImplementsParamExists = true; - else if (name.id.equals(EXPERIMENTAL_AUTOGRAPH_OPTIONS)) + if (keyword.value instanceof Str) { + Str value = (Str) keyword.value; + this.experimentalImplementsParam = value.s; + } else if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + 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 - this.experimentalAutographOptionsParamExists = true; - else if (name.id.equals(EXPERIMENTAL_FOLLOW_TYPE_HINTS)) + 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, + } else if (keyword.value instanceof Tuple) { + Tuple keywordTuple = (Tuple) keyword.value; + exprType[] keywordExpr = keywordTuple.elts; + for (exprType expr : keywordExpr) { + if (expr instanceof Attribute) { + Attribute keywordAttribute = (Attribute) expr; + autographExperimental.add(processAttributeForAutographOptions(keywordAttribute)); + } else { + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " arguments"); + } + } + this.experimentalAutographOptionsParam = autographExperimental; + } else if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + if (value.id != "None") // Checking only literals + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); + } 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; + if (keyword.value instanceof Name) { + Name value = (Name) keyword.value; + if (value.id == "True") + this.experimentaFollowTypeHintsParam = true; + else if (value.id == "False") + this.experimentaFollowTypeHintsParam = false; + else if (value.id != "None") + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " argument."); + } else { + throw new IllegalArgumentException( + "Unable to process " + EXPERIMENTAL_FOLLOW_TYPE_HINTS + " arguments"); + } + } } } } // else, tf.function is used without parameters. } + /** + * Parses expressions to return a string of the shape of a TensorSpec for input signature. + * + * @return TensorSpec shape. + */ + 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") + 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."); + } + + return shape; + + } + + /** + * Parses attributes to return a string of the autograph options. + * + * @return Autograph options that contains various attributes. + */ + private TfAutographExperimentalFeature processAttributeForAutographOptions(Attribute keywordAttribute) { + String attributeEnum; + Attribute tempAttr = keywordAttribute; + + if (tempAttr.value instanceof Attribute) { + NameTok valueAttribute = (NameTok) tempAttr.attr; + attributeEnum = valueAttribute.id; + } else + throw new IllegalArgumentException("Unable to process " + EXPERIMENTAL_AUTOGRAPH_OPTIONS + " argument."); + + 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; + } + + /** + * 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. + * + * @return Array of TensorSpecs with the parsed information. + */ + private ArrayList processTensorSpecs(exprType[] valueElements) { + ArrayList tensorSpecList = new ArrayList<>(); + 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)); + else if (tensorArg instanceof List) + tensor.setShape(processTupleOrListForShape(((List) tensorArg).elts)); + else if (tensorArg instanceof Attribute) { + Attribute attrValue = (Attribute) tensorArg; + Dtype dtype = determineDtypeForAutographOptions(((NameTok) attrValue.attr).id); + tensor.setDType(dtype); + } 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; + Dtype dtype = determineDtypeForAutographOptions(((NameTok) attrValue.attr).id); + tensor.setDType(dtype); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } + tensorSpecList.add(tensor); + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } else { + throw new IllegalArgumentException("Unable to process " + INPUT_SIGNATURE + " argument."); + } + } + return tensorSpecList; + } + /** * 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; + // True is the default value + return (this.autoGraphParam != true); + } /** @@ -184,7 +480,8 @@ public boolean hasAutoGraphParam() { * @return True iff this {@link decoratorType} has parameter experimental_autograph_options. */ public boolean hasExperimentalAutographOptParam() { - return this.experimentalAutographOptionsParamExists; + // None is the default value + return (this.experimentalAutographOptionsParam != null); } /** @@ -193,7 +490,8 @@ public boolean hasExperimentalAutographOptParam() { * @return True iff this {@link decoratorType} has parameter experimental_implements. */ public boolean hasExperimentalImplementsParam() { - return this.experimentalImplementsParamExists; + // None is the default value + return (this.experimentalImplementsParam != null); } /** @@ -202,16 +500,18 @@ public boolean hasExperimentalImplementsParam() { * @return True iff this {@link decoratorType} has parameter experimental_follow_type_hints. */ public boolean hasExperimentalFollowTypeHintsParam() { - return this.experimentaFollowTypeHintsParamExists; + // None is the default value + return (this.experimentaFollowTypeHintsParam != null); } /** - * 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. */ public boolean hasFuncParam() { - return this.funcParamExists; + // None is the default value + return (this.funcParam != null); } /** @@ -220,7 +520,8 @@ public boolean hasFuncParam() { * @return True iff this {@link decoratorType} has parameter input_signature. */ public boolean hasInputSignatureParam() { - return this.inputSignatureParamExists; + // None is the default value + return (this.inputSignatureParam != null); } /** @@ -229,7 +530,8 @@ public boolean hasInputSignatureParam() { * @return True iff this {@link decoratorType} has parameter jit_compile. */ public boolean hasJitCompileParam() { - return this.jitCompileParamExists; + // None is the default value + return (this.jitCompileParam != null); } /** @@ -238,7 +540,98 @@ public boolean hasJitCompileParam() { * @return True iff this {@link Function} has parameter reduce_retracing. */ public boolean hasReduceRetracingParam() { - return this.reduceRetracingParamExists; + // False is the default value + return (this.reduceRetracingParam != false); + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter autograph. + * + * @return boolean of this {@link decoratorType} parameter autograph. + */ + public boolean getAutoGraphArg() { + return this.autoGraphParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. + * + * @return String of this {@link decoratorType} parameter experimental_autograph_options. + */ + public java.util.List getExperimentalAutographOptArg() { + return this.experimentalAutographOptionsParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_implements. + * + * @return String of this {@link decoratorType} parameter experimental_implements. + */ + public String getExperimentalImplementsArg() { + return this.experimentalImplementsParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_follow_type_hints. + * + * @return Boolean of this {@link decoratorType} parameter experimental_follow_type_hints. + */ + public Boolean getExperimentalFollowTypeHintsArg() { + return this.experimentaFollowTypeHintsParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter func. + * + * @return String of this {@link decoratorType} parameter func. + */ + public String getFuncArg() { + return this.funcParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter input_signature. + * + * @return ArrayList of TensorSpecs of this {@link decoratorType} parameter input_signature. + */ + public java.util.List getInputSignatureArg() { + return this.inputSignatureParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter jit_compile. + * + * @return Boolean of this {@link decoratorType} parameter jit_compile. + */ + public Boolean getJitCompileArg() { + return this.jitCompileParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter reduce_retracing. + * + * @return boolean of this {@link Function} parameter reduce_retracing. + */ + public boolean getReduceRetracingArg() { + return this.reduceRetracingParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_compile. + * + * @return Boolean of this {@link decoratorType} parameter experimental_compile. + */ + public Boolean getExperimentalCompileArg() { + return this.jitCompileParam; + } + + /** + * Value of {@link Function}'s {@link decoratorsType} parameter experimental_relax_shapes. + * + * @return boolean of this {@link Function} parameter experimental_relax_shapes. + */ + public boolean getExperimentalRelaxShapeArg() { + return this.reduceRetracingParam; } } 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 00000000..523b94f7 --- /dev/null +++ b/edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/TensorSpec.java @@ -0,0 +1,93 @@ +package edu.cuny.hunter.hybridize.core.analysis; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * A representation of a tf.Tensorspec which describes a tf.Tensor + */ +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 + } + + /** + * Shape of the tensor being described by {@link TensorSpec}. + */ + private List shape; + + /** + * Type of the tensor being described by {@link TensorSpec}. + */ + private Dtype dtype; + + public TensorSpec() { + // Initialize to empty list + this.shape = new ArrayList<>(); + this.dtype = Dtype.float32; + } + + public TensorSpec(List s, Dtype d) { + this.shape = s; + this.dtype = d; + } + + /** + * Shape of {@link TensorSpec}. + * + * @return List of dimensions (null if the shape is unspecified) of this {@link TensorSpec} shape. + */ + public List getShape() { + return this.shape; + } + + /** + * Dtype of {@link TensorSpec}. + * + * @return Dtype of this {@link TensorSpec} dtype. + */ + public Dtype getDType() { + return this.dtype; + } + + /** + * Set shape of {@link TensorSpec}. + */ + public void setShape(List s) { + this.shape = s; + } + + /** + * Set dtype of {@link TensorSpec}. + */ + public void setDType(Dtype 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/resources/HybridizeFunction/testDecoratorArguments/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py new file mode 100644 index 00000000..700a01ab --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(input_signature=None) +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 00000000..b154f958 --- /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 00000000..1457b526 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments10/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(jit_compile=None) +def func(): + pass + + +if __name__ == '__main__': + 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 new file mode 100644 index 00000000..b154f958 --- /dev/null +++ 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 new file mode 100644 index 00000000..4901c4d9 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/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/testDecoratorArguments11/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments11/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /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 00000000..0c360ead --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments12/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(reduce_retracing=False) +def func(): + pass + + +if __name__ == '__main__': + func() 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 00000000..b154f958 --- /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/testDecoratorArguments13/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments13/in/A.py new file mode 100644 index 00000000..a92f73e2 --- /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 00000000..b154f958 --- /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 00000000..0a6cf5e0 --- /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="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 00000000..b154f958 --- /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 00000000..58b7a675 --- /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 00000000..b154f958 --- /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 00000000..b21991d1 --- /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 00000000..b154f958 --- /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 00000000..15284b7d --- /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 00000000..b154f958 --- /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 00000000..88bd5193 --- /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 00000000..b154f958 --- /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 00000000..a1a14268 --- /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 00000000..b154f958 --- /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 new file mode 100644 index 00000000..69b144c7 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/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/testDecoratorArguments2/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments2/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /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/testDecoratorArguments20/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments20/in/A.py new file mode 100644 index 00000000..1618ed3d --- /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 00000000..b154f958 --- /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 00000000..136ed83a --- /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 00000000..b154f958 --- /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 00000000..2c21453e --- /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 00000000..b154f958 --- /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 00000000..12d83503 --- /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 00000000..b154f958 --- /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 00000000..2ea60445 --- /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) 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 00000000..b154f958 --- /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 00000000..79ab565c --- /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) 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 new file mode 100644 index 00000000..041bb974 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/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/testDecoratorArguments25/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments25/in/requirements.txt new file mode 100644 index 00000000..8b137891 --- /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 00000000..2b39f30c --- /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() 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 new file mode 100644 index 00000000..041bb974 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/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/testDecoratorArguments26/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments26/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /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 00000000..981dfe88 --- /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)) 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 00000000..b154f958 --- /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/testDecoratorArguments28/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py new file mode 100644 index 00000000..f03f6d91 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/A.py @@ -0,0 +1,13 @@ +import tensorflow as tf + +var = (tf.TensorSpec(shape=[None], dtype=tf.float32),) + + +@tf.function(input_signature=var) +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/testDecoratorArguments28/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments28/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /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/resources/HybridizeFunction/testDecoratorArguments29/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py new file mode 100644 index 00000000..9dc80af5 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/A.py @@ -0,0 +1,13 @@ +import tensorflow as tf + +var = (2, 2) + + +@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], [2.0, 2.0])) + func(number) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments29/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 00000000..47e13d13 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments3/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(input_signature=(tf.TensorSpec(shape=(2, 2), dtype=tf.float32),)) +def func(x): + return x + +if __name__ == '__main__': + number = tf.constant(([1.0, 1.0],[2.0,2.0])) + func(number) 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 00000000..b154f958 --- /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/testDecoratorArguments30/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py new file mode 100644 index 00000000..9ec26538 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + +var = False + +@tf.function(autograph=var) +def func(x): + return x + + +if __name__ == '__main__': + func(tf.constant(1)) diff --git a/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments30/in/requirements.txt @@ -0,0 +1 @@ +tensorflow==2.9.3 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 00000000..4b1acf37 --- /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 00000000..b154f958 --- /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 00000000..18f7354f --- /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 00000000..b154f958 --- /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 00000000..14d52c43 --- /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 00000000..b154f958 --- /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 00000000..c6f58a6a --- /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 00000000..b154f958 --- /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 00000000..a4f493ff --- /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 00000000..b154f958 --- /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/resources/HybridizeFunction/testDecoratorArguments36/in/A.py b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments36/in/A.py new file mode 100644 index 00000000..a7938173 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments36/in/A.py @@ -0,0 +1,9 @@ +import tensorflow as tf + +@tf.function(input_signature=(tf.TensorSpec(shape=[None, 2], dtype=tf.float32),)) +def func(x): + return x + +if __name__ == '__main__': + 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/testDecoratorArguments36/in/requirements.txt b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments36/in/requirements.txt new file mode 100644 index 00000000..b154f958 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments36/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 00000000..285bdb91 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments4/in/A.py @@ -0,0 +1,11 @@ +import tensorflow as tf + + +@tf.function(input_signature=(tf.TensorSpec([]), tf.TensorSpec([]))) +def func(tensor, integer): + return tensor + integer + + +if __name__ == '__main__': + input = tf.constant(0.0) + func(input, 2) 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 00000000..b154f958 --- /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 00000000..0b0820d5 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments5/in/A.py @@ -0,0 +1,8 @@ +import tensorflow as tf + +@tf.function(input_signature=[tf.TensorSpec([], tf.float32)]) +def func(x): + return x + +if __name__ == '__main__': + func(tf.constant(2.)) 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 00000000..b154f958 --- /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 00000000..5ca325d8 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments6/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(autograph=False) +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 00000000..b154f958 --- /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 00000000..619ec3d9 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments7/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(autograph=True) +def func(): + pass + + +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 00000000..b154f958 --- /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 00000000..e300f814 --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments8/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(jit_compile=True) +def func(): + pass + + +if __name__ == '__main__': + func() 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 00000000..b154f958 --- /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 00000000..4e80146a --- /dev/null +++ b/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments9/in/A.py @@ -0,0 +1,10 @@ +import tensorflow as tf + + +@tf.function(jit_compile=False) +def func(): + pass + + +if __name__ == '__main__': + func() 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 00000000..b154f958 --- /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 4f6f3ba5..61d3e9cb 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,8 +88,11 @@ 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; +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; @@ -826,6 +829,872 @@ 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()) + assertNull(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); + + List shape = Arrays.asList("None"); + TensorSpec tensor = new TensorSpec(shape, Dtype.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()) + assertTrue(tensors.equals(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); + + List shape = Arrays.asList(2, 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())); + } + + /** + * 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); + + TensorSpec tensor = new TensorSpec(); + List tensors = Arrays.asList(tensor, tensor); + + if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertTrue(tensors.equals(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); + + 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() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertTrue(tensors.equals(args.getInputSignatureArg())); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument autograph. + */ + @Test + 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()) + assertFalse(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(); + 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()) + assertTrue(args.getAutoGraphArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument jit_compile. + */ + @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); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertTrue(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()) + assertFalse(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()) + assertNull(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()) + assertTrue(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()) + assertFalse(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 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("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()) + assertNull(args.getExperimentalImplementsArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + */ + @Test + public void testDecoratorArguments16() 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); + + 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(feature, args.getExperimentalAutographOptArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + */ + @Test + 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); + + List feature = Arrays.asList(TfAutographExperimentalFeature.ALL); + + if (!args.hasFuncParam() && !args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) + assertEquals(feature, 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); + + 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(feature, args.getExperimentalAutographOptArg()); + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument experimental_autograph_options + */ + @Test + public void testDecoratorArguments19() 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()) + assertNull(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()) + assertTrue(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()) + assertFalse(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()) + assertNull(args.getExperimentalFollowTypeHintsArg()); + } + + /** + * Test for #136. This simply tests whether we can identify when there are no tf.function args. + */ + @Test + public void testDecoratorArguments23() 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); + + // 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); + } + + /** + * 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); + + List shape = Arrays.asList("None"); + 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()); + } + } + + /** + * Test for #136. Test custom decorator with the same parameter names as tf.function. + */ + @Test + public void testDecoratorArguments25() 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 testDecoratorArguments26() 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()) { + assertFalse(args.getAutoGraphArg()); + assertTrue(args.getInputSignatureArg() == null); + } + + } + + /** + * Test for #136. Tests two different tf.functions. Should only count the parameters of the last one. + */ + @Test + public void testDecoratorArguments27() 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()) { + assertTrue(args.getJitCompileArg()); + assertTrue(args.getAutoGraphArg()); // default value of autograph + } + + } + + /** + * 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 { + 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); + + 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() + && !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() + && !args.hasExperimentalFollowTypeHintsParam()) { + assertTrue(tensors.equals(args.getInputSignatureArg())); + } + + } + + /** + * 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 testDecoratorArguments29() 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); + + List shape = Arrays.asList(2, 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())); + } + + } + + /** + * 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()) { + assertFalse(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()) { + assertFalse(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()) { + assertFalse(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); + + 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(feature, 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()) { + assertTrue(args.getExperimentalFollowTypeHintsArg()); + } + } + + /** + * Test for #136. This simply tests whether we can get the tf.function argument input_signature. + */ + @Test + public void testDecoratorArguments36() 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); + + 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. */ @@ -1610,8 +2479,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 {