In Fluid, a Program is consistence of multi-Block, and Block stores VarDesc and OpDesc. In a specific Block, a VarDesc have a unique name. One block could have some child blocks, and child block's name scopes should inherit the parent's so that OpDesc in child block can reference
| 4337 | |
| 4338 | |
| 4339 | class Block: |
| 4340 | """ |
| 4341 | In Fluid, a Program is consistence of multi-Block, and Block stores |
| 4342 | VarDesc and OpDesc. In a specific Block, a VarDesc have a unique name. |
| 4343 | One block could have some child blocks, and child block's name scopes |
| 4344 | should inherit the parent's so that OpDesc in child block can reference |
| 4345 | a VarDesc that is stored in the parent block. |
| 4346 | Please reference the framework.proto for details. |
| 4347 | |
| 4348 | Args: |
| 4349 | program(Program): The Program that the Block belongs to. |
| 4350 | idx(int): The block's id in the Program. |
| 4351 | |
| 4352 | Notes: |
| 4353 | The constructor of Block should not be invoked directly. Please |
| 4354 | use `Program._create_block()` to create a block. |
| 4355 | |
| 4356 | Examples: |
| 4357 | .. code-block:: pycon |
| 4358 | |
| 4359 | >>> import paddle |
| 4360 | |
| 4361 | >>> paddle.enable_static() |
| 4362 | >>> cur_program = paddle.static.Program() |
| 4363 | >>> cur_block = cur_program.current_block() |
| 4364 | >>> var = cur_block.create_var( |
| 4365 | ... name="X", |
| 4366 | ... shape=[-1, 23, 48], |
| 4367 | ... dtype="float32", |
| 4368 | ... ) |
| 4369 | >>> cur_block.append_op( |
| 4370 | ... type="abs", |
| 4371 | ... inputs={"X": [var]}, |
| 4372 | ... outputs={"Out": [var]}, |
| 4373 | ... ) |
| 4374 | """ |
| 4375 | |
| 4376 | def __init__(self, program, idx): |
| 4377 | self.desc = program.desc.block(idx) |
| 4378 | self.vars = collections.OrderedDict() # var_name --> var |
| 4379 | self.ops = [] # operator list |
| 4380 | self.program = program |
| 4381 | |
| 4382 | def __str__(self): |
| 4383 | return self._to_readable_code() |
| 4384 | |
| 4385 | def _to_readable_code(self, skip_op_callstack=True): |
| 4386 | """ |
| 4387 | Get readable debug string of Block. |
| 4388 | |
| 4389 | .. note:: |
| 4390 | If you want to get the debug string in protobuf format, |
| 4391 | please use :code:`to_string` method. |
| 4392 | |
| 4393 | Args: |
| 4394 | skip_op_callstack(bool): whether to skip parsing Operator's attribute |
| 4395 | op_callstack, default value is True |
| 4396 |
no outgoing calls