Connection
Base URL, credentials and a reachable server.
Check repeated maxima, negative values and width boundaries, rejecting non-finite values and widths outside the input length.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
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