Skip to content

Commit f938c23

Browse files
committed
reverted singleton interpolation
1 parent 39c7cd4 commit f938c23

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

mir_eval/sonify.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,23 @@ def time_frequency(
167167
time_centers = np.mean(times, axis=1) * float(fs)
168168

169169
# Interpolate the values in gram over the time grid.
170-
gram_interpolator = interp1d(
171-
times[:, 0] * fs,
172-
gram[:, :n_times],
173-
kind="previous",
174-
bounds_error=False,
175-
fill_value=(gram[:, 0], gram[:, -1]),
176-
)
177-
signal = gram_interpolator(np.arange(length))
170+
if n_times > 1:
171+
interpolator = interp1d(
172+
times[:, 0] * fs,
173+
gram[:, :n_times],
174+
kind="previous",
175+
bounds_error=False,
176+
fill_value=(gram[:, 0], gram[:, -1]),
177+
)
178+
else:
179+
# NOTE: This is a special case where there is only one time interval.
180+
# scipy 1.10 and above handle this case directly with the interp1d above,
181+
# but older scipy's do not. This is a workaround for that.
182+
#
183+
# In the 0.9 release, we can bump the minimum scipy to 1.10 and remove this
184+
interpolator = _const_interpolator(gram[:, 0])
185+
186+
signal = interpolator(np.arange(length))
178187

179188
# Check if there is at least one element on each frequency that has a value above the threshold
180189
# to justify processing, for optimisation.
@@ -202,6 +211,17 @@ def time_frequency(
202211
return output
203212

204213

214+
def _const_interpolator(value):
215+
"""Return a function that returns `value`
216+
no matter the input.
217+
"""
218+
219+
def __interpolator(x):
220+
return value
221+
222+
return __interpolator
223+
224+
205225
def _fast_synthesize(frequency, n_dec, fs, function, length):
206226
"""Efficiently synthesize a signal.
207227
Generate one cycle, and simulate arbitrary repetitions

0 commit comments

Comments
 (0)