1import numpy as np
2from .get_run_lengths_cpp_ext import get_run_lengths_int16, get_run_lengths_int32
5def get_run_lengths(x: np.ndarray) -> np.ndarray:
6 """Calculate run lengths of zeros and non-zeros in a signal using C++ implementation.
8 Args:
9 x: Input signal (must be int16 or int32)
11 Returns:
12 np.ndarray: Array of run lengths alternating between non-zero and zero runs.
13 The dtype will be uint8, uint16, or uint32 depending on the maximum run length.
15 Raises:
16 ValueError: If input array is not int16 or int32
17 """
18 # Check input dtype and call appropriate implementation
19 if x.dtype == np.int16:
20 return get_run_lengths_int16(x)
21 elif x.dtype == np.int32:
22 return get_run_lengths_int32(x)
23 else:
24 raise ValueError(f"Input array must be int16 or int32, got {x.dtype}")