Helper method to extend the list of side_effects for a subscribed tensor. Args: tensor: A `tf.Tensor` as returned by subscribe(). side_effects: List of side_effect functions, see subscribe for details. Returns: The given subscribed tensor (for API consistency).
(tensor, side_effects)
| 153 | |
| 154 | |
| 155 | def _subscribe_extend(tensor, side_effects): |
| 156 | """Helper method to extend the list of side_effects for a subscribed tensor. |
| 157 | |
| 158 | Args: |
| 159 | tensor: A `tf.Tensor` as returned by subscribe(). |
| 160 | side_effects: List of side_effect functions, see subscribe for details. |
| 161 | |
| 162 | Returns: |
| 163 | The given subscribed tensor (for API consistency). |
| 164 | """ |
| 165 | assert len(tensor.op.inputs) == 1, 'Op {} must only have one input'.format( |
| 166 | tensor.op.name) |
| 167 | source_tensor = tensor.op.inputs[0] |
| 168 | |
| 169 | # Build the side effect graphs and add their outputs to the list of control |
| 170 | # dependencies for the subscribed tensor. |
| 171 | outs = [] |
| 172 | name_scope = source_tensor.op.name + '/subscription/' |
| 173 | with ops.name_scope(name_scope): |
| 174 | for s in side_effects: |
| 175 | outs += s(source_tensor) |
| 176 | |
| 177 | out_ops = [out.op if isinstance(out, ops.Tensor) else out for out in outs] |
| 178 | tensor.op._add_control_inputs(out_ops) # pylint: disable=protected-access |
| 179 | |
| 180 | return tensor |
| 181 | |
| 182 | |
| 183 | def _is_subscribed_identity(tensor): |
no test coverage detected