def _types_backward()

in tensorflow_fold/blocks/blocks.py [0:0]


  def _types_backward(self, child):
    in_type = child.input_type
    if in_type is None: return
    wires = self._child_input_wire_dict.get(child)
    if wires is None: return
    if isinstance(in_type, tdt.PyObjectType) or len(wires) == 1:
      in_type = (in_type,) * len(wires)
    elif len(wires) != len(in_type):
      raise TypeError('block %s has %d inputs but expects %d' %
                      (child, len(wires), len(in_type)))
    for i, ((block, index), itype) in enumerate(zip(wires, in_type)):
      if index is None:
        block.set_output_type(itype)
      elif block.output_type is not None and block.output_type[index] != itype:
        # We don't propagate partial type information backward because
        # we don't currently have a representation of partial tuple
        # types (e.g. A tuple whose first item is a tensor).
        if len(wires) == 1:
          raise TypeError(
              'output %d of block %s has type %s; cannot connect'
              'it to block %s with input type %s' %
              (index, block, block.output_type[index], child, in_type))
        raise TypeError(
            'output %d of block %s has type %s; cannot connect'
            'it to input %d of block %s having type %s' %
            (index, block, block.output_type[index], i, child, itype))