Files
sunnypilot/common/numpy_fast.py
T
Jason Wen 2f33f13f8b sunnypilot v2024.08.11-1662
version: sunnypilot v0.9.7.0 release
  date: 2024-08-11T04:16:15
  master commit: c0df551c5bbd296a1e272c1878535dec14b4e7ad
2024-08-11 04:16:15 +00:00

20 lines
463 B
Python

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)