MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / flatten_meta_objs

Method flatten_meta_objs

monai/data/meta_obj.py:89–105  ·  view source on GitHub ↗

Recursively flatten input and yield all instances of `MetaObj`. This means that for both `torch.add(a, b)`, `torch.stack([a, b])` (and their numpy equivalents), we return `[a, b]` if both `a` and `b` are of type `MetaObj`. Args: args: Iterables o

(*args: Iterable)

Source from the content-addressed store, hash-verified

87
88 @staticmethod
89 def flatten_meta_objs(*args: Iterable):
90 """
91 Recursively flatten input and yield all instances of `MetaObj`.
92 This means that for both `torch.add(a, b)`, `torch.stack([a, b])` (and
93 their numpy equivalents), we return `[a, b]` if both `a` and `b` are of type
94 `MetaObj`.
95
96 Args:
97 args: Iterables of inputs to be flattened.
98 Returns:
99 list of nested `MetaObj` from input.
100 """
101 for a in itertools.chain(*args):
102 if isinstance(a, (list, tuple)):
103 yield from MetaObj.flatten_meta_objs(a)
104 elif isinstance(a, MetaObj):
105 yield a
106
107 @staticmethod
108 def copy_items(data):

Callers 1

update_metaMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected