Remap in place the inputs of two subgraph views to mimic the reroute. This function is meant to used by reroute_inputs only. Args: sgv0: the first subgraph to have its inputs remapped. sgv1: the second subgraph to have its inputs remapped. mode: reroute mode, see _reroute_ts(...).
(sgv0, sgv1, mode)
| 257 | |
| 258 | |
| 259 | def _reroute_sgv_remap(sgv0, sgv1, mode): |
| 260 | """Remap in place the inputs of two subgraph views to mimic the reroute. |
| 261 | |
| 262 | This function is meant to used by reroute_inputs only. |
| 263 | |
| 264 | Args: |
| 265 | sgv0: the first subgraph to have its inputs remapped. |
| 266 | sgv1: the second subgraph to have its inputs remapped. |
| 267 | mode: reroute mode, see _reroute_ts(...). |
| 268 | Raises: |
| 269 | TypeError: if svg0 or svg1 are not SubGraphView. |
| 270 | ValueError: if sgv0 and sgv1 do not belong to the same graph. |
| 271 | """ |
| 272 | a2b, b2a = _RerouteMode.check(mode) |
| 273 | if not isinstance(sgv0, _subgraph.SubGraphView): |
| 274 | raise TypeError("Expected a SubGraphView, got {}".format(type(sgv0))) |
| 275 | if not isinstance(sgv1, _subgraph.SubGraphView): |
| 276 | raise TypeError("Expected a SubGraphView, got {}".format(type(sgv1))) |
| 277 | _util.check_graphs(sgv0, sgv1) |
| 278 | sgv0_ = sgv0.copy() |
| 279 | sgv1_ = sgv1.copy() |
| 280 | # pylint: disable=protected-access |
| 281 | if a2b and b2a: |
| 282 | (sgv0_._input_ts, sgv1_._input_ts) = (sgv1_._input_ts, sgv0_._input_ts) |
| 283 | (sgv0_._passthrough_ts, sgv1_._passthrough_ts) = (sgv1_._passthrough_ts, |
| 284 | sgv0_._passthrough_ts) |
| 285 | elif a2b: |
| 286 | sgv1_._input_ts = sgv0_._input_ts[:] |
| 287 | sgv1_._passthrough_ts = sgv0_._passthrough_ts[:] |
| 288 | elif b2a: |
| 289 | sgv0_._input_ts = sgv1_._input_ts[:] |
| 290 | sgv0_._passthrough_ts = sgv1_._passthrough_ts[:] |
| 291 | # pylint: enable=protected-access |
| 292 | |
| 293 | # Update the passthrough outputs as well. |
| 294 | def update_passthrough_outputs(a, b): |
| 295 | # pylint: disable=protected-access |
| 296 | for i, t in enumerate(b._output_ts): |
| 297 | if t in a._passthrough_ts: |
| 298 | ii = a._input_ts.index(t) |
| 299 | b._output_ts[i] = b._input_ts[ii] |
| 300 | # pylint: enable=protected-access |
| 301 | |
| 302 | if a2b: |
| 303 | update_passthrough_outputs(sgv0_, sgv1_) |
| 304 | if b2a: |
| 305 | update_passthrough_outputs(sgv1_, sgv0_) |
| 306 | |
| 307 | # in-place |
| 308 | # pylint: disable=protected-access |
| 309 | sgv0._assign_from(sgv0_) |
| 310 | sgv1._assign_from(sgv1_) |
| 311 | # pylint: enable=protected-access |
| 312 | |
| 313 | |
| 314 | def _reroute_sgv_inputs(sgv0, sgv1, mode): |
no test coverage detected