For each key in this HumanData, get the dimension for slicing. 0 for default, if no other value specified. Returns: dict: Keys are self.keys(). Values indicate where to slice. None for not expected to be sliced or
(self)
| 610 | return ret_human_data |
| 611 | |
| 612 | def __get_slice_dim__(self) -> dict: |
| 613 | """For each key in this HumanData, get the dimension for slicing. 0 for |
| 614 | default, if no other value specified. |
| 615 | |
| 616 | Returns: |
| 617 | dict: |
| 618 | Keys are self.keys(). |
| 619 | Values indicate where to slice. |
| 620 | None for not expected to be sliced or |
| 621 | failed. |
| 622 | """ |
| 623 | supported_keys = self.__class__.SUPPORTED_KEYS |
| 624 | ret_dict = {} |
| 625 | for key in self.keys(): |
| 626 | # keys not expected be sliced |
| 627 | if key in supported_keys and \ |
| 628 | 'dim' in supported_keys[key] and \ |
| 629 | supported_keys[key]['dim'] is None: |
| 630 | ret_dict[key] = None |
| 631 | else: |
| 632 | value = self[key] |
| 633 | if isinstance(value, dict) and len(value) > 0: |
| 634 | ret_dict[key] = {} |
| 635 | for sub_key in value.keys(): |
| 636 | try: |
| 637 | sub_value_len = len(value[sub_key]) |
| 638 | if sub_value_len != self.__data_len__: |
| 639 | ret_dict[key][sub_key] = None |
| 640 | elif 'dim' in value: |
| 641 | ret_dict[key][sub_key] = value['dim'] |
| 642 | else: |
| 643 | ret_dict[key][sub_key] = 0 |
| 644 | except TypeError: |
| 645 | ret_dict[key][sub_key] = None |
| 646 | continue |
| 647 | # instance cannot be sliced without len method |
| 648 | try: |
| 649 | value_len = len(value) |
| 650 | except TypeError: |
| 651 | ret_dict[key] = None |
| 652 | continue |
| 653 | # slice on dim 0 by default |
| 654 | slice_dim = 0 |
| 655 | if key in supported_keys and \ |
| 656 | 'dim' in supported_keys[key]: |
| 657 | slice_dim = \ |
| 658 | supported_keys[key]['dim'] |
| 659 | data_len = value_len if slice_dim == 0 \ |
| 660 | else value.shape[slice_dim] |
| 661 | # dim not for slice |
| 662 | if data_len != self.__data_len__: |
| 663 | ret_dict[key] = None |
| 664 | continue |
| 665 | else: |
| 666 | ret_dict[key] = slice_dim |
| 667 | return ret_dict |
| 668 | |
| 669 | def __setitem__(self, key: _KT, val: _VT) -> None: |
no test coverage detected