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

Method get_slice

detrsmpl/data/data_structures/multi_human_data.py:204–267  ·  view source on GitHub ↗

Slice all sliceable values along major_dim dimension. Args: arg_0 (int): When arg_1 is None, arg_0 is stop and start=0. When arg_1 is not None, arg_0 is start. arg_1 (Union[int, Any], optional): None or where to stop.

(self,
                  arg_0: int,
                  arg_1: Union[int, Any] = None,
                  step: int = 1)

Source from the content-addressed store, hash-verified

202 self.__instance_num__ = value
203
204 def get_slice(self,
205 arg_0: int,
206 arg_1: Union[int, Any] = None,
207 step: int = 1) -> _HumanData:
208 """Slice all sliceable values along major_dim dimension.
209
210 Args:
211 arg_0 (int):
212 When arg_1 is None, arg_0 is stop and start=0.
213 When arg_1 is not None, arg_0 is start.
214 arg_1 (Union[int, Any], optional):
215 None or where to stop.
216 Defaults to None.
217 step (int, optional):
218 Length of step. Defaults to 1.
219
220 Returns:
221 MultiHumanData:
222 A new MultiHumanData instance with sliced values.
223 """
224 ret_human_data = \
225 MultiHumanData.new(key_strict=self.get_key_strict())
226 if arg_1 is None:
227 start = 0
228 stop = arg_0
229 else:
230 start = arg_0
231 stop = arg_1
232 slice_index = slice(start, stop, step)
233 dim_dict = self.__get_slice_dim__()
234 # frame_range = self.get_raw_value('optional')['frame_range']
235 for key, dim in dim_dict.items():
236 # primary index
237 if key == 'optional':
238 frame_range = None
239 else:
240 frame_range = self.get_raw_value('optional')['frame_range']
241 # keys not expected be sliced
242 if dim is None:
243 ret_human_data[key] = self[key]
244 elif isinstance(dim, dict):
245 value_dict = self.get_raw_value(key)
246 sliced_dict = {}
247 for sub_key in value_dict.keys():
248 sub_value = value_dict[sub_key]
249 if dim[sub_key] is None:
250 sliced_dict[sub_key] = sub_value
251 else:
252 sub_dim = dim[sub_key]
253 sliced_sub_value = \
254 MultiHumanData.__get_sliced_result__(
255 sub_value, sub_dim, slice_index, frame_range)
256 sliced_dict[sub_key] = sliced_sub_value
257 ret_human_data[key] = sliced_dict
258 else:
259 value = self[key]
260 sliced_value = \
261 MultiHumanData.__get_sliced_result__(

Callers

nothing calls this directly

Calls 9

__get_slice_dim__Method · 0.95
newMethod · 0.80
get_key_strictMethod · 0.80
get_raw_valueMethod · 0.80
itemsMethod · 0.45
keysMethod · 0.45
__get_sliced_result__Method · 0.45

Tested by

no test coverage detected