Reroute the end of the tensors (t0,t1). Warning: this function is directly manipulating the internals of the `tf.Graph`. Args: t0: a tf.Tensor. t1: a tf.Tensor. consumers1: The consumers of t1 which needs to be rerouted. can_modify: iterable of operations which can be modifie
(t0, t1, consumers1, can_modify=None, cannot_modify=None)
| 99 | |
| 100 | |
| 101 | def _reroute_t(t0, t1, consumers1, can_modify=None, cannot_modify=None): |
| 102 | """Reroute the end of the tensors (t0,t1). |
| 103 | |
| 104 | Warning: this function is directly manipulating the internals of the |
| 105 | `tf.Graph`. |
| 106 | |
| 107 | Args: |
| 108 | t0: a tf.Tensor. |
| 109 | t1: a tf.Tensor. |
| 110 | consumers1: The consumers of t1 which needs to be rerouted. |
| 111 | can_modify: iterable of operations which can be modified. Any operation |
| 112 | outside within_ops will be left untouched by this function. |
| 113 | cannot_modify: iterable of operations which cannot be modified. |
| 114 | Any operation within cannot_modify will be left untouched by this |
| 115 | function. |
| 116 | Returns: |
| 117 | The number of individual modifications made by the function. |
| 118 | """ |
| 119 | nb_update_inputs = 0 |
| 120 | if can_modify is not None: |
| 121 | consumers1 &= can_modify |
| 122 | if cannot_modify is not None: |
| 123 | consumers1 -= cannot_modify |
| 124 | consumers1_indices = {} |
| 125 | for consumer1 in consumers1: |
| 126 | consumers1_indices[consumer1] = [i for i, t in enumerate(consumer1.inputs) |
| 127 | if t is t1] |
| 128 | for consumer1 in consumers1: |
| 129 | for i in consumers1_indices[consumer1]: |
| 130 | consumer1._update_input(i, t0) # pylint: disable=protected-access |
| 131 | nb_update_inputs += 1 |
| 132 | return nb_update_inputs |
| 133 | |
| 134 | |
| 135 | def _reroute_ts(ts0, ts1, mode, can_modify=None, cannot_modify=None): |
no test coverage detected