Adds a node calling a function. This adds a `call` op to the default graph that calls the function of signature `sig`, passing the tensors in `inputs` as arguments. It returns the outputs of the call, which are one or more tensors. `sig` is OpDefArg.a `_DefinedFunction` object. You can
(sig, *inputs, **kwargs)
| 1019 | |
| 1020 | |
| 1021 | def _call(sig, *inputs, **kwargs): |
| 1022 | """Adds a node calling a function. |
| 1023 | |
| 1024 | This adds a `call` op to the default graph that calls the function |
| 1025 | of signature `sig`, passing the tensors in `inputs` as arguments. |
| 1026 | It returns the outputs of the call, which are one or more tensors. |
| 1027 | |
| 1028 | `sig` is OpDefArg.a `_DefinedFunction` object. |
| 1029 | |
| 1030 | You can pass an optional keyword parameter `name=string` to name the |
| 1031 | added operation. |
| 1032 | |
| 1033 | You can pass an optional keyword parameter `noinline=True|False` to |
| 1034 | instruct the runtime not to inline the function body into the call |
| 1035 | site. |
| 1036 | |
| 1037 | Args: |
| 1038 | sig: OpDefArg. The signature of the function. |
| 1039 | *inputs: arguments to the function. |
| 1040 | **kwargs: Optional keyword arguments. Can only contain 'name' or |
| 1041 | 'noinline'. |
| 1042 | |
| 1043 | Returns: |
| 1044 | A 2-element tuple. First element: a Tensor if the function returns a single |
| 1045 | value; a list of Tensors if the function returns multiple value; the |
| 1046 | Operation if the function returns no values. Second element: the Operation. |
| 1047 | |
| 1048 | Raises: |
| 1049 | ValueError: if the arguments are invalid. |
| 1050 | """ |
| 1051 | if len(inputs) != len(sig.input_arg): |
| 1052 | raise ValueError("Expected number of arguments: %d, received: %d" % (len( |
| 1053 | sig.input_arg), len(inputs))) |
| 1054 | name = kwargs.pop("name", None) |
| 1055 | g = ops.get_default_graph() |
| 1056 | func_name = sig.name |
| 1057 | if name is None: |
| 1058 | name = func_name |
| 1059 | attrs = _parse_kwargs_as_attrs(func_name, **kwargs) |
| 1060 | output_types = [dtypes.DType(x.type) for x in sig.output_arg] |
| 1061 | op = g.create_op( |
| 1062 | func_name, list(inputs), output_types, name=name, attrs=attrs, op_def=sig) |
| 1063 | if op.outputs: |
| 1064 | if len(op.outputs) == 1: |
| 1065 | ret = op.outputs[0] |
| 1066 | else: |
| 1067 | ret = tuple(op.outputs) |
| 1068 | else: |
| 1069 | ret = op |
| 1070 | return ret, op |
| 1071 | |
| 1072 | |
| 1073 | def _from_definition(fdef, grad_func=None): |