Skip to content

Commit 8f08696

Browse files
committed
[cytation5] improve autofocus effiency by caching
1 parent 46d8eb2 commit 8f08696

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pylabrobot/plate_reading/biotek_backend.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import time
77
from dataclasses import dataclass
8-
from typing import Any, Callable, Coroutine, List, Literal, Optional, Tuple, Union, cast
8+
from typing import Any, Callable, Coroutine, Dict, List, Literal, Optional, Tuple, Union, cast
99

1010
try:
1111
import cv2 # type: ignore
@@ -67,10 +67,16 @@ async def _golden_ratio_search(
6767
c = b - (b - a) / phi
6868
d = a + (b - a) / phi
6969

70+
cache: Dict[float, float] = {}
71+
async def cached_func(x: float) -> float:
72+
if x not in cache:
73+
cache[x] = await func(x)
74+
return cache[x]
75+
7076
t0 = time.time()
7177
iteration = 0
7278
while abs(b - a) > tol:
73-
if (await func(c)) > (await func(d)):
79+
if (await cached_func(c)) > (await cached_func(d)):
7480
b = d
7581
else:
7682
a = c

0 commit comments

Comments
 (0)