MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / __check_value_shape__

Method __check_value_shape__

detrsmpl/data/data_structures/human_data.py:851–895  ·  view source on GitHub ↗

Check whether the shape of val matches definition in HumanData.SUPPORTED_KEYS. Args: key (Any): Key in HumanData. val (Any): Value to the key. Returns: bool: If expected shape is defined and

(self, key: Any, val: Any)

Source from the content-addressed store, hash-verified

849 return ret_bool
850
851 def __check_value_shape__(self, key: Any, val: Any) -> bool:
852 """Check whether the shape of val matches definition in
853 HumanData.SUPPORTED_KEYS.
854
855 Args:
856 key (Any):
857 Key in HumanData.
858 val (Any):
859 Value to the key.
860
861 Returns:
862 bool:
863 If expected shape is defined and doesn't match,
864 return False.
865 Else return True.
866 """
867 ret_bool = True
868 supported_keys = self.__class__.SUPPORTED_KEYS
869 # check definition
870 if key in supported_keys:
871 # check shape
872 if 'shape' in supported_keys[key]:
873 val_shape = val.shape
874 for shape_ind in range(len(supported_keys[key]['shape'])):
875 # length not match
876 if shape_ind >= len(val_shape):
877 ret_bool = False
878 break
879 expect_val = supported_keys[key]['shape'][shape_ind]
880 # value not match
881 if expect_val > 0 and \
882 expect_val != val_shape[shape_ind]:
883 ret_bool = False
884 break
885 if not ret_bool:
886 expected_shape = str(supported_keys[key]['shape'])
887 expected_shape = expected_shape.replace('-1', 'Any')
888 err_msg = 'Shape check Failed:\n'
889 err_msg += f'key={str(key)}\n'
890 err_msg += f'val.shape={val_shape}\n'
891 err_msg += f'expected shape={expected_shape}\n'
892 print_log(msg=err_msg,
893 logger=self.__class__.logger,
894 level=logging.ERROR)
895 return ret_bool
896
897 @property
898 def data_len(self) -> int:

Callers 1

__check_value__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected