Files
dragonpilot/common/numpy_fast.py

19 lines
468 B
Python
Raw Normal View History

2018-01-30 12:58:14 -08:00
def int_rnd(x):
return int(round(x))
2016-11-29 18:34:21 -08:00
def clip(x, lo, hi):
return max(lo, min(hi, x))
2016-12-14 21:29:12 -08:00
def interp(x, xp, fp):
N = len(xp)
def get_interp(xv):
2016-12-14 21:29:12 -08:00
hi = 0
while hi < N and xv > xp[hi]:
2016-12-14 21:29:12 -08:00
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)