MCPcopy Create free account
hub / github.com/open-mmlab/mmengine / TmpObject

Class TmpObject

tests/test_structures/test_instance_data.py:13–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class TmpObject:
14
15 def __init__(self, tmp) -> None:
16 assert isinstance(tmp, list)
17 if len(tmp) > 0:
18 for t in tmp:
19 assert isinstance(t, list)
20 self.tmp = tmp
21
22 def __len__(self):
23 return len(self.tmp)
24
25 def __getitem__(self, item):
26 if isinstance(item, int):
27 if item >= len(self) or item < -len(self): # type:ignore
28 raise IndexError(f'Index {item} out of range!')
29 else:
30 # keep the dimension
31 item = slice(item, None, len(self))
32 return TmpObject(self.tmp[item])
33
34 @staticmethod
35 def cat(tmp_objs):
36 assert all(isinstance(results, TmpObject) for results in tmp_objs)
37 if len(tmp_objs) == 1:
38 return tmp_objs[0]
39 tmp_list = [tmp_obj.tmp for tmp_obj in tmp_objs]
40 tmp_list = list(itertools.chain(*tmp_list))
41 new_data = TmpObject(tmp_list)
42 return new_data
43
44 def __repr__(self):
45 return str(self.tmp)
46
47
48class TmpObjectWithoutCat:

Callers 3

__getitem__Method · 0.85
catMethod · 0.85
setup_dataMethod · 0.85

Calls

no outgoing calls

Tested by 3

__getitem__Method · 0.68
catMethod · 0.68
setup_dataMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…