Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common/numpy_fast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)
2 changes: 1 addition & 1 deletion opendbc_repo/opendbc/car/bmw/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from opendbc.car.interfaces import CarControllerBase
from opendbc.can.packer import CANPacker
from opendbc.car.common.conversions import Conversions as CV
from common import numpy_fast as np
import common.numpy_fast as np

VisualAlert = car_capnp.CarControl.HUDControl.VisualAlert

Expand Down
Loading