def _intervals(x: np.ndarray) -> np.ndarray:
    r"""Compute the intervals between non zero elements of a vector."""
    nonzero_idxs = np.where(x != 0)[0]
    return np.diff(nonzero_idxs + 1, prepend=0).astype(x.dtype)
Compute the intervals between non zero elements of a vector.
python/statsforecast/models.py