Small speed-up for the convolve() recipe. (GH-106371)

This commit is contained in:
Raymond Hettinger 2023-07-03 15:38:38 -05:00 committed by GitHub
parent b4efdf8cda
commit 7709037095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -1085,8 +1085,8 @@ The following recipes have a more mathematical flavor:
kernel = tuple(kernel)[::-1]
n = len(kernel)
padded_signal = chain(repeat(0, n-1), signal, repeat(0, n-1))
for window in sliding_window(padded_signal, n):
yield math.sumprod(kernel, window)
windowed_signal = sliding_window(padded_signal, n)
return map(math.sumprod, repeat(kernel), windowed_signal)
def polynomial_from_roots(roots):
"""Compute a polynomial's coefficients from its roots.