MCPcopy Index your code
hub / github.com/evalplus/evalplus / fix

Function fix

tools/humaneval/fix_v014.py:37–57  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

35
36
37def fix(data):
38 check_id(data, 32)
39 data[32]["contract"] = (
40 '\n assert isinstance(xs, list) and len(xs) > 0 and len(xs) % 2 == 0, "invalid inputs" # $_CONTRACT_$'
41 + '\n assert all(type(x) == int for x in xs), "invalid inputs" # $_CONTRACT_$'
42 + "\n dxs = [xs[i] * i for i in range(1, len(xs))] # $_CONTRACT_$"
43 + "\n def func(x): # $_CONTRACT_$"
44 + "\n return poly(xs, x) # $_CONTRACT_$"
45 + "\n def derivative(x): # $_CONTRACT_$"
46 + "\n return poly(dxs, x) # $_CONTRACT_$"
47 + "\n x, tol = 0, 1e-5 # $_CONTRACT_$"
48 + "\n for _ in range(1000): # $_CONTRACT_$"
49 + "\n fx = func(x) # $_CONTRACT_$"
50 + "\n dfx = derivative(x) # $_CONTRACT_$"
51 + "\n if abs(fx) < tol: break # $_CONTRACT_$"
52 + "\n x = x - fx / dfx # $_CONTRACT_$"
53 + '\n assert abs(poly(xs, x)) < tol, "invalid inputs" # $_CONTRACT_$\n'
54 )
55 data[32]["plus_input"] = [l for l in data[32]["plus_input"] if check_valid(l[0])]
56
57 return data
58
59
60if __name__ == "__main__":

Callers 1

fix_v014.pyFile · 0.70

Calls 2

check_idFunction · 0.70
check_validFunction · 0.70

Tested by

no test coverage detected