def _setup()

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


  def _setup(self, root_block_like, interactive_mode):
    """Sets up the compiler."""
    self._root = (
        tensorflow_fold.blocks.blocks.convert_to_block(
            root_block_like))
    self._ctx = _CompilerContext()
    self._compile_blocks()

    out_type = self.root.output_type
    terminal_ts = list(out_type.terminal_types())
    tensor_ts = [t for t in terminal_ts if isinstance(t, tdt.TensorType)]

    if not interactive_mode:
      if any(isinstance(t, tdt.PyObjectType) for t in terminal_ts):
        raise TypeError('root outputs must all be tensors: %s' % out_type)
      if not (tensor_ts or self._ctx.metric_ops):
        raise TypeError('root must have at least one output or metric tensor: '
                        '%s' % out_type)
      subtypes = [out_type]
      while subtypes:
        subtype = subtypes.pop()
        if isinstance(subtype, tdt.SequenceType):
          raise TypeError('root output may not contain sequences %s' % out_type)
        if isinstance(subtype, tdt.TupleType):
          subtypes.extend(subtype)

      flatten = out_type.flatten
      if not tensor_ts:  # no tensor outputs
        self._extract_tensor_outputs = None
      else:  # all outputs will be tensors
        self._extract_tensor_outputs = flatten
    self._dry = self._ctx.create_tagged_loom(tensor_ts, dry_run=True)
    return self