(
cls, program, fetch_list, fetch_var_name, use_fetch_v2=False
)
| 2783 | |
| 2784 | @classmethod |
| 2785 | def _add_fetch_ops( |
| 2786 | cls, program, fetch_list, fetch_var_name, use_fetch_v2=False |
| 2787 | ): |
| 2788 | tmp_program = program.clone() |
| 2789 | |
| 2790 | global_block = tmp_program.global_block() |
| 2791 | |
| 2792 | if fetch_var_name in global_block.vars: |
| 2793 | fetch_var = global_block.var(fetch_var_name) |
| 2794 | else: |
| 2795 | fetch_var = global_block.create_var( |
| 2796 | name=fetch_var_name, |
| 2797 | type=core.VarDesc.VarType.FETCH_LIST, |
| 2798 | persistable=True, |
| 2799 | ) |
| 2800 | |
| 2801 | if use_fetch_v2: |
| 2802 | fetch_op = 'fetch_v2' |
| 2803 | else: |
| 2804 | fetch_op = 'fetch' |
| 2805 | |
| 2806 | # append fetch_operators |
| 2807 | if not has_fetch_operators( |
| 2808 | global_block, fetch_list, fetch_var_name, fetch_op |
| 2809 | ): |
| 2810 | for i, var in enumerate(fetch_list): |
| 2811 | assert isinstance(var, (Variable, str)), ( |
| 2812 | f"Wrong type for fetch_list[{i}]: {type(var)}" |
| 2813 | ) |
| 2814 | global_block.append_op( |
| 2815 | type=fetch_op, |
| 2816 | inputs={'X': [var]}, |
| 2817 | outputs={'Out': [fetch_var]}, |
| 2818 | attrs={'col': i}, |
| 2819 | ) |
| 2820 | |
| 2821 | return tmp_program |
| 2822 | |
| 2823 | @classmethod |
| 2824 | def _remove_fetch_ops(cls, program, fetch_op_name='fetch'): |
no test coverage detected