You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using internal ArrayKit utilities, and avoiding the usage of Python objects where possible, lets implement transition_slices_from_group as CPythhon function in ArrayKit.
def_slices_from_transitions(
transitions: tp.Iterator[int], size: int
) ->tp.Iterator[slice]:
start=0fortintransitions:
yieldslice(start, t)
start=tifstart<size:
yieldslice(start, None)
deftransition_slices_from_group(group: np.ndarray) ->tuple[tp.Iterator[slice], bool]:
ifgroup.ndim==2:
group_to_tuple=Trueifgroup.dtype==DTYPE_OBJECT:
# NOTE: cannot get view of object; use stringconsolidated=view_2d_as_1d(group.astype(str))
else:
consolidated=view_2d_as_1d(group)
transitions=nonzero_1d(consolidated!=roll_1d(consolidated, 1))[1:]
else:
group_to_tuple=Falsetransitions=nonzero_1d(group!=roll_1d(group, 1))[1:]
return_slices_from_transitions(transitions, len(group)), group_to_tuple# type: ignor
Activity