Create arguments passed to converted while_loop.
(self, pfor_input)
| 381 | return output |
| 382 | |
| 383 | def _create_init_values(self, pfor_input): |
| 384 | """Create arguments passed to converted while_loop.""" |
| 385 | with ops.name_scope("while_init"): |
| 386 | loop_len_vector = pfor_input.pfor.loop_len_vector |
| 387 | loop_len = loop_len_vector[0] |
| 388 | num_outputs = len(self._outputs) |
| 389 | |
| 390 | inputs = [] |
| 391 | maybe_stacked_cache = {} |
| 392 | # Convert all the Enters. Need to do this before checking for stacking |
| 393 | # below. |
| 394 | for i, enter in enumerate(self._enters): |
| 395 | inp, stacked = self._convert_enter(pfor_input.pfor, enter) |
| 396 | inputs.append(inp) |
| 397 | maybe_stacked_cache[enter] = stacked |
| 398 | # Since this enter node is part of the `loop_vars`, it corresponds to an |
| 399 | # output and its preceding switch. We mark this switch's output the same |
| 400 | # stackness, to act at the base case for the logic below. Below, we will |
| 401 | # be going through the body figuring out which inputs might need to be |
| 402 | # stacked and which inputs can safely remain unstacked. |
| 403 | if i < num_outputs: |
| 404 | maybe_stacked_cache[self._exit_switches[i].outputs[1]] = stacked |
| 405 | |
| 406 | # Shape invariants for init_values corresponding to self._enters. |
| 407 | input_shape_invariants = [] |
| 408 | # TensorArrays for outputs of converted while loop |
| 409 | output_tas = [] |
| 410 | # Shape invariants for output TensorArrays. |
| 411 | ta_shape_invariants = [] |
| 412 | # List of booleans indicating stackness of inputs, i.e. tensors |
| 413 | # corresponding to self._enters. |
| 414 | inputs_stacked = [] |
| 415 | for i, inp in enumerate(inputs): |
| 416 | enter = self._enters[i] |
| 417 | inp_stacked = self._maybe_stacked(maybe_stacked_cache, enter) |
| 418 | # Note that even when an input is unstacked, the body could make it |
| 419 | # stacked. we use a heuristic below to figure out if body may be making |
| 420 | # it stacked. |
| 421 | if i < num_outputs: |
| 422 | body_output = self._body_outputs[i] |
| 423 | if enter.op in self._pfor_ops: |
| 424 | body_output_stacked = self._maybe_stacked(maybe_stacked_cache, |
| 425 | body_output) |
| 426 | else: |
| 427 | # If constructed outside of pfor loop, then the output would not be |
| 428 | # stacked. |
| 429 | body_output_stacked = False |
| 430 | if body_output_stacked and not inp_stacked: |
| 431 | inp = _stack(inp, loop_len_vector).t |
| 432 | inputs[i] = inp |
| 433 | inp_stacked = True |
| 434 | # TODO(agarwal): other attributes for the TensorArray ? |
| 435 | output_tas.append(tensor_array_ops.TensorArray(inp.dtype, loop_len)) |
| 436 | ta_shape_invariants.append(tensor_shape.TensorShape(None)) |
| 437 | |
| 438 | inputs_stacked.append(inp_stacked) |
| 439 | input_shape_invariants.append(tensor_shape.TensorShape(None)) |
| 440 |
no test coverage detected