d9bf9f0a40
* enable some more flake8 checks * some more quick ones * bump opendbc * e401 * e711 e712 * e115 e116 * e222 * e301 * remove that * e129 * e701 e702 * e125 e131 * e227 * e306 * e262 * W503 * e713 * e704 * e731 * bump opendbc * fix some e722
23 lines
503 B
Python
23 lines
503 B
Python
def int_rnd(x):
|
|
return int(round(x))
|
|
|
|
def clip(x, lo, hi):
|
|
return max(lo, min(hi, x))
|
|
|
|
def interp(x, xp, fp):
|
|
N = len(xp)
|
|
|
|
def get_interp(xv):
|
|
hi = 0
|
|
while hi < N and xv > xp[hi]:
|
|
hi += 1
|
|
low = hi - 1
|
|
return fp[-1] if hi == N and xv > xp[low] else (
|
|
fp[0] if hi == 0 else
|
|
(xv - xp[low]) * (fp[hi] - fp[low]) / (xp[hi] - xp[low]) + fp[low])
|
|
|
|
return [get_interp(v) for v in x] if hasattr(x, '__iter__') else get_interp(x)
|
|
|
|
def mean(x):
|
|
return sum(x) / len(x)
|