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

Function _parse_every_object

python/paddle/framework/io.py:619–652  ·  view source on GitHub ↗
(obj, condition_func, convert_func)

Source from the content-addressed store, hash-verified

617
618
619def _parse_every_object(obj, condition_func, convert_func):
620 if condition_func(obj):
621 return convert_func(obj)
622 elif type(obj) in (dict, collections.OrderedDict, list):
623 if type(obj) == list:
624 keys = range(len(obj))
625 else:
626 keys = list(obj.keys())
627 for key in keys:
628 if condition_func(obj[key]):
629 obj[key] = convert_func(obj[key])
630 else:
631 obj[key] = _parse_every_object(
632 obj[key], condition_func, convert_func
633 )
634 return obj
635 elif type(obj) == tuple:
636 return tuple(
637 _parse_every_object(list(obj), condition_func, convert_func)
638 )
639 elif type(obj) == set:
640 return set(_parse_every_object(list(obj), condition_func, convert_func))
641 else:
642 # Support dataclass objects - return as-is without further parsing
643 if dataclasses.is_dataclass(obj):
644 return obj
645 if isinstance(obj, Iterable) and not isinstance(
646 obj,
647 (str, np.ndarray, core.eager.Tensor, core.DenseTensor),
648 ):
649 raise NotImplementedError(
650 f"The iterable objects supported are tuple, list, dict, OrderedDict, string. But received {type(obj)}."
651 )
652 return obj
653
654
655def _parse_load_result(obj, return_numpy):

Callers 7

_pickle_saveFunction · 0.85
_parse_load_resultFunction · 0.85

Calls 6

rangeFunction · 0.85
listFunction · 0.85
setClass · 0.85
NotImplementedErrorClass · 0.85
typeFunction · 0.50
keysMethod · 0.45