MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / WhileGuard

Class WhileGuard

python/paddle/static/nn/control_flow.py:157–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155
156
157class WhileGuard(BlockGuard):
158 def __init__(self, while_op):
159 if not isinstance(while_op, While):
160 raise TypeError("WhileGuard takes a while op")
161 if not in_pir_mode():
162 super().__init__(while_op.helper.main_program)
163 self.while_op = while_op
164
165 def __enter__(self):
166 if in_pir_mode():
167 self.block = build_while_op(self.while_op.cond_var, []).body()
168 return self.block.__enter__()
169 self.while_op.status = While.IN_WHILE_BLOCK
170 return super().__enter__()
171
172 def __exit__(self, exc_type, exc_val, exc_tb):
173 if in_pir_mode():
174 cf_yield([self.while_op.cond_var])
175 return self.block.__exit__(exc_type, exc_val, exc_tb)
176 if exc_type is not None:
177 return False
178 self.while_op.status = While.AFTER_WHILE_BLOCK
179 self.while_op._complete()
180 return super().__exit__(exc_type, exc_val, exc_tb)
181
182
183class If:

Callers 1

blockMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected