Open the context
Choose the project folder and name the files or behavior involved.
Fit a nondecreasing sequence to at most 128 finite observations bounded by ±10^6 with equal least-squares weights. Test empty and descending inputs, rejecting Booleans and preserving the source list.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import isfinite
def isotonic_fit(values):
if type(values) is not list or len(values) > 128:
raise ValueError("bounded list")
if any(type(x) not in (int, float) or abs(x) > 10**6 or
not isfinite(x) for x in values):
raise ValueError("bounded finite values")
blocks = []
for value in values:
blocks.append([float(value), 1])
while len(blocks) > 1 and (
blocks[-2][0] / blocks[-2][1] > blocks[-1][0] / blocks[-1][1]):
total, count = blocks.pop()
blocks[-1][0] += total; blocks[-1][1] += count
return [total / count for total, count in blocks for _ in range(count)]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.