Skip to content
Open
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
2 changes: 1 addition & 1 deletion openpilot/selfdrive/locationd/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def fft_next_good_size(n: int) -> int:


def parabolic_peak_interp(R, max_index):
if max_index == 0 or max_index == len(R) - 1:
if max_index <= 0 or max_index >= len(R) - 1:
return max_index

y_m1, y_0, y_p1 = R[max_index - 1], R[max_index], R[max_index + 1]
Expand Down
16 changes: 16 additions & 0 deletions openpilot/selfdrive/locationd/test/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from openpilot.selfdrive.locationd.helpers import parabolic_peak_interp


class TestParabolicPeakInterp:
def test_symmetric_peak_refines_to_center(self):
assert parabolic_peak_interp([0.0, 1.0, 0.0], 1) == 1.0

def test_endpoints_return_index(self):
R = [1.0, 0.5, 0.2]
assert parabolic_peak_interp(R, 0) == 0
assert parabolic_peak_interp(R, len(R) - 1) == len(R) - 1

def test_degenerate_inputs_do_not_raise(self):
# an empty array or an out-of-range index must not raise IndexError
assert parabolic_peak_interp([], 7) == 7
assert parabolic_peak_interp([1.0, 2.0], 5) == 5
Loading