Overload of while_stmt that stages a TF while_stmt.
(test, body, get_state, set_state, init_vars,
basic_symbol_names, composite_symbol_names, opts)
| 734 | # composite_symbol_names=None and call _verify_tf_loop_vars(...) itself. We can |
| 735 | # remove these arguments once all callers do that. |
| 736 | def _tf_while_stmt(test, body, get_state, set_state, init_vars, |
| 737 | basic_symbol_names, composite_symbol_names, opts): |
| 738 | """Overload of while_stmt that stages a TF while_stmt.""" |
| 739 | _disallow_undefs_into_loop(*init_vars) |
| 740 | |
| 741 | if opts is None: |
| 742 | opts = {} |
| 743 | |
| 744 | # TODO(mdan): Simplify this. |
| 745 | loop_vars_slice = slice(len(init_vars)) |
| 746 | state_slice = slice(len(init_vars), None) |
| 747 | |
| 748 | def aug_test(*aug_loop_vars): |
| 749 | state = aug_loop_vars[state_slice] |
| 750 | set_state(state) |
| 751 | return test(*aug_loop_vars[loop_vars_slice]) |
| 752 | |
| 753 | def aug_body(*aug_loop_vars): |
| 754 | state = aug_loop_vars[state_slice] |
| 755 | set_state(state) |
| 756 | loop_vars = body(*aug_loop_vars[loop_vars_slice]) |
| 757 | new_state = loop_vars + get_state() |
| 758 | _verify_tf_loop_vars(aug_loop_vars, new_state, basic_symbol_names, |
| 759 | composite_symbol_names) |
| 760 | |
| 761 | return new_state |
| 762 | |
| 763 | # Non-v2 while_loop unpacks the results when there is only one return value. |
| 764 | # This enforces consistency across versions. |
| 765 | opts['return_same_structure'] = True |
| 766 | |
| 767 | aug_init_vars = init_vars + get_state() |
| 768 | final_aug_vars = control_flow_ops.while_loop(aug_test, aug_body, |
| 769 | aug_init_vars, **opts) |
| 770 | final_state = final_aug_vars[state_slice] |
| 771 | set_state(final_state) |
| 772 | return final_aug_vars[loop_vars_slice] |
| 773 | |
| 774 | |
| 775 | class _PythonLoopChecker(object): |
no test coverage detected