| 11 | |
| 12 | |
| 13 | class 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 | |
| 48 | class TmpObjectWithoutCat: |
no outgoing calls
searching dependent graphs…