def _preprocess(t, v):
""" Raises and exception if any of the inputs are not valid.
Otherwise, returns a list of Points, ordered by t.
"""
# Validate the inputs.
if len(t) != len(v):
raise ValueError('`t` and `v` must have the same length.')
t_arr, v_arr = np.array(t), np.array(v)
if not np.all(np.isfinite(t)):
raise ValueError('All values in `t` must be finite.')
finite_mask = np.isfinite(v_arr)
if np.sum(finite_mask) < 2:
raise ValueError('`v` must have at least 2 finite values.')
t_arr, v_arr = t_arr[finite_mask], v_arr[finite_mask]
if len(np.unique(t_arr)) != len(t_arr):
raise ValueError('All `t` values must be unique.')
# Order both arrays by t-values.
sort_order = np.argsort(t_arr)
t_arr, v_arr = t_arr[sort_order], v_arr[sort_order]
return t_arr, v_arr
评论列表
文章目录