Skip to content

Commit 1ec0507

Browse files
committed
a bit faster search
1 parent 6a016ac commit 1ec0507

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

openptv_python/find_candidate.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import math
22
from typing import List
33

4-
from numba import float64, njit
4+
import numpy as np
5+
from numba import float64, int32, njit
56

67
from .calibration import Calibration
78
from .constants import MAXCAND
@@ -155,7 +156,6 @@ def quality_ratio(a: float, b: float) -> float:
155156
return 0
156157
return min(a, b) / max(a, b)
157158

158-
159159
def find_start_point(crd: List[Coord2d], num: int, xa: float, vpar: VolumePar) -> int:
160160
"""Find the start point of the candidate search.
161161
@@ -171,12 +171,19 @@ def find_start_point(crd: List[Coord2d], num: int, xa: float, vpar: VolumePar) -
171171
-------
172172
The start point of the candidate search.
173173
"""
174-
num = len(crd)
174+
x = np.array([_.x for _ in crd])
175+
eps0 = vpar.eps0
176+
out = find_start_point_binary(x, num, xa, eps0)
177+
return out
178+
179+
@njit(int32(float64[:], int32, float64, float64))
180+
def find_start_point_binary(x: np.ndarray, num: int, xa: float, eps0: float) -> int:
181+
# num = len(x)
175182
j0 = num // 2
176183
dj = num // 4
177184

178185
while dj > 1:
179-
if crd[j0].x < (xa - vpar.eps0):
186+
if x[j0] < (xa - eps0):
180187
j0 += dj
181188
else:
182189
j0 -= dj

0 commit comments

Comments
 (0)