From: Raymond Hettinger Date: Mon, 3 Jul 2023 20:38:38 +0000 (-0500) Subject: Small speed-up for the convolve() recipe. (GH-106371) X-Git-Tag: v3.13.0a1~1540 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77090370952307730ea71d68b848cce0dc8cbd83;p=thirdparty%2FPython%2Fcpython.git Small speed-up for the convolve() recipe. (GH-106371) --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 56d6599798af..a2d1798a2c6d 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.