parameters: (structure, arg_names=None)
return_statement: return nest.pack_sequence_as(structure, mapped)
docstring: Convert a potentially nested structure to a signature.
  
    Args:
      structure: Structure to convert, where top level collection is a list or a
        tuple.
      arg_names: Optional list of arguments that has equal number of elements as
        `structure` and is used for naming corresponding TensorSpecs.
  
    Returns:
      Identical structure that has TensorSpec objects instead of Tensors and
      UnknownArgument instead of any unsupported types.
docstring_summary: Convert a potentially nested structure to a signature.
docstring_tokens: Convert a potentially nested structure to a signature .
function: def convert_structure_to_signature(structure, arg_names=None):
    """Convert a potentially nested structure to a signature.
  
    Args:
      structure: Structure to convert, where top level collection is a list or a
        tuple.
      arg_names: Optional list of arguments that has equal number of elements as
        `structure` and is used for naming corresponding TensorSpecs.
  
    Returns:
      Identical structure that has TensorSpec objects instead of Tensors and
      UnknownArgument instead of any unsupported types.
    """
    def encode_arg(arg, path):
      """A representation for this argument, for converting into signatures."""
      if isinstance(arg, ops.Tensor):
        user_specified_name = None
        try:
          user_specified_name = compat.as_str(
              arg.op.get_attr("_user_specified_name"))
        except ValueError:
          pass
  
        if path and user_specified_name and user_specified_name != path[0]:
          # The user has explicitly named the argument differently than the name
          # of the function argument.
          name = user_specified_name
        else:
          name = "/".join(str(p) for p in path)
        return tensor_spec.TensorSpec(arg.shape, arg.dtype, name)
      if isinstance(arg, composite_tensor.CompositeTensor):
        # TODO(b/133606651) Do we need to inject arg_name?
        return arg._type_spec  # pylint: disable=protected-access
      if isinstance(arg, resource_variable_ops.BaseResourceVariable):
        name = "/".join(str(p) for p in path)
        return resource_variable_ops.VariableSpec(arg.shape, arg.dtype, name,
                                                  trainable=arg.trainable)
      if isinstance(arg, (
          int,
          float,
          bool,
          str,
          type(None),
          dtypes.DType,
          tensor_spec.TensorSpec,
          type_spec.TypeSpec,
      )):
        return arg
      return UnknownArgument()
  
    # We are using the flattened paths to name the TensorSpecs. We need an
    # explicit name for them downstream.
    flattened = nest.flatten_with_tuple_paths(structure)
    if arg_names:
      if len(arg_names) != len(structure):
        raise ValueError(
            "Passed in arg_names don't match actual signature (%s)." % arg_names)
      # Replace all top-level names with their actual arg_names. If a path before
      # was "(2,'a',1)", it will become "(arg_names[2],'a',1)".
      flattened = [
          ((arg_names[path[0]],) + path[1:], arg) for path, arg in flattened
      ]
  
    mapped = [encode_arg(arg, path) for path, arg in flattened]
    return nest.pack_sequence_as(structure, mapped)
function_tokens: def convert_structure_to_signature ( structure , arg_names = None ) : def encode_arg ( arg , path ) : """A representation for this argument, for converting into signatures.""" if isinstance ( arg , ops . Tensor ) : user_specified_name = None try : user_specified_name = compat . as_str ( arg . op . get_attr ( "_user_specified_name" ) ) except ValueError : pass if path and user_specified_name and user_specified_name != path [ 0 ] : # The user has explicitly named the argument differently than the name # of the function argument. name = user_specified_name else : name = "/" . join ( str ( p ) for p in path ) return tensor_spec . TensorSpec ( arg . shape , arg . dtype , name ) if isinstance ( arg , composite_tensor . CompositeTensor ) : # TODO(b/133606651) Do we need to inject arg_name? return arg . _type_spec # pylint: disable=protected-access if isinstance ( arg , resource_variable_ops . BaseResourceVariable ) : name = "/" . join ( str ( p ) for p in path ) return resource_variable_ops . VariableSpec ( arg . shape , arg . dtype , name , trainable = arg . trainable ) if isinstance ( arg , ( int , float , bool , str , type ( None ) , dtypes . DType , tensor_spec . TensorSpec , type_spec . TypeSpec , ) ) : return arg return UnknownArgument ( ) # We are using the flattened paths to name the TensorSpecs. We need an # explicit name for them downstream. flattened = nest . flatten_with_tuple_paths ( structure ) if arg_names : if len ( arg_names ) != len ( structure ) : raise ValueError ( "Passed in arg_names don't match actual signature (%s)." % arg_names ) # Replace all top-level names with their actual arg_names. If a path before # was "(2,'a',1)", it will become "(arg_names[2],'a',1)". flattened = [ ( ( arg_names [ path [ 0 ] ] , ) + path [ 1 : ] , arg ) for path , arg in flattened ] mapped = [ encode_arg ( arg , path ) for path , arg in flattened ] return nest . pack_sequence_as ( structure , mapped )