コード例 #1
0
def create_dummy_computation_tuple():
    """Returns a tuple computation and type."""
    names = ['a', 'b', 'c']
    fn, fn_type = create_dummy_computation_tensorflow_constant()
    element_value = pb.Computation(
        type=type_serialization.serialize_type(fn_type),
        call=pb.Call(function=fn))
    element_type = fn_type.result
    elements = [pb.Struct.Element(name=n, value=element_value) for n in names]
    type_signature = computation_types.StructType(
        (n, element_type) for n in names)
    value = pb.Computation(
        type=type_serialization.serialize_type(type_signature),
        struct=pb.Struct(element=elements))
    return value, type_signature
コード例 #2
0
def create_lambda_empty_struct() -> pb.Computation:
  """Returns a lambda computation returning an empty struct.

  Has the type signature:

  ( -> <>)

  Returns:
    An instance of `pb.Computation`.
  """
  result_type = computation_types.StructType([])
  type_signature = computation_types.FunctionType(None, result_type)
  result = pb.Computation(
      type=type_serialization.serialize_type(result_type),
      struct=pb.Struct(element=[]))
  fn = pb.Lambda(parameter_name=None, result=result)
  # We are unpacking the lambda argument here because `lambda` is a reserved
  # keyword in Python, but it is also the name of the parameter for a
  # `pb.Computation`.
  # https://developers.google.com/protocol-buffers/docs/reference/python-generated#keyword-conflicts
  return pb.Computation(
      type=type_serialization.serialize_type(type_signature), **{'lambda': fn})  # pytype: disable=wrong-keyword-args