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

Method _update_desc_attr

python/paddle/base/framework.py:3852–3874  ·  view source on GitHub ↗

Update the value of desc's attribute by attribute's name. Args: name(str): the attribute name. val(bool|int|str|float|list): the value of the attribute. Raises: ValueError: If the type of value doesn't match with desc.attr_type(name).

(self, name, val)

Source from the content-addressed store, hash-verified

3850 self.desc.remove_attr(name)
3851
3852 def _update_desc_attr(self, name, val):
3853 """
3854 Update the value of desc's attribute by attribute's name.
3855
3856 Args:
3857 name(str): the attribute name.
3858 val(bool|int|str|float|list): the value of the attribute.
3859
3860 Raises:
3861 ValueError: If the type of value doesn't match with desc.attr_type(name).
3862 """
3863 if isinstance(val, Variable):
3864 self.desc.set_var_attr(name, val.desc)
3865 elif isinstance(val, list) and _all_is_type(val, Variable):
3866 self.desc.set_vars_attr(name, [v.desc for v in val])
3867 elif isinstance(val, Block):
3868 self.desc.set_block_attr(name, val.desc)
3869 elif isinstance(val, list) and val and _all_is_type(val, Block):
3870 self.desc.set_blocks_attr(name, [v.desc for v in val])
3871 elif isinstance(val, (core.BlockDesc, core.ProgramDesc)):
3872 self.desc.set_serialized_attr(name, val.serialize_to_string())
3873 else:
3874 self._update_desc_plain_attr(name, val)
3875
3876 def _update_desc_plain_attr(self, name, val):
3877 desc = self.desc

Callers 2

__init__Method · 0.95
_set_attrMethod · 0.95

Calls 3

_all_is_typeFunction · 0.85
serialize_to_stringMethod · 0.45

Tested by

no test coverage detected