Skip to content

Commit 0f4b788

Browse files
committed
remove out of bound checking for the piecewise tendency
1 parent d137ed6 commit 0f4b788

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

tests/tendencies/test_piecewise.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ def test_generate():
107107
assert not tendency.annotations
108108

109109

110+
def test_get_value_bounds():
111+
"""
112+
Check the generated values outside of the time array.
113+
"""
114+
tendency = PiecewiseLinearTendency(
115+
user_time=np.array([1, 2, 3]), user_value=np.array([2, 4, 8])
116+
)
117+
_, values = tendency.get_value(np.array([0.0, 0.5, 1.0, 3.0, 3.5, 4.0]))
118+
assert np.allclose(values, [2, 2, 2, 8, 8, 8])
119+
assert not tendency.annotations
120+
121+
110122
def test_get_value_interpolate():
111123
"""
112124
Check the generated interpolated values.
@@ -125,15 +137,15 @@ def test_get_value_interpolate():
125137
)
126138
time, values = tendency.get_value(np.array([0.5, 1.5, 2.0, 2.5, 3.0]))
127139
assert np.allclose(values, [2.0, 3.0, 4.0, 6.0, 8.0])
128-
assert tendency.annotations
140+
assert not tendency.annotations
129141

130142
# Request after time range
131143
tendency = PiecewiseLinearTendency(
132144
user_time=np.array([1, 2, 3]), user_value=np.array([2, 4, 8])
133145
)
134146
time, values = tendency.get_value(np.array([1.0, 1.5, 2.0, 2.5, 3.5]))
135147
assert np.allclose(values, [2.0, 3.0, 4.0, 6.0, 8.0])
136-
assert tendency.annotations
148+
assert not tendency.annotations
137149

138150

139151
def test_get_derivative_interpolate():
@@ -159,7 +171,7 @@ def test_get_derivative_interpolate():
159171
)
160172
expected_derivatives = [2, 2, -1, -1, -0.5, -0.5, -0.5, -0.5, 2, 2, 2, 2, 2]
161173
assert np.allclose(derivatives, expected_derivatives)
162-
assert tendency.annotations
174+
assert not tendency.annotations
163175

164176
# Request derivative after time range
165177
tendency = PiecewiseLinearTendency(
@@ -170,4 +182,4 @@ def test_get_derivative_interpolate():
170182
)
171183
expected_derivatives = [2, 2, -1, -1, -0.5, -0.5, -0.5, -0.5, 2, 2, 2, 2, 2]
172184
assert np.allclose(derivatives, expected_derivatives)
173-
assert tendency.annotations
185+
assert not tendency.annotations

waveform_editor/tendencies/piecewise.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def get_value(
4646
if time is None:
4747
return self.time, self.value
4848

49-
self._validate_requested_time(time)
5049
interpolated_values = np.interp(time, self.time, self.value)
5150
return time, interpolated_values
5251

@@ -59,7 +58,6 @@ def get_derivative(self, time: np.ndarray) -> np.ndarray:
5958
Returns:
6059
numpy array containing the derivatives
6160
"""
62-
self._validate_requested_time(time)
6361

6462
# Compute piecewise derivatives
6563
dv = np.diff(self.value)
@@ -72,19 +70,6 @@ def get_derivative(self, time: np.ndarray) -> np.ndarray:
7270

7371
return piecewise_derivatives[indices]
7472

75-
def _validate_requested_time(self, time):
76-
"""Check if the requested time data falls within the piecewise tendency.
77-
78-
Args:
79-
time: The time array on which to generate points.
80-
"""
81-
if np.any(time < self.time[0]) or np.any(time > self.time[-1]):
82-
error_msg = (
83-
f"The provided time array contains values outside the valid range "
84-
f"({self.time[0]}, {self.time[-1]}).\n"
85-
)
86-
self.annotations.add(self.line_number, error_msg)
87-
8873
def _validate_time_value(self, time, value):
8974
"""Validates the provided time and value lists.
9075

0 commit comments

Comments
 (0)