Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Goals:
- # * Convert values to Tensors if it contains constants.
- # * Verify that values is a list if that matches the input_arg's
- # type.
- # * If the input_arg's type is determined by attrs, either set
- # those attrs and validate those attr values are legal (if
- # they have not yet been set) or validate the input matches
- # the type indicated by the attrs (if they have already been
- # inferred via an earlier input).
- # * If the input_arg has an explicit type, make sure the input
- # conforms.
- if _IsListParameter(input_arg):
- """
- (Skip line 408~470)
- """
- types = [x.dtype for x in values]
- inputs.extend(values)
- else:
- # In cases where we have an expected type, try to convert non-Tensor
- # arguments to that type.
- dtype = None
- default_dtype = None
- if input_arg.type != types_pb2.DT_INVALID:
- dtype = input_arg.type
- elif input_arg.type_attr in attrs:
- dtype = attrs[input_arg.type_attr]
- elif input_arg.type_attr in default_type_attr_map:
- # The dtype could not be inferred solely from the inputs,
- # so we prefer the attr's default, so code that adds a new attr
- # with a default is backwards compatible.
- default_dtype = default_type_attr_map[input_arg.type_attr]
- try:
- values = ops.internal_convert_to_tensor(
- values,
- name=input_arg.name,
- dtype=dtype,
- as_ref=input_arg.is_ref,
- preferred_dtype=default_dtype)
- except TypeError as err:
- """
- (Skip line 497~531)
- """
- types = [values.dtype]
- inputs.append(values)
- base_types = [x.base_dtype for x in types]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement