Get debug string. Args: throw_on_error(bool): raise exception when self is not initialized when throw_on_error is True. with_details(bool): more details about variables and parameters (e.g. trainable, optimize_attr, ...) will
(self, throw_on_error, with_details=False)
| 4430 | return block_str |
| 4431 | |
| 4432 | def to_string(self, throw_on_error, with_details=False): |
| 4433 | """ |
| 4434 | Get debug string. |
| 4435 | |
| 4436 | Args: |
| 4437 | throw_on_error(bool): raise exception when self is not initialized |
| 4438 | when throw_on_error is True. |
| 4439 | with_details(bool): more details about variables and parameters |
| 4440 | (e.g. trainable, optimize_attr, ...) will be printed when |
| 4441 | with_details is True. Default False. |
| 4442 | |
| 4443 | Returns: |
| 4444 | str: The debug string. |
| 4445 | """ |
| 4446 | assert isinstance(throw_on_error, bool) and isinstance( |
| 4447 | with_details, bool |
| 4448 | ) |
| 4449 | if with_details: |
| 4450 | re_add_indent = re.compile(r"\n(.)") |
| 4451 | res_str = ( |
| 4452 | f"blocks {{\n idx: {self.idx}\n parent_idx: {self.parent_idx}" |
| 4453 | ) |
| 4454 | for var in list(self.vars.values()): |
| 4455 | res_str += "\n vars {{\n {} }}".format( |
| 4456 | re_add_indent.sub( |
| 4457 | r"\n \1", var.to_string(throw_on_error, with_details) |
| 4458 | ) |
| 4459 | ) |
| 4460 | for op in self.ops: |
| 4461 | res_str += "\n ops {{\n {} }}".format( |
| 4462 | re_add_indent.sub(r"\n \1", op.to_string(throw_on_error)) |
| 4463 | ) |
| 4464 | res_str += "\n}" |
| 4465 | else: |
| 4466 | protostr = self.desc.serialize_to_string() |
| 4467 | proto = framework_pb2.BlockDesc.FromString(bytes(protostr)) |
| 4468 | res_str = _debug_string_(proto, throw_on_error) |
| 4469 | return res_str |
| 4470 | |
| 4471 | __repr__ = __str__ |
| 4472 |
no test coverage detected