Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. # Goals:
  2. # * Convert values to Tensors if it contains constants.
  3. # * Verify that values is a list if that matches the input_arg's
  4. # type.
  5. # * If the input_arg's type is determined by attrs, either set
  6. # those attrs and validate those attr values are legal (if
  7. # they have not yet been set) or validate the input matches
  8. # the type indicated by the attrs (if they have already been
  9. # inferred via an earlier input).
  10. # * If the input_arg has an explicit type, make sure the input
  11. # conforms.
  12.  
  13. if _IsListParameter(input_arg):
  14. """
  15. (Skip line 408~470)
  16. """
  17. types = [x.dtype for x in values]
  18. inputs.extend(values)
  19. else:
  20. # In cases where we have an expected type, try to convert non-Tensor
  21. # arguments to that type.
  22. dtype = None
  23. default_dtype = None
  24. if input_arg.type != types_pb2.DT_INVALID:
  25. dtype = input_arg.type
  26. elif input_arg.type_attr in attrs:
  27. dtype = attrs[input_arg.type_attr]
  28. elif input_arg.type_attr in default_type_attr_map:
  29. # The dtype could not be inferred solely from the inputs,
  30. # so we prefer the attr's default, so code that adds a new attr
  31. # with a default is backwards compatible.
  32. default_dtype = default_type_attr_map[input_arg.type_attr]
  33.  
  34. try:
  35. values = ops.internal_convert_to_tensor(
  36. values,
  37. name=input_arg.name,
  38. dtype=dtype,
  39. as_ref=input_arg.is_ref,
  40. preferred_dtype=default_dtype)
  41. except TypeError as err:
  42. """
  43. (Skip line 497~531)
  44. """
  45.  
  46. types = [values.dtype]
  47. inputs.append(values)
  48. base_types = [x.base_dtype for x in types]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement