file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f7626.py
|
def f(n: int) -> int:
return 3 if n == 0 else (2 << ((2 << (n - 1)) - 1)) + 1
assert f(1) == 5
|
benchmark_functions_edited/f261.py
|
def f(val, low, high):
return low + (high - low) * val
assert f(0, 1, 2) == 1
|
benchmark_functions_edited/f13164.py
|
def f(t):
return t % (24 * 3600)
assert f(2) == 2
|
benchmark_functions_edited/f12790.py
|
def f(start, end):
# -
if start > end:
return -1
# +
elif start <= end:
return 1
return 0
assert f(0, 5) == 1
|
benchmark_functions_edited/f12150.py
|
def f(obj, dest_type: type):
if obj is None:
return None
if issubclass(dest_type, bool):
return dest_type(int(obj))
return dest_type(obj)
assert f(1.1, int) == 1
|
benchmark_functions_edited/f116.py
|
def f(x, a, b, c):
return a*(x-b)**2 + c
assert f(0, 1, 1, 1) == 2
|
benchmark_functions_edited/f7691.py
|
def f(lexdata, lexpos):
last_cr = lexdata.rfind('\n', 0, lexpos)
if last_cr < 0:
return lexpos + 1
else:
return lexpos - last_cr
assert f(u"abc\ndef\n", 3) == 4
|
benchmark_functions_edited/f12933.py
|
def f(rep_restart_wait=None, quorum_loss_wait=None,
standby_replica_keep=None):
flag_sum = 0
if rep_restart_wait is not None:
flag_sum += 1
if quorum_loss_wait is not None:
flag_sum += 2
if standby_replica_keep is not None:
flag_sum += 4
return flag_sum
assert f(None, None, None) == 0
|
benchmark_functions_edited/f3666.py
|
def f(subs):
try:
return next(subs)
except StopIteration:
return None
assert f(iter([1])) == 1
|
benchmark_functions_edited/f859.py
|
def f(v, w):
return sum([x * y for x, y in zip(v, w)])
assert f( [1, 1, 1], [1, 1, 1] ) == 3
|
benchmark_functions_edited/f9108.py
|
def f(month):
if month not in range(1, 13):
raise ValueError("invalid month")
d = {1: 1, 2: 1, 3: 1,
4: 2, 5: 2, 6: 2,
7: 3, 8: 3, 9: 3,
10: 4, 11: 4, 12: 4}
return d[month]
# return (month + 2) // 3
assert f(1) == 1
|
benchmark_functions_edited/f7963.py
|
def f(L, value):
val = next(iter(filter(lambda x: x[1] == value, enumerate(L))))
if val:
return(val[0])
else:
raise(ValueError("{} is not in the list.".format(value)))
assert f(
['C', 'A', 'A', 'B', 'B', 'C', 'C'],
'A'
) == 1
|
benchmark_functions_edited/f687.py
|
def f(value, grad):
eta = 0.1
return (value - eta*grad)
assert f(10, 100) == 0
|
benchmark_functions_edited/f429.py
|
def f(n):
return int(2*n**(1/3))
assert f(36) == 6
|
benchmark_functions_edited/f1670.py
|
def f(Di, WT):
return Di + 2 * WT
assert f(1, 1) == 3
|
benchmark_functions_edited/f8131.py
|
def f(val):
retval = val * 10
if retval < 0:
retval = 0
elif retval > 10:
retval = 10
else:
retval = int(round(retval))
return retval
assert f(-3) == 0
|
benchmark_functions_edited/f2490.py
|
def f(dd):
mm = 0.046
return dd * mm
assert f(0) == 0
|
benchmark_functions_edited/f9891.py
|
def f(dataset_iter):
try:
sample = next(dataset_iter)
except (StopIteration, RuntimeError) as e:
if "Can't copy Tensor with type" in str(e):
sample = None
elif isinstance(e, StopIteration):
sample = None
else:
raise e
return sample
assert f(iter([0])) == 0
|
benchmark_functions_edited/f2628.py
|
def f(A):
my_max = 0
for v in A:
if my_max < v:
my_max = v
return my_max
assert f([1, 2, 3]) == 3
|
benchmark_functions_edited/f3011.py
|
def f(dat):
tot = 0
for params, obj in dat:
tot += obj
return tot
assert f(list(zip([1, 0], [1, 2]))) == 3
|
benchmark_functions_edited/f2354.py
|
def f(seq, default=None):
if len(seq):
return min(seq)
return default
assert f(range(1, 5)) == 1
|
benchmark_functions_edited/f2138.py
|
def f(current, value):
if current is None:
return value
return current
assert f(None, 5) == 5
|
benchmark_functions_edited/f4959.py
|
def f(a,b):
diffs = 0
z = zip(a,b)
for x, y in z:
if x != y:
diffs += 1
return diffs
assert f(list('xyz'), list('abc')) == 3
|
benchmark_functions_edited/f13831.py
|
def f(lst, begin, end):
if begin > end or begin > len(lst) - 1 or end > len(lst) - 1:
raise IndexError
if begin < end:
return lst.index(begin) + f(lst, begin + 1, end)
return 0
assert f(list('abcdef'), 0, 0) == 0
|
benchmark_functions_edited/f10772.py
|
def f(k_means_matrix):
return sum([min(dist) for dist in k_means_matrix])
assert f([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 3
|
benchmark_functions_edited/f3486.py
|
def f(p,l):
pos = l.index(p)
if pos-1 < 0:
return l[-1]
else:
return l[pos-1]
assert f(2, [1,2,3]) == 1
|
benchmark_functions_edited/f5175.py
|
def f(value, minval, maxval):
if value < minval:
return minval
if value > maxval:
return maxval
return value
assert f(-3, 0, 10) == 0
|
benchmark_functions_edited/f10197.py
|
def f(arr):
return sorted(arr)[(len(arr)-1)//2]
assert f([1, 2, 3]) == 2
|
benchmark_functions_edited/f727.py
|
def f(a: int, b: int) -> int:
return ((a + b - 1) // b) * b
assert f(5, 2) == 6
|
benchmark_functions_edited/f1432.py
|
def f(l, w, h):
return (2 * l * w) + (2 * w * h) + (2 * h * l)
assert f(1, 1, 1) == 6
|
benchmark_functions_edited/f3522.py
|
def f(a, b) :
#print('HCF : ', a, b)
if b == 0 :
return a
return f(b, a%b)
assert f(11, 12) == 1
|
benchmark_functions_edited/f11225.py
|
def f(num, mult):
if mult == 0:
return 0
else:
offset = mult - (num % mult)
if offset == mult:
offset = 0
return offset
assert f(0, 3) == 0
|
benchmark_functions_edited/f12377.py
|
def f(lst):
res, i = 1, sum(lst)
i0 = lst.index(max(lst))
for a in lst[:i0] + lst[i0 + 1 :]:
for j in range(1, a + 1):
res *= i
res //= j
i -= 1
return res
assert f([0, 0, 0, 0, 0, 1, 0, 0, 0, 0]) == 1
|
benchmark_functions_edited/f13672.py
|
def f(lhs: int, rhs: int) -> int:
if lhs == 0:
raise ValueError()
return lhs + rhs
assert f(2, 2) == 4
|
benchmark_functions_edited/f113.py
|
def f(x):
return 1.0-x**2
assert f(1) == 0
|
benchmark_functions_edited/f13063.py
|
def f(n):
no_of_steps = 1
print(n)
while n != 1:
if n % 2 == 0:
n = n / 2
print(n)
elif n % 2 == 1:
n = n * 3 + 1
print(n)
no_of_steps += 1
return no_of_steps
assert f(4) == 3
|
benchmark_functions_edited/f13327.py
|
def f(v0w, b0w, b1w, v0f, b0f, b1f, config_string, prefact, weight_b0, weight_b1):
return prefact*2*(b0w-b0f)/(b0w+b0f)
assert f(4, 1, 4, 3, 1, 3, "", 1, 1, 1) == 0
|
benchmark_functions_edited/f4666.py
|
def f(group):
if group["fire_mode"] == "auto":
shots = 3
else:
shots = 1
return shots
assert f(
{
"fire_mode": "single",
}
) == 1
|
benchmark_functions_edited/f14053.py
|
def f(n):
n &= 0x0000FFFF
n = (n | (n << 8)) & 0x00FF00FF
n = (n | (n << 4)) & 0x0F0F0F0F
n = (n | (n << 2)) & 0x33333333
n = (n | (n << 1)) & 0x55555555
return n
assert f(0) == 0
|
benchmark_functions_edited/f3585.py
|
def f(data):
n = len(data)
if n < 1:
raise ValueError('mean requires at least one data point')
return sum(data)/n
assert f([1, 3]) == 2
|
benchmark_functions_edited/f13244.py
|
def f(what):
if what in ["TRUE", "True", "Yes", "OK"]:
return True
if what in ["FALSE", "False", "None"]:
return False
if what == "Unknown":
return None
try:
return int(what)
except ValueError:
pass
try:
return float(what)
except ValueError:
pass
return what
assert f("1") == 1
|
benchmark_functions_edited/f14343.py
|
def f(y, x, dx, f):
k1 = dx * f(y, x)
k2 = dx * f(y + 0.5 * k1, x + 0.5 * dx)
k3 = dx * f(y + 0.5 * k2, x + 0.5 * dx)
k4 = dx * f(y + k3, x + dx)
return y + (k1 + 2 * k2 + 2 * k3 + k4) / 6.
assert f(0, 0, 1, lambda y, x: 4) == 4
|
benchmark_functions_edited/f6339.py
|
def f(n):
# Base case.
if n <= 1:
return n
return n + f(n - 1)
assert f(1) == 1
|
benchmark_functions_edited/f12873.py
|
def f(comment, word):
comment = comment.replace('?', ' ')
comment = comment.replace('.', ' ')
comment = comment.replace('-', ' ')
comment = comment.replace('/', ' ')
a = comment.split(" ")
count = 0
for i in range(len(a)):
if (word == a[i]):
count = count + 1
return count
assert f("-", "comment") == 0
|
benchmark_functions_edited/f11051.py
|
def f(digits, base=10):
# first get an iterator to digits
if not hasattr(digits, 'next'):
# digits is an iterator
digits = iter(digits)
# now loop through digits, updating num
num = next(digits)
for d in digits:
num *= base
num += d
return num
assert f(iter([0, 1]), 2) == 1
|
benchmark_functions_edited/f1503.py
|
def f(x, p):
p_index = int(p * len(x))
return sorted(x)[p_index]
assert f(list(range(10)), 0.25) == 2
|
benchmark_functions_edited/f14476.py
|
def f(s1, s2):
import os
l_pref = len(os.path.commonprefix([s1, s2]))
l_suf = len(os.path.commonprefix([s1[::-1], s2[::-1]]))
res = 1 if (l_pref>0) and (l_suf > 0) and (l_pref+l_suf >= min(len(s1), len(s2))) else 0
# if res == 1:
# print(s1, s2, res)
return res
assert f( "Avenue C Berten", "Avenue Clovis Berta" ) == 0
|
benchmark_functions_edited/f2052.py
|
def f(s):
return min(len(x) for x in s.split())
assert f("i want to travel the world writing code one day") == 1
|
benchmark_functions_edited/f4887.py
|
def f(g_cur, char):
if char == '0':
g_cur += 1
else:
g_cur = 0
return g_cur
assert f(0, '1') == 0
|
benchmark_functions_edited/f2199.py
|
def f(n):
a, b = 0, 1
for i in range(n):
a, b = b, a + b
return a
assert f(4) == 3
|
benchmark_functions_edited/f8024.py
|
def f(f, a, b, m):
h = 1.0*(b-a)/m
sum = 0
for i in range(1,m+1):
x = a + i*h
if i==0 or i==m:
sum += 0.5*f(x)
else:
sum += f(x)
return h*sum
assert f(lambda x: x, 0, 0, 10) == 0
|
benchmark_functions_edited/f2883.py
|
def f(x):
return 2 * (x >= 0) - 1
assert f(0.5) == 1
|
benchmark_functions_edited/f11136.py
|
def f(x,t):
if x<t:
return 0
else:
return 1
assert f(0.9, 0.05) == 1
|
benchmark_functions_edited/f3932.py
|
def f(i):
if i >= 255:
return 255
elif i < 0:
return 0
else:
return i
assert f(0) == 0
|
benchmark_functions_edited/f2277.py
|
def f(n, k):
return 2*n**2*k
assert f(0, 100000) == 0
|
benchmark_functions_edited/f13783.py
|
def f(x, d, div, upperbound, lowerbound=-float('inf'), precision=1e-6):
low = max(x, lowerbound)
up = upperbound
while up-low > precision:
m = (low+up)/2
if div(x, m) > d:
up = m
else:
low = m
return (low+up)/2
assert f(1, 1, lambda a, b: 0, 1) == 1
|
benchmark_functions_edited/f4516.py
|
def f(x, y):
if x > y:
return x - y
else:
return y - x
assert f(2, 1.0) == 1
|
benchmark_functions_edited/f1779.py
|
def f(cmd_line):
import subprocess
return subprocess.call(cmd_line, shell=True)
assert f(
"echo Hello World"
) == 0
|
benchmark_functions_edited/f10925.py
|
def f(graph, source_node, dest_node):
if dest_node == source_node or dest_node - source_node == 1:
return 1
else:
routes = 0
for child in graph[source_node]:
routes += f(graph, child, dest_node)
return routes
assert f(
{1: [2, 3, 4], 2: [5, 6], 3: [7], 4: [], 5: [], 6: [], 7: []},
1,
7
) == 2
|
benchmark_functions_edited/f9608.py
|
def f(x, y):
return (x > y) - (x < y)
assert f(4, 4) == 0
|
benchmark_functions_edited/f9682.py
|
def f(trace_json):
return len(trace_json.get('children'))
assert f(
{
'children': [
{
'name': 'child_1',
'ts': 1000000,
'dur': 1000000,
'tts': 1000000
},
{
'name': 'child_2',
'ts': 100000,
'dur': 1000000,
'tts': 1000000
},
{
'name': 'child_3',
'ts': 100000,
'dur': 1000000,
'tts': 1000000
}
],
'name': 'root_1',
'ph': 'X',
'pid': '1',
'tid': '1',
'ts': 1000000,
'dur': 1000000,
'tts': 1000000,
'tdur': 1000000
}
) == 3
|
benchmark_functions_edited/f7086.py
|
def f(v, width):
mask = 1 << (width - 1)
return -(v & mask) + (v & ~mask)
assert f(0, 1) == 0
|
benchmark_functions_edited/f541.py
|
def f(x, to2):
to = to2/2
return (x + to)%to2 - to
assert f(1442, 360) == 2
|
benchmark_functions_edited/f2103.py
|
def f(bank):
weight = 0
for par in bank:
if par:
weight += par.weight
return weight
assert f([]) == 0
|
benchmark_functions_edited/f7336.py
|
def f(data, length_size):
result = 0
for i in range(length_size):
v = data[i]
if type(v) == str:
v = ord(v)
result |= v << ((length_size - 1) - i) * 8
return result
assert f(b"\x01", 1) == 1
|
benchmark_functions_edited/f12760.py
|
def f(keyspace, trials):
return trials - keyspace + keyspace * ((keyspace - 1) / keyspace) ** trials
assert f(1, 1) == 0
|
benchmark_functions_edited/f8176.py
|
def f(dict):
if len(dict) > 0:
v=list(dict.values())
k=list(dict.keys())
return k[v.index(max(v))]
else:
return "Check"
assert f(dict({1: 1, 2: 1, 3: 1})) == 1
|
benchmark_functions_edited/f8093.py
|
def f(predicate, iterable):
return next(filter(predicate, iterable), None)
assert f(lambda x: x == 3, [1, 2, 3]) == 3
|
benchmark_functions_edited/f12591.py
|
def f(delt_log=144, delt_matrix=55.5, delt_fluid=189):
return (delt_log-delt_matrix)/(delt_fluid-delt_matrix)
assert f(10, 50, 10) == 1
|
benchmark_functions_edited/f80.py
|
def f(var1, var2):
f = var1 / var2
return f
assert f(1, 1) == 1
|
benchmark_functions_edited/f10127.py
|
def f(sv, t):
rank = 0
for k in range(len(sv)):
if sv[k] > t:
rank = rank + 1
else: # sv is ordered big->small so break on condition not met
break
return rank
assert f([1, 0.5, 1, 1, 0.1, 0.2, 0.3], 0.0001) == 7
|
benchmark_functions_edited/f9372.py
|
def f(slot_map):
return sum([len(v) for v in slot_map.values()])
assert f(
{'A': ['a', 'b'], 'B': ['c', 'd', 'e']}
) == 5
|
benchmark_functions_edited/f10406.py
|
def f(line, tabsize=8):
tab_cnt = line.count('\t')
if not tab_cnt:
return len(line)
count = 0
for char in line:
if char == '\t':
count += tabsize - count % tabsize
else:
count += 1
return count
assert f(
" a"
) == 5
|
benchmark_functions_edited/f7486.py
|
def f(lst):
for x in lst:
if (x != 0):
return x
assert f( [ 1, 2, 3 ] ) == 1
|
benchmark_functions_edited/f7973.py
|
def f(xpos, ypos, grid_serial):
rack_id = xpos + 10
start_level = rack_id * ypos
power = start_level + grid_serial
power *= rack_id
return int((power % 1000) / 100) - 5
assert f(101, 153, 71) == 4
|
benchmark_functions_edited/f5088.py
|
def f(x, baseline, amplitude, tconstant, hillcoef):
return baseline+amplitude*(x**hillcoef)/(x**hillcoef+tconstant**hillcoef)
assert f(0, 1, 1, 1, 2) == 1
|
benchmark_functions_edited/f11417.py
|
def f(corr_id):
# Select the final 4 digits of the string
reduced_string = corr_id[-4:]
reduced_int = int(reduced_string, 16)
return reduced_int
assert f("1") == 1
|
benchmark_functions_edited/f6316.py
|
def f(tem, h):
max = h
if tem > max:
return tem
return h
assert f(7, 4) == 7
|
benchmark_functions_edited/f8013.py
|
def f(distances, wanted_distance):
return sum(
True
for row in distances
for col in row
if col > 0 and col >= wanted_distance
)
assert f(
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]],
0
) == 0
|
benchmark_functions_edited/f7408.py
|
def f(mode_val):
if isinstance(mode_val, str):
return int(mode_val, 16)
if isinstance(mode_val, int):
return mode_val
return None
assert f('1') == 1
|
benchmark_functions_edited/f13285.py
|
def f(a, b):
if b < 0:
f = lambda x,y:x-y
else:
f = lambda x,y:x+y
return f(a, b)
assert f(2, 3) == 5
|
benchmark_functions_edited/f1393.py
|
def f(lst):
p = 1.0
for i in lst:
p *= i
return p
assert f([1,2,3]) == 6
|
benchmark_functions_edited/f10820.py
|
def f(num):
if num == 0:
return 1
factorial = 1
for i in range(1, num + 1):
factorial = factorial * i
return factorial
assert f(0) == 1
|
benchmark_functions_edited/f5498.py
|
def f(row, name, mapping={}):
if name in mapping:
return row[mapping[name]]
else:
return row[name]
assert f(
{ 'foo': 1, 'bar': 2 },
'bar'
) == 2
|
benchmark_functions_edited/f11896.py
|
def f(value, target_format, min_value=None, max_value=None):
if min_value is not None:
value = max(value, min_value)
if max_value is not None:
value = min(value, max_value)
return target_format(value)
assert f(2.25, int) == 2
|
benchmark_functions_edited/f5497.py
|
def f(s, tabsize=4):
sx = s.expandtabs(tabsize)
# if line is empty yields 0
return 0 if sx.isspace() else len(sx) - len(sx.lstrip())
assert f(u"a\n ") == 0
|
benchmark_functions_edited/f12391.py
|
def f(n):
total = 0
for k in range(n):
total = total + ((k+1) ** 2)
return total
assert f(2) == 5
|
benchmark_functions_edited/f3002.py
|
def f(n:int, d:int)->int:
return (n + d - 1) // d
assert f(15, 7) == 3
|
benchmark_functions_edited/f3894.py
|
def f(DIM_FRACTAL, DiamInitial, NumCol):
return DiamInitial * 2**(NumCol / DIM_FRACTAL)
assert f(2, 4, 2) == 8
|
benchmark_functions_edited/f1288.py
|
def f(a, b) -> float:
return (float(a[0]) * b[0]) + (float(a[1]) * b[1])
assert f( (-4,0), (0,4) ) == 0
|
benchmark_functions_edited/f633.py
|
def f(a: int = 0, b: int = 0, c=0):
return (a * b) + c
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f13938.py
|
def f(value, from_min, from_max, to_min=0, to_max=8):
from_range = from_max - from_min
to_range = to_max - to_min
return (((value - from_min) / from_range) * to_range) + to_min
assert f(5, 0, 10, 1, 1) == 1
|
benchmark_functions_edited/f8857.py
|
def f(mu, A, d):
return mu*A*d;
assert f(2, 2, 2) == 8
|
benchmark_functions_edited/f11809.py
|
def f(num_elements: int, min_chunk_size: int) -> int:
if min_chunk_size >= num_elements:
return min_chunk_size
leftover_elements = num_elements % min_chunk_size
num_chunks = num_elements // min_chunk_size
return min_chunk_size + (leftover_elements - 1) // num_chunks + 1
assert f(100, 5) == 5
|
benchmark_functions_edited/f2656.py
|
def f(value, arg):
if value or arg:
return int(value or 0) - int(arg or 0)
return ''
assert f(1, 0) == 1
|
benchmark_functions_edited/f11646.py
|
def f(shape):
if len(shape) == 4:
n = shape[0] * shape[1] * shape[3]
return (2.0 / n)**.5
elif len(shape) == 2:
return (2.0 / shape[1])**.5
else:
assert False, "Only works on normal layers"
assert f((2,2)) == 1
|
benchmark_functions_edited/f7867.py
|
def f(band_data, bit_location):
return band_data & (1 << bit_location)
assert f(5, 1) == 0
|
benchmark_functions_edited/f8798.py
|
def f(ref_l, cand_l):
least_diff = abs(cand_l - ref_l[0])
best = ref_l[0]
for ref in ref_l:
if abs(cand_l - ref) < least_diff:
least_diff = abs(cand_l - ref)
best = ref
return best
assert f([3, 4, 5], 5) == 5
|
benchmark_functions_edited/f6077.py
|
def f(s):
try:
n = float(s)
except ValueError:
n = 0
return n
assert f('') == 0
|
benchmark_functions_edited/f1114.py
|
def f(lst):
p = 1
for l in lst:
p *= l
return p
assert f([1]) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.