Checks if the given tensor is an identity op returned by `subscribe()`. Args: tensor: A `tf.Tensor` to check. Returns: True if the given tensor matches the criteria for subscription identies: its op type is `Identity`, its name matches the name of its input and conforms to the
(tensor)
| 181 | |
| 182 | |
| 183 | def _is_subscribed_identity(tensor): |
| 184 | """Checks if the given tensor is an identity op returned by `subscribe()`. |
| 185 | |
| 186 | Args: |
| 187 | tensor: A `tf.Tensor` to check. |
| 188 | |
| 189 | Returns: |
| 190 | True if the given tensor matches the criteria for subscription identies: |
| 191 | its op type is `Identity`, its name matches the name of its input and |
| 192 | conforms to the convention for subscribed nodes. |
| 193 | False otherwise. |
| 194 | """ |
| 195 | # Subscribed tensor are assumed to be identity ops. |
| 196 | if tensor.op.type != 'Identity': |
| 197 | return False |
| 198 | |
| 199 | # Check that the tensor name matches the convention in place for identity ops |
| 200 | # created by subscribe(). |
| 201 | match = re.match(r'(?P<prefix_name>^.*?)/subscription/Identity[^/]+', |
| 202 | tensor.name) |
| 203 | if match is None or len(match.groups()) != 1: |
| 204 | return False |
| 205 | prefix_name = match.group('prefix_name') |
| 206 | |
| 207 | # Get a reference to the source tensor and check that it has a matching name. |
| 208 | assert len(tensor.op.inputs) == 1, 'Op {} must only have one input'.format( |
| 209 | tensor.op.name) |
| 210 | source_tensor = tensor.op.inputs[0] |
| 211 | if prefix_name != source_tensor.op.name: |
| 212 | return False |
| 213 | |
| 214 | return True |
| 215 | |
| 216 | |
| 217 | def _subscribe(tensor, side_effects, control_cache): |
no test coverage detected