WWindowRidge
Workflows

Coding workflows · Sliding-window maxima

03
Built around your work

A concrete starting point

Find the maximum in each complete fixed-width numeric window. Check repeated maxima, negative values and width boundaries, rejecting non-finite values and widths outside the input length.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Sliding-window maxima

A concrete starting point
from collections import deque
from math import isfinite
def window_max(values, width):
    if type(width) is not int or not 1 <= width <= len(values):
        raise ValueError("width")
    if not all(map(isfinite, values)): raise ValueError("finite values")
    queue, result = deque(), []
    for i, value in enumerate(values):
        while queue and queue[0] <= i - width: queue.popleft()
        while queue and values[queue[-1]] <= value: queue.pop()
        queue.append(i)
        if i >= width - 1: result.append(values[queue[0]])
    return result

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗