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
SignalMixin.smooth_frames: use minimal data type for result.
Instead of always returning the result as an int64 or float64 array,
select the output type based on the types of the input arrays.
The output type should be the smallest type that has the correct
"kind" and is able to represent all input values. For example, in
digital mode, if the input includes some int8 arrays and some int16
arrays, the result should be an int16 array. In physical mode, if the
inputs are all float32, then the result will be float32; otherwise the
result will be float64.
However, although the output type should generally match the input
type, intermediate results may need to be stored as a different type.
For example, if the input and output are both int16, and one or more
signals have spf > 1 and use the entire 16-bit range, then the sum of
N samples will overflow an int16. Previously, it was fine simply to
store the intermediate results in the output array itself, because the
output array was 64-bit, and no WFDB format has more than 32-bit
precision, and spf is (in practice) limited to at most 2**31-1.
For simplicity, continue using int64 or float64 as the intermediate
type, regardless of the actual input types and spf.
At the same time, we can also optimize the calculation slightly by
reshaping the input array and using np.sum, avoiding another Python
loop.
0 commit comments