A representation for this argument, for converting into signatures.
(arg, path)
| 89 | UknownArgument instead of any unsupported types. |
| 90 | """ |
| 91 | def encode_arg(arg, path): |
| 92 | """A representation for this argument, for converting into signatures.""" |
| 93 | if isinstance(arg, ops.Tensor): |
| 94 | user_specified_name = None |
| 95 | try: |
| 96 | user_specified_name = compat.as_str( |
| 97 | arg.op.get_attr("_user_specified_name")) |
| 98 | except ValueError: |
| 99 | pass |
| 100 | |
| 101 | if path and user_specified_name and user_specified_name != path[0]: |
| 102 | # The user has explicitly named the argument differently than the name |
| 103 | # of the function argument. |
| 104 | name = user_specified_name |
| 105 | else: |
| 106 | name = "/".join([str(p) for p in path]) |
| 107 | return tensor_spec.TensorSpec(arg.shape, arg.dtype, name) |
| 108 | if isinstance(arg, composite_tensor.CompositeTensor): |
| 109 | # TODO(b/133606651) Do we need to inject arg_name? |
| 110 | return arg._type_spec # pylint: disable=protected-access |
| 111 | if isinstance(arg, ( |
| 112 | int, |
| 113 | float, |
| 114 | bool, |
| 115 | type(None), |
| 116 | dtypes.DType, |
| 117 | tensor_spec.TensorSpec, |
| 118 | type_spec.TypeSpec, |
| 119 | )): |
| 120 | return arg |
| 121 | return UnknownArgument() |
| 122 | |
| 123 | # We are using the flattened paths to name the TensorSpecs. We need an |
| 124 | # explicit name for them downstream. |
no test coverage detected