summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2023-07-03 20:38:38 (GMT)
committerGitHub <noreply@github.com>2023-07-03 20:38:38 (GMT)
commit77090370952307730ea71d68b848cce0dc8cbd83 (patch)
treea157920d019294485579f7c08bf5cc312156037f
parentb4efdf8cda8fbbd0ca53b457d5f6e46a59348caf (diff)
downloadcpython-77090370952307730ea71d68b848cce0dc8cbd83.zip
cpython-77090370952307730ea71d68b848cce0dc8cbd83.tar.gz
cpython-77090370952307730ea71d68b848cce0dc8cbd83.tar.bz2
Small speed-up for the convolve() recipe. (GH-106371)
-rw-r--r--Doc/library/itertools.rst4
1 files changed, 2 insertions, 2 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 56d6599..a2d1798 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -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.