file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f13645.py
|
def f(v: float, divisor: int = 8) -> int:
n = v / divisor
return int(max(n + 0.5, n * 0.9 + 1)) * divisor
assert f(1.0123456) == 8
|
benchmark_functions_edited/f12490.py
|
def f(array, pivot):
i = -1
j = 0
while j < len(array) - 1:
if array[j] == pivot:
array[-1], array[j] = array[j], array[-1]
continue
elif array[j] < pivot:
i += 1
array[i], array[j] = array[j], array[i]
j += 1
array[-1], array[i + 1] = array[i + 1], array[-1]
return i + 1
assert f(list('asdfg'), 'a') == 0
|
benchmark_functions_edited/f13974.py
|
def f(points, fga, tpfga, fta):
try:
ts = points / (2.0 * ((fga + tpfga) + 0.44 * fta))
except ZeroDivisionError:
ts = 0
return round(ts, 3)
assert f(0, 0, 0, 10) == 0
|
benchmark_functions_edited/f777.py
|
def f(rho, U, L, mu):
Re = (rho * U * L) / mu
return Re
assert f(1, 2, 1, 2) == 1
|
benchmark_functions_edited/f12747.py
|
def f(norm_power, threshold_power, duration):
ss = (duration/3600) * (norm_power/threshold_power)**2 * 100
return ss
assert f(1000, 125, 0) == 0
|
benchmark_functions_edited/f423.py
|
def f(x):
return 1 if x > 0 else (-1 if x < 0 else 0)
assert f(0) == 0
|
benchmark_functions_edited/f1494.py
|
def f(N):
if N==0:
return 0
elif N<=4:
return 1
else:
return (N-4)//2 + 1 + N%2
assert f(0) == 0
|
benchmark_functions_edited/f3748.py
|
def f(a, b):
if a==b: return 1
else: return 0
assert f(1, 1) == 1
|
benchmark_functions_edited/f4918.py
|
def f(utt, history):
return int("?" in utt)
assert f(
"hi how are you?",
["hello", "how are you?"]
) == 1
|
benchmark_functions_edited/f12623.py
|
def f(side_length: float) -> float:
if side_length < 0:
raise ValueError("f() only accepts non-negative values")
return side_length ** 2
assert f(0) == 0
|
benchmark_functions_edited/f11199.py
|
def f(inputPos, in_min, in_max, out_min, out_max):
scale = ((out_max - out_min) / (in_max - in_min))
return float(((inputPos - in_min) * scale) + out_min)
assert f(10, 0, 100, 0, 10) == 1
|
benchmark_functions_edited/f13313.py
|
def f(theta1_min: float, theta1_max: float, theta1_step=1) -> int:
n_trace = int((theta1_max - theta1_min) / theta1_step + 1)
return n_trace
assert f(0, 11, 6) == 2
|
benchmark_functions_edited/f14321.py
|
def f(answer, base, mod):
log = 1
val = base
while True:
if answer == val:
return log
log += 1
val = (val * base) % mod
assert f(3, 5, 11) == 2
|
benchmark_functions_edited/f2616.py
|
def f(lst):
return sum(lst) / len(lst)
assert f( [1, 2, 3, 4, 5] ) == 3
|
benchmark_functions_edited/f8304.py
|
def f(number) -> int:
return int(number) if number - int(number) <= 0 else int(number) + 1
assert f(1.0) == 1
|
benchmark_functions_edited/f6607.py
|
def f(idx, shape):
assert len(idx) == len(shape)
if not idx:
return 0
assert idx < shape
return idx[-1] + (shape[-1] * f(idx[:-1], shape[:-1]))
assert f((1, ), (2, )) == 1
|
benchmark_functions_edited/f5807.py
|
def f(b):
if b == "":
return 0
else:
return 2 * f(b[:-1]) + int(b[-1])
assert f("1000") == 8
|
benchmark_functions_edited/f12626.py
|
def f(x):
items = iter(x)
first = next(items)
for item in items:
if item != first:
raise ValueError("Values are not identical: {}, {}".format(first, item))
return first
assert f({1:1, 1:1, 1:1}) == 1
|
benchmark_functions_edited/f1419.py
|
def f(n, start=(0, 1)):
a, b = start
while n > 0:
a, b = b, a + b
n -= 1
return n
assert f(1) == 0
|
benchmark_functions_edited/f90.py
|
def f(x):
return x.__trunc__()
assert f(1) == 1
|
benchmark_functions_edited/f6793.py
|
def f(n):
if n == 0:
return 1
elif n == 1:
return 1
else:
return f(n-1) + f(n-2)
assert f(0) == 1
|
benchmark_functions_edited/f6839.py
|
def f(items):
return float(sum(items)) / len(items)
assert f([1, 2, 3, 4, 5]) == 3
|
benchmark_functions_edited/f13742.py
|
def f(a, b):
sentenceerror = "%s,%s must be positive integers" % (str(a), str(b))
if not isinstance(a, int) or not isinstance(b, int):
raise TypeError(sentenceerror)
if a <= 0 or b <= 0:
raise TypeError(sentenceerror)
while a != b:
if a < b:
a, b = b, a
a, b = a - b, b
return a
assert f(8, 4) == 4
|
benchmark_functions_edited/f1791.py
|
def f(n):
return sum([number for number in range(n + 1)])
assert f(1) == 1
|
benchmark_functions_edited/f12807.py
|
def f(H, delta_P, A_i, v, A_s, E, alpha, delta_T): # pragma: no cover
pressure_term = delta_P * A_i * (1 - 2 * v)
temperature_term = A_s * E * alpha * delta_T
return H - pressure_term - temperature_term
assert f(1, 0, 1, 1, 1, 1, 1, 1) == 0
|
benchmark_functions_edited/f14314.py
|
def f(sequence, condition):
for i, item in enumerate(sequence):
if condition(item):
return i
raise ValueError()
assert f("hello world", lambda item: item == "l") == 2
|
benchmark_functions_edited/f13228.py
|
def f(number):
try:
x = round(float(number))
except ValueError:
x = 0
return x
assert f("1.0") == 1
|
benchmark_functions_edited/f7868.py
|
def f(dep : dict,l):
i_0 = len(dep.values())
for i,dep_to_add in enumerate(l):
dep[dep_to_add] = i+i_0
return len(dep.values())
assert f(dict(),["A","B"]) == 2
|
benchmark_functions_edited/f12022.py
|
def f(x, dx, eps=1e-2, alfa=0.1, method='decm'):
if method == 'decm':
alfa0 = (eps-1)*x/dx
for a in alfa0:
if a>=0:
alfa = min(alfa, a)
else:
alfa = 1
return alfa
assert f(1, 0.1, 1, 2, 3) == 1
|
benchmark_functions_edited/f707.py
|
def f(prevc, c):
return prevc << 32 | c
assert f(0, 0) == 0
|
benchmark_functions_edited/f4070.py
|
def f(val, ref_val):
return (val - ref_val) / ref_val if ref_val != 0 else 0.0
assert f(100, 0) == 0
|
benchmark_functions_edited/f10166.py
|
def f(value, mapper, default):
return mapper(value) if value is not None else default
assert f('', len, 0) == 0
|
benchmark_functions_edited/f7374.py
|
def f(n, adj_mat, sol):
return sum([adj_mat[sol[_]][sol[(_ + 1) % n]] for _ in range(n)])
assert f(3, [[0,1,0], [1,0,1], [0,1,0]], [0,2,1]) == 2
|
benchmark_functions_edited/f7698.py
|
def f(p, x) -> float:
if not isinstance(p,(list,tuple)):
p = [p]
y = p[-1]
for i in range(len(p)-2,-1,-1):
y = p[i] + y*x
return y
assert f([0], 2) == 0
|
benchmark_functions_edited/f480.py
|
def f(name):
size_name = len(name)
return size_name
assert f('Dave') == 4
|
benchmark_functions_edited/f4832.py
|
def f(x):
try:
x = float(x)
if x % 1 == 0:
x = int(x)
except ValueError:
pass
return(x)
assert f('5') == 5
|
benchmark_functions_edited/f10940.py
|
def f(r, incborder=1):
w = r[2]-r[0] + incborder
h = r[3]-r[1] + incborder
if w <= 0 or h <= 0: return 0
return w * h
assert f( (1, 1, 0, 0), 0 ) == 0
|
benchmark_functions_edited/f11879.py
|
def f(lado_1, lado_2, lado_3):
return lado_1 + lado_2 + lado_3
assert f(1, 1, 1) == 3
|
benchmark_functions_edited/f4397.py
|
def f(string):
try:
return float(string)
except (ValueError, TypeError):
return string
assert f(4) == 4
|
benchmark_functions_edited/f7686.py
|
def f(lst):
if not not lst:
return lst[len(lst)-1]
else:
return
assert f([1]) == 1
|
benchmark_functions_edited/f2084.py
|
def f(x, x0, gamma, alpha):
return alpha * gamma / ((x-x0)**2 + gamma ** 2)
assert f(100, 100, 100, 0) == 0
|
benchmark_functions_edited/f11496.py
|
def f(n):
if n == 0:
return 0
if n % 2 == 0:
return f(n / 2)
if n % 2 == 1:
return 1 - f((n - 1) / 2)
assert f(22) == 1
|
benchmark_functions_edited/f12203.py
|
def f(s, const):
v = 0
p = len(s)-1
for i in reversed(range(p+1)):
v += int(s[i]) * (const ** p)
p -= 1
return v
assert f('', 19) == 0
|
benchmark_functions_edited/f13666.py
|
def f(n):
# begin solution
s = 0
for i in range(n):
if i % 3 == 0 or i % 5 == 0:
s += i
return s
# end solution
assert f(5) == 3
|
benchmark_functions_edited/f1516.py
|
def f(theta):
if theta < 60.0:
return 1
else:
return 0
assert f(90.0) == 0
|
benchmark_functions_edited/f12486.py
|
def f(entropy, subset_indices, alpha=1.):
if len(subset_indices) == 0:
return 0
else:
u_score = alpha*entropy[subset_indices]
return u_score
assert f(0.5, []) == 0
|
benchmark_functions_edited/f1676.py
|
def f(u, v):
return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]
assert f(
(0, 0, 1),
(0, 0, 1),
) == 1
|
benchmark_functions_edited/f4075.py
|
def f(key, dictionary):
if key in dictionary:
return dictionary[key]
return 0
assert f("baz", {"foo": "bar"}) == 0
|
benchmark_functions_edited/f1799.py
|
def f(n):
return len("{0:b}".format(n))
assert f(5) == 3
|
benchmark_functions_edited/f7614.py
|
def f(x, a, b):
l = 0
# if not torch.isreal(x):
# return l
if a <= b:
if x >= a and x <= b:
l = 1
else:
if x >= b and x <= a:
l = 1
return l
assert f(0.2, 0.1, 0.3) == 1
|
benchmark_functions_edited/f11675.py
|
def f(input_list):
ris = 0
for l in input_list:
for x in l:
if x[1] is None:
ris += 1
return ris
assert f(
[
[
("topic1", None),
("topic2", None),
],
[
("topic3", None),
("topic4", None),
],
]
) == 4
|
benchmark_functions_edited/f11091.py
|
def f(credit, debit):
credit_sum = 0
for entry in credit:
credit_sum += entry.amount
debit_sum = 0
for entry in debit:
debit_sum += entry.amount
return credit_sum - debit_sum
assert f([], []) == 0
|
benchmark_functions_edited/f5875.py
|
def f(a, b):
result = (a + b) % 0x10000
assert 0 <= result <= 0xFFFF
return result
assert f(0x10000, 0x10000) == 0
|
benchmark_functions_edited/f6721.py
|
def f(F, x, h, order, points, prefacs, args, kwargs):
return sum(prefac * F(x + point*h, *args, **kwargs) for point, prefac in zip(points, prefacs)) / (h**order)
assert f(lambda x: 3, 0, 1, 1, [0], [1], [], {}) == 3
|
benchmark_functions_edited/f4906.py
|
def f(error, real_word):
if error == 5:
print("You lost!")
print("Real word is:", real_word)
else:
print("You won!")
return 0
assert f(0, "fig") == 0
|
benchmark_functions_edited/f7305.py
|
def f(version):
return 4 if version > 0 else 2
assert f(9) == 4
|
benchmark_functions_edited/f9912.py
|
def f(start, ndim):
if start < -ndim or start > ndim:
raise ValueError(f"For rollaxis, start {start} is out of bounds. Ranging from {-ndim} to {ndim} is allowed.")
if start < 0:
start = start + ndim
return start
assert f(3, 5) == 3
|
benchmark_functions_edited/f1594.py
|
def f(pos):
return -(pos * (pos - 2))
assert f(0) == 0
|
benchmark_functions_edited/f2377.py
|
def f(char, word):
return word.count(char)
# If you want to do it manually try a for loop
assert f("a", "cat") == 1
|
benchmark_functions_edited/f5921.py
|
def f(confstr, default=None):
ret = default
try:
ret = int(confstr)
except:
pass # ignore errors and fall back on default
return ret
assert f("+1") == 1
|
benchmark_functions_edited/f270.py
|
def f(t, a, b):
return a*t + b
assert f(2, 1, 1) == 3
|
benchmark_functions_edited/f3775.py
|
def f(regions):
mw = 0
for r in regions:
mw = max(mw, r.profEntry.weight)
return mw
assert f([]) == 0
|
benchmark_functions_edited/f9831.py
|
def f(string):
if isinstance(string, str):
return string.replace('\'', '\"').replace('\\', '\\\\')
else:
return string
assert f(1) == 1
|
benchmark_functions_edited/f5865.py
|
def f(val: int, in_min: int, in_max: int, out_min: int, out_max: int) -> int:
return int((val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)
assert f(0, 0, 20, 0, 20) == 0
|
benchmark_functions_edited/f4597.py
|
def f(qty_bytes):
bytes_in_gb = 1024 * 1024 * 1024
qty_gb = qty_bytes / bytes_in_gb
return round(qty_gb, 2)
assert f(1) == 0
|
benchmark_functions_edited/f13407.py
|
def f(phases, cut):
from itertools import permutations
def perms(phase):
return [list(i) for i in permutations(phase.split())]
print("Searching the clean validation cut...")
while phases[cut].split() in perms(phases[cut-1]):
#print('Cut at index:', cut, phases[cut])
cut += 1
return cut
assert f(
['A', 'B', 'C', 'D', 'A', 'D', 'C', 'B', 'A'], 0
) == 1
|
benchmark_functions_edited/f8201.py
|
def f(n):
# import pdb; pdb.set_trace()
if n <= 2:
return n
dp = [0 for __ in range(n)]
dp[0] = 1
dp[1] = 2
for i in range(2, n):
dp[i] = dp[i - 1] + dp[i - 2]
return dp[n - 1]
assert f(1) == 1
|
benchmark_functions_edited/f5170.py
|
def f(sow):
if sow < 0 or sow > 86400e0 * 7:
raise RuntimeError('[ERROR] gnssdates::sow2dow Invalid date.')
return int(sow) // 86400
assert f(86400*6) == 6
|
benchmark_functions_edited/f6739.py
|
def f(x1, x2, history):
history.append((x1, x2))
if x1 == x2:
return 1
else:
return 0.2
assert f(2, 2, []) == 1
|
benchmark_functions_edited/f666.py
|
def f(list):
return float(sum(list)) / max(len(list), 1)
assert f( (1, 2, 3, 4, 5) ) == 3
|
benchmark_functions_edited/f2857.py
|
def f(sub1, sub2):
diff = abs(sub1-sub2)
return abs((diff/255)-1)
assert f(255, 0) == 0
|
benchmark_functions_edited/f7238.py
|
def f(t, y, L_list):
L = L_list[0][0]
for n in range(1, len(L_list)):
L = L + L_list[n][0] * L_list[n][1](t)
return L * y
assert f(1, 1, [(1, lambda t: 1), (1, lambda t: t)]) == 2
|
benchmark_functions_edited/f4692.py
|
def f(loader, filename, index):
return loader(filename, index)
assert f(lambda f, i: i % 2, "filename", 42) == 0
|
benchmark_functions_edited/f1515.py
|
def f(start, end, frac):
diff = end - start
return start + frac * diff
assert f(1, 2, 1.0) == 2
|
benchmark_functions_edited/f8711.py
|
def f(ofile):
data = [next(ofile)]
loc = 1
if data[0].strip()[0] == '{':
raise ValueError("This looks like a sparse ARFF: not supported yet")
for i in ofile:
loc += 1
return loc
assert f(iter(['@RELATION test', '@ATTRIBUTE a NUMERIC', '@ATTRIBUTE b NUMERIC', '@DATA'])) == 4
|
benchmark_functions_edited/f10343.py
|
def f(N, M, mode):
if mode == 'full':
return 0
elif mode == 'valid':
return min(M, N) - 1
elif mode == 'same':
return (min(N, M) - 1) // 2
else:
raise ValueError("mode='{0}' not recognized".format(mode))
assert f(1, 4, 'full') == 0
|
benchmark_functions_edited/f6378.py
|
def f(vec):
m_sum = sum(vec)
from math import log
return m_sum*log(m_sum, 2) - sum([e*log(e, 2) for e in vec if e != 0])
assert f( [0, 2, 0, 0, 0, 0, 0, 0, 0, 0] ) == 0
|
benchmark_functions_edited/f485.py
|
def f(base, height):
return base * height / 2
assert f(3, 4) == 6
|
benchmark_functions_edited/f6965.py
|
def f(N_ESS):
table_20_14 = {0: 0,
1: 1,
2: 2,
3: 4}
return table_20_14[N_ESS]
assert f(2) == 2
|
benchmark_functions_edited/f13180.py
|
def f(line, tab_length):
line = line.expandtabs(tab_length)
indentation = (len(line) - len(line.lstrip(' '))) // tab_length
if line.rstrip().endswith(':'):
indentation += 1
elif indentation >= 1:
if line.lstrip().startswith(('return', 'pass', 'raise', 'yield')):
indentation -= 1
return indentation
assert f( ' ', 4) == 0
|
benchmark_functions_edited/f6162.py
|
def f(x):
val = x
while True:
last = val
val = (val + x /val) * 0.5
if abs(val - last) < 1e-9:
break
return val
assert f(4) == 2
|
benchmark_functions_edited/f10958.py
|
def f(a, b):
assert len(a) == 2
assert len(b) == 2
x = a[0] - b[0]
y = a[1] - b[1]
return (x * x) + (y * y)
assert f((0, 0), (0, 2)) == 4
|
benchmark_functions_edited/f903.py
|
def f(G, E):
return E/(2*G)-1
assert f(1, 2) == 0
|
benchmark_functions_edited/f1180.py
|
def f(b: bytes):
return int.from_bytes(b, byteorder='big')
assert f(b'\x00\x00\x00\x08') == 8
|
benchmark_functions_edited/f1397.py
|
def f(x) -> int:
assert x == 0
return 0
assert f(-0.0) == 0
|
benchmark_functions_edited/f7784.py
|
def f(l, i, d=None):
if type(l) in (dict, set):
return l[i] if i in l else d
try:
return l[i]
except (IndexError, KeyError, TypeError):
return d
assert f([2], 0) == 2
|
benchmark_functions_edited/f11755.py
|
def f(i: int, n: int) -> int:
if i % n == 0:
return i // n
else:
return (i // n) + 1
assert f(8, 3) == 3
|
benchmark_functions_edited/f3306.py
|
def f(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return f(n-1) + f(n-2)
assert f(0) == 0
|
benchmark_functions_edited/f7598.py
|
def f(x, y, z):
result = x
if y > result:
result = y
elif z > result:
result = z
return result
assert f(9, 3, 5) == 9
|
benchmark_functions_edited/f10027.py
|
def f(text: str):
words = len(sorted(set(text.split())))
lenght = len(text)
uniqueness = lenght + words
return uniqueness
assert f('') == 0
|
benchmark_functions_edited/f5124.py
|
def f(pred, iterable):
for v in iterable:
if pred(v):
return v
return None
assert f(lambda n: n > 0, range(0, 5)) == 1
|
benchmark_functions_edited/f9199.py
|
def f(a, b):
assert len(a) == len(b)
d = 0
for feature in range(len(a)):
d += (a[feature] - b[feature]) ** 2
return d ** 0.5
assert f(
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]
) == 0
|
benchmark_functions_edited/f14463.py
|
def f(TP, FP, FN, beta):
try:
result = ((1 + (beta)**2) * TP) / \
((1 + (beta)**2) * TP + FP + (beta**2) * FN)
return result
except (ZeroDivisionError, TypeError):
return "None"
assert f(0, 0, 1, 0.5) == 0
|
benchmark_functions_edited/f2901.py
|
def f(i, j):
if i == j:
return i
return 6-i-j
assert f(2, 2) == 2
|
benchmark_functions_edited/f10358.py
|
def f(cred, cgreen, cblue):
redval = int(round(cred))
greenval = int(round(cgreen))
blueval = int(round(cblue))
ret = int(redval * 0x10000 + greenval * 0x100 + blueval)
if ret < 0:
ret = 0
if ret > 0x00ffffff:
ret = 0x00ffffff
return ret
assert f(0, 0, 0.0) == 0
|
benchmark_functions_edited/f7491.py
|
def f(gen_input, *gen_funcs):
for func in gen_funcs:
gen_input = func(gen_input)
return gen_input
assert f(2, lambda x: x**2) == 4
|
benchmark_functions_edited/f6207.py
|
def f(x):
if x is None:
return None
return int(x)
assert f(1.9) == 1
|
benchmark_functions_edited/f9066.py
|
def f(cls_name, label_map):
if cls_name in label_map:
return label_map[cls_name]
raise ValueError('Invalid class')
assert f(
"dandelion",
{"dandelion": 1, "daisy": 2, "tulip": 3}
) == 1
|
benchmark_functions_edited/f973.py
|
def f(y, z):
val = y * z
return val
assert f(1,2) == 2
|
benchmark_functions_edited/f5357.py
|
def f(label):
label_length = 5
while label_length < len(label) and label[label_length].isdigit():
label_length += 1
return label_length
assert f('AAAA') == 5
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.