code: def sg_reuse(tensor, **opt):
      r
      opt = tf.sg_opt(opt)
      assert hasattr(tensor, '_sugar'), 'cannot reuse this node.'
      assert opt.input is not None, 'input is mandatory.'
  
      # get all nodes in this graph
      nodes, prev = [tensor], tensor._sugar.prev
      while prev is not None:
          nodes = [prev] + nodes
          prev = prev._sugar.prev if hasattr(prev, '_sugar') else None
  
      # create graph again for this input
      out = opt.input
      for node in nodes[1:]:  # exclude head node
          if node._sugar.is_layer:
              fn = tf.sg_layer_func(node._sugar.func)
              if node._sugar.arg.scope_name:
                  with tf.variable_scope(node._sugar.arg.scope_name):
                      out = fn(out, **(node._sugar.arg + tf.sg_opt(name=node._sugar.name, reuse=True)))
              else:
                  out = fn(out, **(node._sugar.arg + tf.sg_opt(name=node._sugar.name, reuse=True)))
          else:
              out = node._sugar.func(out, node._sugar.arg)
  
      return out
docs: r""" Reconstruct computational graph of `tensor` so all the parameters
      can be reused and replace its input tensor with `opt.input`.
  
      Args:
        tensor: A `Tensor` (automatically given by chaining).
        **opt:
          input: A `Tensor` that will replace the original input tensor.
  
      Returns:
        Reconstructed tensor nodes.