in Synthesis_incorporation/value_search/function_operation.py [0:0]
def __init__(self, function_info):
"""Creates a FunctionOperation.
Args:
function_info: A tf_functions.FunctionInfo.
"""
(
function_name,
arg_names,
constant_kwargs,
) = torch_functions.parse_function_info_name(function_info)
self._function_obj = tf_coder_utils.get_torch_function(function_name)
docstring = self._function_obj.__doc__
if not docstring:
print(
"Warning: could not get docstring for function {}".format(function_name)
)
docstring = ""
# Make sure the function and argument names appear in the docstring. (Args
# should already appear in the docstring "Args" section though.)
docstring += "\n" + function_info.name
# If 'reduce_max' is the function name, make sure 'reduce' and 'max' also
# appear as separate words. Ditto for argument names as well.
docstring += "\n" + function_info.name.replace("_", " ")
# Upweight the function name (moreso than the argument names).
function_name_without_torch = re.sub(r"^torch\.", "", function_name)
docstring += ("\n" + function_name_without_torch) * 4
if "_" in function_name_without_torch:
docstring += ("\n" + function_name_without_torch.replace("_", " ")) * 2
metadata = operation_base.OperationMetadata(docstring=docstring)
super(FunctionOperation, self).__init__(
num_args=len(arg_names), weight=function_info.weight, metadata=metadata
)
self.function_info = function_info
self.function_name = function_name
self.arg_names = arg_names
self.constant_kwargs = constant_kwargs
operation_filtering.add_filters_to_function_operation(self)