mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 12:02:09 +08:00
d8f56b30b5
* ban all of common & copy numpy_fast * add numpy_fast * these are okay * and ban controls * better name * Conversions * do utils, kalman * clean up * sorting * don't forget old-commit-hash: 8d961a12e5b033855f2abf5d8bd9c51374f74c6e
23 lines
466 B
Python
23 lines
466 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)
|
|
|