parameters: (ts0, ts1, mode, can_modify=None, cannot_modify=None)
return_statement: return nb_update_inputs
docstring: Reroute the end of the tensors in each pair (t0,t1) in ts0 x ts1.
  
    This function is the back-bone of the Graph-Editor. It is essentially a thin
    wrapper on top of the tf.Operation._update_input.
  
    Given a pair of tensor t0, t1 in ts0 x ts1, this function re-route the end
    of t0 and t1 in three possible ways:
    1) The reroute mode is "a<->b" or "b<->a": the tensors' end are swapped. After
    this operation, the previous consumers of t0 are now consumers of t1 and
    vice-versa.
    2) The reroute mode is "a->b": the tensors' end of t0 are re-routed to the
    tensors's end of t1 (which are left dangling). After this operation, the
    previous consumers of t0 are still consuming t0 but the previous consumers of
    t1 are not also consuming t0. The tensor t1 has no consumer.
    3) The reroute mode is "b->a": this mode is the symmetric of the "a->b" mode.
  
    Note that this function is re-routing the end of two tensors, not the start.
    Re-routing the start of two tensors is not supported by this library. The
    reason for that is the following: TensorFlow, by design, creates a strong bond
    between an op and its output tensor. This Graph editor follows this design and
    treats an operation A and its generating tensors {t_i} as an entity which
    cannot be broken. In other words, an op cannot be detached from any of its
    output tensors, ever. But it is possible to detach an op from its input
    tensors, which is what this function concerns itself with.
  
    Warning: this function is directly manipulating the internals of the tf.Graph.
  
    Args:
      ts0: an object convertible to a list of tf.Tensor.
      ts1: an object convertible to a list of tf.Tensor.
      mode: what to do with those tensors: "a->b" or "b<->a" for swaping and
        "a->b" or "b->a" for one direction re-routing.
      can_modify: iterable of operations which can be modified. Any operation
        outside within_ops will be left untouched by this function.
      cannot_modify: iterable of operations which cannot be modified.
        Any operation within cannot_modify will be left untouched by this
        function.
    Returns:
      The number of individual modifications made by the function.
    Raises:
      TypeError: if ts0 or ts1 cannot be converted to a list of tf.Tensor.
      TypeError: if can_modify or cannot_modify is not None and cannot be
        converted to a list of tf.Operation.
docstring_summary: Reroute the end of the tensors in each pair (t0,t1) in ts0 x ts1.
docstring_tokens: Reroute the end of the tensors in each pair ( t0 t1 ) in ts0 x ts1 .
function: def _reroute_ts(ts0, ts1, mode, can_modify=None, cannot_modify=None):
    """Reroute the end of the tensors in each pair (t0,t1) in ts0 x ts1.
  
    This function is the back-bone of the Graph-Editor. It is essentially a thin
    wrapper on top of the tf.Operation._update_input.
  
    Given a pair of tensor t0, t1 in ts0 x ts1, this function re-route the end
    of t0 and t1 in three possible ways:
    1) The reroute mode is "a<->b" or "b<->a": the tensors' end are swapped. After
    this operation, the previous consumers of t0 are now consumers of t1 and
    vice-versa.
    2) The reroute mode is "a->b": the tensors' end of t0 are re-routed to the
    tensors's end of t1 (which are left dangling). After this operation, the
    previous consumers of t0 are still consuming t0 but the previous consumers of
    t1 are not also consuming t0. The tensor t1 has no consumer.
    3) The reroute mode is "b->a": this mode is the symmetric of the "a->b" mode.
  
    Note that this function is re-routing the end of two tensors, not the start.
    Re-routing the start of two tensors is not supported by this library. The
    reason for that is the following: TensorFlow, by design, creates a strong bond
    between an op and its output tensor. This Graph editor follows this design and
    treats an operation A and its generating tensors {t_i} as an entity which
    cannot be broken. In other words, an op cannot be detached from any of its
    output tensors, ever. But it is possible to detach an op from its input
    tensors, which is what this function concerns itself with.
  
    Warning: this function is directly manipulating the internals of the tf.Graph.
  
    Args:
      ts0: an object convertible to a list of tf.Tensor.
      ts1: an object convertible to a list of tf.Tensor.
      mode: what to do with those tensors: "a->b" or "b<->a" for swaping and
        "a->b" or "b->a" for one direction re-routing.
      can_modify: iterable of operations which can be modified. Any operation
        outside within_ops will be left untouched by this function.
      cannot_modify: iterable of operations which cannot be modified.
        Any operation within cannot_modify will be left untouched by this
        function.
    Returns:
      The number of individual modifications made by the function.
    Raises:
      TypeError: if ts0 or ts1 cannot be converted to a list of tf.Tensor.
      TypeError: if can_modify or cannot_modify is not None and cannot be
        converted to a list of tf.Operation.
    """
    a2b, b2a = _RerouteMode.check(mode)
    ts0 = util.make_list_of_t(ts0)
    ts1 = util.make_list_of_t(ts1)
    _check_ts_compatibility(ts0, ts1)
    if cannot_modify is not None:
      cannot_modify = frozenset(util.make_list_of_op(cannot_modify))
    if can_modify is not None:
      can_modify = frozenset(util.make_list_of_op(can_modify))
    nb_update_inputs = 0
    for t0, t1 in zip(ts0, ts1):
      if t0 is t1:
        continue  # Silently ignore identical tensors.
      consumers0 = set(t0.consumers())
      consumers1 = set(t1.consumers())
      if a2b:
        nb_update_inputs += _reroute_t(t0, t1, consumers1,
                                       can_modify, cannot_modify)
      if b2a:
        nb_update_inputs += _reroute_t(t1, t0, consumers0,
                                       can_modify, cannot_modify)
    return nb_update_inputs
function_tokens: def _reroute_ts ( ts0 , ts1 , mode , can_modify = None , cannot_modify = None ) : a2b , b2a = _RerouteMode . check ( mode ) ts0 = util . make_list_of_t ( ts0 ) ts1 = util . make_list_of_t ( ts1 ) _check_ts_compatibility ( ts0 , ts1 ) if cannot_modify is not None : cannot_modify = frozenset ( util . make_list_of_op ( cannot_modify ) ) if can_modify is not None : can_modify = frozenset ( util . make_list_of_op ( can_modify ) ) nb_update_inputs = 0 for t0 , t1 in zip ( ts0 , ts1 ) : if t0 is t1 : continue # Silently ignore identical tensors. consumers0 = set ( t0 . consumers ( ) ) consumers1 = set ( t1 . consumers ( ) ) if a2b : nb_update_inputs += _reroute_t ( t0 , t1 , consumers1 , can_modify , cannot_modify ) if b2a : nb_update_inputs += _reroute_t ( t1 , t0 , consumers0 , can_modify , cannot_modify ) return nb_update_inputs