Skip to content

Commit a37958f

Browse files
Add fixes identified by test cases
1 parent 4cec9b0 commit a37958f

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

precise/functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ def asigmoid(x):
8282

8383
def pdf(x, mu, std):
8484
"""Probability density function (normal distribution)"""
85+
if std == 0:
86+
return 0
8587
return (1.0 / (std * sqrt(2 * pi))) * np.exp(-(x - mu) ** 2 / (2 * std ** 2))

precise/scripts/engine.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def run(self):
6262
stdout.buffer.flush()
6363
except (EOFError, KeyboardInterrupt):
6464
pass
65+
finally:
66+
sys.stdout = stdout
6567

6668

6769
main = EngineScript.run_main

precise/threshold_decoder.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ def __init__(self, mu_stds: Tuple[Tuple[float, float]], center=0.5, resolution=2
3434
def decode(self, raw_output: float) -> float:
3535
if raw_output == 1.0 or raw_output == 0.0:
3636
return raw_output
37-
ratio = (asigmoid(raw_output) - self.min_out) / self.out_range
38-
ratio = min(max(ratio, 0.0), 1.0)
39-
cp = self.cd[int(ratio * (len(self.cd) - 1) + 0.5)]
37+
if self.out_range == 0:
38+
cp = int(raw_output > self.min_out)
39+
else:
40+
ratio = (asigmoid(raw_output) - self.min_out) / self.out_range
41+
ratio = min(max(ratio, 0.0), 1.0)
42+
cp = self.cd[int(ratio * (len(self.cd) - 1) + 0.5)]
4043
if cp < self.center:
4144
return 0.5 * cp / self.center
4245
else:

runner/precise_runner/runner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def write(self, s):
107107
self.buffer += s
108108
self.write_event.set()
109109

110+
def flush(self):
111+
"""Makes compatible with sys.stdout"""
112+
pass
113+
110114

111115
class TriggerDetector:
112116
"""

0 commit comments

Comments
 (0)