Avoid redundant computation in PiecewiseLinear. (#1915)

This commit is contained in:
Fangjun Kuang 2025-04-09 11:52:37 +08:00 committed by GitHub
parent 86bd16d496
commit 171cf8c9fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,8 +160,10 @@ class PiecewiseLinear(object):
extra_x_vals.append(extra_x_val)
if len(extra_x_vals) > 0:
x_vals = sorted(set(x_vals + extra_x_vals))
y_vals1 = [self(x) for x in x_vals]
y_vals2 = [p(x) for x in x_vals]
y_vals1 = [self(x) for x in x_vals]
y_vals2 = [p(x) for x in x_vals]
return (
PiecewiseLinear(*zip(x_vals, y_vals1)),
PiecewiseLinear(*zip(x_vals, y_vals2)),