file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f1081.py
|
def f(val):
return int.from_bytes(val,"little")
assert f(b'\x00\x00\x00\x00') == 0
|
benchmark_functions_edited/f1070.py
|
def f(val):
try:
return int(val)
except:
return int(0)
assert f('0') == 0
|
benchmark_functions_edited/f9167.py
|
def f(nums):
xor = 0
for n in nums:
xor ^= n
return xor
assert f(
[9, 3, 9, 3, 9, 7, 9]
) == 7
|
benchmark_functions_edited/f14059.py
|
def f(x, y):
if len(x) == 0:
return len(y)
elif len(y) == 0:
return len(x)
else:
distHor = f(x[:-1], y) + 1
distVer = f(x, y[:-1]) + 1
if x[-1] == y[-1]:
distDiag = f(x[:-1], y[:-1])
else:
distDiag = f(x[:-1], y[:-1]) + 1
return min(distDiag, distHor, distVer)
assert f('', '') == 0
|
benchmark_functions_edited/f927.py
|
def f(x):
return (x & -x).bit_length() - 1
assert f(0x80) == 7
|
benchmark_functions_edited/f7172.py
|
def f(dictionary, key):
val = dictionary.get(key)
if val is None or not isinstance(val, str):
return None
if not val.isdigit():
return None
return int(val)
assert f(
{
'a': 1,
'b': '2'
},
'b'
) == 2
|
benchmark_functions_edited/f3914.py
|
def f(value):
return -int(-value//1)
assert f(1.000001) == 2
|
benchmark_functions_edited/f451.py
|
def f(X, Y):
return -(X**2 + Y**2)
assert f(0, 0) == 0
|
benchmark_functions_edited/f7103.py
|
def f(y, y_mean, y_std, scale_std=False):
if not scale_std:
y = y * y_std + y_mean
else:
y *= y_std
return y
assert f(2, 0, 1) == 2
|
benchmark_functions_edited/f8997.py
|
def f(lists):
total = 0
lists = list(lists)
while lists:
item = lists.pop()
if isinstance(item, list):
lists.extend(item)
else:
total += item
return total
assert f([1]) == 1
|
benchmark_functions_edited/f12480.py
|
def f(colorstring):
colorstring = colorstring.strip()
while colorstring[0] == '#': colorstring = colorstring[1:]
# get bytes in reverse order to deal with PIL quirk
colorstring = colorstring[-2:] + colorstring[2:4] + colorstring[:2]
# finally, make it numeric
color = int(colorstring, 16)
return color
assert f('#000000') == 0
|
benchmark_functions_edited/f11519.py
|
def f(hospital, hospital_prefs, matching):
return max(
[
hospital_prefs[hospital].index(resident)
for resident in hospital_prefs[hospital]
if resident in matching[hospital]
]
)
assert f(1, [[0, 1], [1, 2, 3]], {0: [0], 1: [1, 2, 3]}) == 2
|
benchmark_functions_edited/f3936.py
|
def f(p0, p1, p2, p3, t):
return (1-t)**3*p0 + 3*(1-t)**2*t*p1 + 3*(1-t)*t**2*p2 + t**3*p3
assert f(1, 2, 3, 4, 1) == 4
|
benchmark_functions_edited/f14146.py
|
def f(obj, quiet=False):
# Try "2" -> 2
try:
return int(obj)
except (ValueError, TypeError):
pass
# Try "2.5" -> 2
try:
return int(float(obj))
except (ValueError, TypeError):
pass
# Eck, not sure what this is then.
if not quiet:
raise TypeError("Can not translate '%s' (%s) to an integer"
% (obj, type(obj)))
return obj
assert f(2.5) == 2
|
benchmark_functions_edited/f8842.py
|
def f(start, end, validators):
count = 0
for number in range(start, end + 1):
if all(validator(number) for validator in validators):
count += 1
return count
assert f(1, 1, []) == 1
|
benchmark_functions_edited/f13255.py
|
def f(Cu, Cth, Ck, density=2700, c1=9.52, c2=2.56, c3=3.48):
return (10e-5)*density*(c1 * Cu + c2 * Cth + c3 * Ck)
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f7265.py
|
def f(wvl, data, unc):
unc_wvl = unc
return unc_wvl
assert f(1500, 20, 4) == 4
|
benchmark_functions_edited/f11670.py
|
def f(t=None):
# python2.3 localtime() can't take None
from time import time, daylight, altzone, timezone, localtime
if t is None:
t = time()
if localtime(t).tm_isdst and daylight:
return -altzone
else:
return -timezone
assert f(24*3600 + 1 + f(24*3600 + 1)) == 0
|
benchmark_functions_edited/f14488.py
|
def f(a, b): # (1)
if a < 0: a = -a
if b < 0: b = -b
if a == 0: return b
if b == 0: return a
while b != 0:
(a, b) = (b, a%b)
return a
assert f(5, 20) == 5
|
benchmark_functions_edited/f12692.py
|
def f(k, inverse_scale_factor):
if k == 0:
return 1;
return (1 / (inverse_scale_factor * (k + 1)))
assert f(0, 0.03) == 1
|
benchmark_functions_edited/f2465.py
|
def f(address, align):
return address + ((align - (address % align)) % align)
assert f(1, 4) == 4
|
benchmark_functions_edited/f10316.py
|
def f(aList_in):
iFlag_unique = 1
for elem in aList_in:
if aList_in.count(elem) > 1:
iFlag_unique = 0
break
else:
pass
return iFlag_unique
assert f(
[1,2,3,4]
) == 1
|
benchmark_functions_edited/f8035.py
|
def f(string):
try:
docid = int(string)
except ValueError:
# print("Error converting docid to integer:", string)
docid = 0
return docid
assert f("-0000000000") == 0
|
benchmark_functions_edited/f7342.py
|
def f(n):
u = [1]
en = n
while en > 0:
u.extend([u[0] * 2 + 1, u[0] * 3 + 1])
u.pop(0)
u = sorted(list(set(u)))[:n + 1]
en -= 1
return u[0]
assert f(0) == 1
|
benchmark_functions_edited/f5043.py
|
def f(val, min, max):
if val > max:
val = max
elif val < min:
val = min
return val
assert f(1, 0, 1) == 1
|
benchmark_functions_edited/f1430.py
|
def f(*args):
ret = min(v for v in args if v is not None)
return ret
assert f(3, 5, 8, None) == 3
|
benchmark_functions_edited/f1931.py
|
def f(N, max_order):
return N // 2 if max_order is None else max_order
assert f(5, **{'max_order': 5}) == 5
|
benchmark_functions_edited/f11239.py
|
def f(s):
f = s % 14
if f < 7:
return 0
elif f < 11:
return 1
else:
return 2
assert f(19) == 0
|
benchmark_functions_edited/f8569.py
|
def f(f, values, i):
if f is not None:
return f
mask = 0
for value in values:
if value is not None and value[i] is not None:
mask |= value[i].getFormat()
return mask
assert f(0, ((1, None), (None, None)), 0) == 0
|
benchmark_functions_edited/f5818.py
|
def f(x):
if x >= 0:
return 1
elif x < 0:
return -1
assert f(1.234) == 1
|
benchmark_functions_edited/f8199.py
|
def f(amino_acids):
return sum(amino_acid == "C" for amino_acid in amino_acids)
assert f( "C") == 1
|
benchmark_functions_edited/f12405.py
|
def f(pprod):
eprod = 0.0025 * pprod**2 #\; (PP \leq 200)
eprod = 0.5 * pprod # (PP > 200)
return eprod
assert f(0) == 0
|
benchmark_functions_edited/f12947.py
|
def f(u, kap, eps):
return kap * (1 + eps * u) ** 3 + 1
assert f(0, 1, 0) == 2
|
benchmark_functions_edited/f6644.py
|
def f(iterator):
return sum(1 for _item in iterator)
assert f(iter([1, 2, 3, 4, 5])) == 5
|
benchmark_functions_edited/f4988.py
|
def getPercentage (times100, divisor):
percentage = (times100 * 100) / divisor
return percentage
assert f(0, 1) == 0
|
benchmark_functions_edited/f8256.py
|
def f(i, j):
if i == j:
return 1
else:
return 0
assert f(3, 4) == 0
|
benchmark_functions_edited/f7197.py
|
def f(targets, map_target_position):
if isinstance(targets, (list, tuple)):
return targets[map_target_position["target"]]
else:
return targets[:, map_target_position["target"]]
assert f((1, 2, 3), {"target": 1}) == 2
|
benchmark_functions_edited/f4004.py
|
def f(listy):
if listy != []:
return (max(listy))
assert f( [5, 4, 3, 2, 1] ) == 5
|
benchmark_functions_edited/f2683.py
|
def f(x, a, r):
return a*x**(a-1) - (a-1)*x**a - r
assert f(2, 1, 1) == 0
|
benchmark_functions_edited/f2224.py
|
def f(list_, index, key):
dict_ = list_[index]
return dict_.get(key)
assert f(
[{'a': 1, 'b': 2}, {'a': 4, 'b': 5}, {'a': 7, 'b': 8}],
2,
'a'
) == 7
|
benchmark_functions_edited/f5201.py
|
def f(a, b):
sum = a + b # addition
return sum
assert f(-100, 100) == 0
|
benchmark_functions_edited/f10586.py
|
def f(first: int, second: int) -> float:
biggest = 0
smallest = 0
if (first < second):
biggest = second
return biggest - first
return first - second
assert f(100, 100) == 0
|
benchmark_functions_edited/f4423.py
|
def f(s):
try:
return int(s)
except ValueError:
return int(s.lower() not in ("false", "no", "off"))
assert f("false") == 0
|
benchmark_functions_edited/f10069.py
|
def f(val, diss_cf, hill_cf):
if val == 0:
return 0
else:
return 1 / (1 + (diss_cf / val) ** hill_cf)
assert f(10, 0, 2) == 1
|
benchmark_functions_edited/f703.py
|
def f(X):
C = sum(X) / len(X)
return C
assert f(set([0,1,2,3,4])) == 2
|
benchmark_functions_edited/f5432.py
|
def f(num):
return sum(2 ** i for i in range(num))
assert f(0) == 0
|
benchmark_functions_edited/f3049.py
|
def f(n):
return n if n < 2 else f(n-1) + f(n-2)
assert f(5) == 5
|
benchmark_functions_edited/f14326.py
|
def f(idx: int, dim: int, neg: bool = True):
if neg:
if idx < 0:
return idx
else:
return (idx + 1) % -(dim + 1)
else:
return idx % dim
assert f(3, 3) == 0
|
benchmark_functions_edited/f4467.py
|
def f(list_or_tensor):
if type(list_or_tensor) == list:
return len(list_or_tensor)
return list_or_tensor.shape[0]
assert f([1, 2, 3]) == 3
|
benchmark_functions_edited/f11314.py
|
def f(cell):
try:
return int(cell)
except ValueError:
try:
return float(cell)
except ValueError:
return cell
assert f("1") == 1
|
benchmark_functions_edited/f12872.py
|
def f(x):
#replacing 8+ rooms with 8 rooms
if x == '8+':
return 8
#if the value is less than 8 and is a number keep it!
if float(x) < 8:
return x
#all the other numbers look like garbage values
#replace those with 1 bathroom since that is 90% of all properties
else:
return 1
assert f('118.23') == 1
|
benchmark_functions_edited/f10335.py
|
def f(item):
if type(item) == list:
return sum(f(subitem) for subitem in item)
else:
return 1
assert f(1) == 1
|
benchmark_functions_edited/f14530.py
|
def f(x, xs, ys):
for index in range(0, len(xs)):
if x < xs[index]:
return ys[index - 1] if index > 0 else ys[index]
return ys[len(ys) - 1]
assert f(0, [1, 2, 3, 4], [1, 3, 4, 5]) == 1
|
benchmark_functions_edited/f12982.py
|
def f(precision_value, recall_value, eps=1e-5):
numerator = 2 * (precision_value * recall_value)
denominator = precision_value + recall_value + eps
return numerator / denominator
assert f(1.0, 0.0) == 0
|
benchmark_functions_edited/f13422.py
|
def f(dictionary, sought):
try:
return dictionary[sought]
except KeyError:
caseless_keys = {k.lower(): k for k in dictionary.keys()}
real_key = caseless_keys[sought.lower()] # allow any KeyError here
return dictionary[real_key]
assert f(
{
'Fred' : 9,
'Barney' : 3,
'Sheila' : 0,
},
'sheila',
) == 0
|
benchmark_functions_edited/f1991.py
|
def f(value, mn, mx):
assert mn <= mx, (mn, mx)
return max(min(value, mx), mn)
assert f(5, 1, 5) == 5
|
benchmark_functions_edited/f498.py
|
def f(a, b):
s = a + b
return s
assert f(2, 1) == 3
|
benchmark_functions_edited/f1173.py
|
def f(x):
return 6 * x ** -2
assert f(1) == 6
|
benchmark_functions_edited/f11584.py
|
def f(x_elem):
if x_elem == 3:
return 2
if x_elem == 4:
return 3
if x_elem == 5:
return 4
return x_elem
assert f(2) == 2
|
benchmark_functions_edited/f1435.py
|
def f(val, lower, upper):
return lower if val < lower else upper if val > upper else val
assert f(1, 0, 10) == 1
|
benchmark_functions_edited/f2002.py
|
def f(ranking):
if len(ranking) < 1: return 0
if int(ranking[0]) >= 3: return 1
else: return 0
assert f([1]) == 0
|
benchmark_functions_edited/f11159.py
|
def f(num: int, den: int) -> int:
return (den - num % den) * ((num % den) != 0)
assert f(5, 6) == 1
|
benchmark_functions_edited/f11611.py
|
def f(point1, point2):
x1, y1 = point1
x2, y2 = point2
dist = abs(x1-x2) + abs(y1-y2)
return dist
assert f( (0, 0), (3, 3) ) == 6
|
benchmark_functions_edited/f5575.py
|
def f(n):
return min(max(0, n), (max(0, n)//2)+1)
assert f(11) == 6
|
benchmark_functions_edited/f8319.py
|
def f(length, logprobs, alpha=0.):
modifier = (((5 + length) ** alpha) /
((5 + 1) ** alpha))
return logprobs / modifier
assert f(10, 1) == 1
|
benchmark_functions_edited/f10677.py
|
def f(d, n):
out = 0
for i in range(1, 6+1):
if d:
out += f(d - 1, n - i)
else:
if n:
return 0
else:
return 1
return out
assert f(5, 2) == 0
|
benchmark_functions_edited/f7539.py
|
def f(stdev, count):
w = int(round((3.5 * stdev) / (count ** (1.0 / 3))))
if w:
return w
else:
return 1
assert f(1, 10) == 2
|
benchmark_functions_edited/f5623.py
|
def f(l):
m = -float("inf") - 1
index = -1
for i in range(len(l)):
if l[i] > m:
index = i
m = l[i]
return index
assert f([1, 2, 3, 4]) == 3
|
benchmark_functions_edited/f16.py
|
def f(x, y):
return -(-x // y)
assert f(20, 5) == 4
|
benchmark_functions_edited/f6147.py
|
def f(disc, positions, time, pos):
# Assume time is zero for now
return positions - ((disc + pos) % positions)
assert f(5, 2, 0, 0) == 1
|
benchmark_functions_edited/f11140.py
|
def f(x, y):
n = 0
while x != 0 and y != 0:
if x % 2 != y % 2:
n += 1
x /= 2
y /= 2
m = x if x != 0 else y
if m != 0:
while m != 0:
if m % 2 == 1:
n += 1
m /= 2
return n
assert f(2, 2) == 0
|
benchmark_functions_edited/f4641.py
|
def f(line):
val = 0
for char in line:
val <<= 1
val += char == "#"
return val
assert f(("#","#","#")) == 7
|
benchmark_functions_edited/f8678.py
|
def f(s):
try:
x = float(s)
except ValueError:
return None
else:
return x
assert f("0") == 0
|
benchmark_functions_edited/f5690.py
|
def f(array: list, i: int) -> int:
if i >= 1:
j = f(array, i-1)
if array[i] < array[j]:
return j
return i
assert f([1], 0) == 0
|
benchmark_functions_edited/f12334.py
|
def f(filename):
tmp = filename.split("_")[-1]
tmp = tmp.split(".")[0]
# parity = tmp[-1]
spin = int(tmp[1:-1])
# return f"{spin:03d}{parity}" # Examples: 000p, 000n, 016p, 016n
return spin
assert f(r"log_Sc44_GCLSTsdpfsdgix5pn_j0p.txt") == 0
|
benchmark_functions_edited/f5368.py
|
def f(feet=0, inches=0): #the zero is a default argument
in_to_cm = inches*2.54
ft_to_cm = feet*12*2.54
return in_to_cm + ft_to_cm
assert f(0, 0) == 0
|
benchmark_functions_edited/f12182.py
|
def f(x_1: float, x_2: float, theta: float = 0.1) -> float:
# check what theta is really supposed to do; Is it only supposed to prevent Div by zero? --> Doesn't say in the text. It is simply a degree of freedom to fit data
return abs(x_1 - x_2) / (abs(x_1) + abs(x_2) + theta)
assert f(0, 0) == 0
|
benchmark_functions_edited/f316.py
|
def f(x, y):
return abs(x-y)
assert f(3, 3) == 0
|
benchmark_functions_edited/f1782.py
|
def f(a, b):
return -(-a // b)
assert f(5, 3) == 2
|
benchmark_functions_edited/f3025.py
|
def f(iterable):
res = 1
for i in iterable:
res *= i
return res
assert f(range(1,4)) == 6
|
benchmark_functions_edited/f3334.py
|
def f(pos1: tuple, pos2: tuple) -> int:
return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])
assert f( (1, 1), (1, -1) ) == 2
|
benchmark_functions_edited/f10117.py
|
def f(n_coeffs):
delta_sqrt = int((8 * n_coeffs + 1.)**.5 + 0.5)
if delta_sqrt**2 != (8*n_coeffs+1.):
raise ValueError('Wrong input in f(): {:}'.format(n_coeffs))
return int((delta_sqrt - 3.) / 2. + 0.5)
assert f(10) == 3
|
benchmark_functions_edited/f8020.py
|
def f(idx, text, beginning="<"):
akt_idx = idx
while text[akt_idx] != beginning:
akt_idx -= 1
return akt_idx
assert f(1, "<head") == 0
|
benchmark_functions_edited/f10221.py
|
def f(a, p, m):
if not p :
return 1
tmp = f(a, p//2, m) % m;
tmp = (tmp*tmp) % m
return tmp if p%2==0 else (tmp*a % m)
assert f(1, 0, 3) == 1
|
benchmark_functions_edited/f4550.py
|
def f(s: slice, l: int):
out = list(range(*s.indices(l)))
assert len(out) == 1
return out[0]
assert f(slice(1, 2, 3), 2) == 1
|
benchmark_functions_edited/f9090.py
|
def f(v, low, high):
return max(int(low), min(int(v), int(high)))
assert f(-1.5, 2, 3) == 2
|
benchmark_functions_edited/f8266.py
|
def f(axis, ndim):
if axis < 0:
axis += ndim
if axis < 0 or axis >= ndim:
raise ValueError("invalid axis %s" % axis)
return axis
assert f(-1, 2) == 1
|
benchmark_functions_edited/f464.py
|
def f(a, b, c):
return ((int(a) ** int(b)) % int(c))
assert f(3, 3, 4) == 3
|
benchmark_functions_edited/f8461.py
|
def f(iterator, custom_error, *args):
try:
return next(iterator, None)
except Exception as error:
custom_error(error, *args)
raise Exception(error)
assert f(iter([1, 2, 3]), None) == 1
|
benchmark_functions_edited/f6549.py
|
def f(args):
result = 1
for num in args:
result *= num
return result
assert f([1, 2, 3]) == 6
|
benchmark_functions_edited/f8460.py
|
def f(path):
# path = (state, (action, total_cost), state, ... )
if len(path) < 3:
return 0
else:
action, total_cost = path[-2]
return total_cost
assert f( (1, (None, 3), 1) ) == 3
|
benchmark_functions_edited/f518.py
|
def f(begin, end, size):
return (end - begin) % size
assert f(2, 3, 3) == 1
|
benchmark_functions_edited/f6734.py
|
def f(iterator, item):
# pylint: disable=unused-argument
# We are conforming to the interface defined by Iterator.
return item
assert f(2, 5) == 5
|
benchmark_functions_edited/f4106.py
|
def f(value):
try:
return int(value)
except (ValueError, TypeError):
return None
assert f(True) == 1
|
benchmark_functions_edited/f3281.py
|
def f(a, b): # preliminary
print('{:d}*{:d} = '.format(a, b))
return a*b
assert f(4, 1) == 4
|
benchmark_functions_edited/f13402.py
|
def f(n: bytes) -> int:
# this is written in a highly imperative style
# to make it easy to translate to MIPS
p = 0
i = 0
while True:
c = n[i]
if c == ord('1'):
p |= 1
elif c == ord('0'):
pass # |= 0
elif c == 0: # null byte
p >>= 1
break
else:
raise ValueError('invalid string representing binary')
p <<= 1
i += 1
return p
assert f(b'\x00') == 0
|
benchmark_functions_edited/f9429.py
|
def f(root):
if root is None:
return 0
return max(f(root.left), f(root.right)) + 1
assert f(None) == 0
|
benchmark_functions_edited/f9030.py
|
def f(ops):
count = 0
for op in ops:
if isinstance(op, str):
count += len(op)
elif isinstance(op, int) and op < 0:
count += op
return count
assert f("abc") == 3
|
benchmark_functions_edited/f10910.py
|
def f(x, a, b, c):
return a * x ** 2 + b * x + c
assert f(0, 0, 0, 0) == 0
|
benchmark_functions_edited/f11317.py
|
def f(x):
if x == 'none' or x == 'standby' or x == 'P':
return 0
if x == 'left' or x == 'D':
return 1
else:
return -1
assert f('P') == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.