Heuristic to figue out if the coverting inp leads to a stacked value. Args: cache: map from Tensor to boolean indicating stacked/unstacked. inp: input Tensor. Returns: True if `inp` could get stacked. If the function returns False, the converted value should be gua
(self, cache, inp)
| 339 | return inp, stacked |
| 340 | |
| 341 | def _maybe_stacked(self, cache, inp): |
| 342 | """Heuristic to figue out if the coverting inp leads to a stacked value. |
| 343 | |
| 344 | |
| 345 | Args: |
| 346 | cache: map from Tensor to boolean indicating stacked/unstacked. |
| 347 | inp: input Tensor. |
| 348 | |
| 349 | Returns: |
| 350 | True if `inp` could get stacked. If the function returns False, the |
| 351 | converted value should be guaranteed to be unstacked. If returning True, |
| 352 | it may or may not be stacked. |
| 353 | """ |
| 354 | if inp in cache: |
| 355 | return cache[inp] |
| 356 | if not self.op_is_inside_loop(inp.op): |
| 357 | return False |
| 358 | op = inp.op |
| 359 | output = False |
| 360 | if op.type in [ |
| 361 | "Shape", |
| 362 | "Rank", |
| 363 | "ShapeN", |
| 364 | "ZerosLike", |
| 365 | "TensorArrayV3", |
| 366 | "TensorArraySizeV3", |
| 367 | ]: |
| 368 | output = False |
| 369 | elif _is_stateful_pfor_op(op): |
| 370 | # This may be fairly aggressive. |
| 371 | output = True |
| 372 | elif op.type == "Exit": |
| 373 | # This may be fairly aggressive. |
| 374 | output = True |
| 375 | else: |
| 376 | for t in op.inputs: |
| 377 | if self._maybe_stacked(cache, t): |
| 378 | output = True |
| 379 | break |
| 380 | cache[inp] = output |
| 381 | return output |
| 382 | |
| 383 | def _create_init_values(self, pfor_input): |
| 384 | """Create arguments passed to converted while_loop.""" |
no test coverage detected