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

Function check_valid

tools/humaneval/fix_v014.py:12–34  ·  view source on GitHub ↗
(xs)

Source from the content-addressed store, hash-verified

10
11
12def check_valid(xs):
13 if not (isinstance(xs, list) and len(xs) > 0 and len(xs) % 2 == 0):
14 return False
15 if not all(type(x) == int for x in xs):
16 return False
17 dxs = [xs[i] * i for i in range(1, len(xs))]
18
19 def func(x):
20 return poly(xs, x)
21
22 def derivative(x):
23 return poly(dxs, x)
24
25 x, tol = 0, 1e-5
26 for _ in range(1000):
27 fx = func(x)
28 dfx = derivative(x)
29 if abs(fx) < tol:
30 break
31 x = x - fx / dfx
32 if abs(poly(xs, x)) >= tol:
33 return False
34 return True
35
36
37def fix(data):

Callers 1

fixFunction · 0.70

Calls 3

funcFunction · 0.85
derivativeFunction · 0.85
polyFunction · 0.85

Tested by

no test coverage detected