file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f8925.py
|
def f(content, token_line, last_number):
token_line = token_line.strip()
found = None
try:
found = content.index(token_line, last_number+1)
except ValueError:
pass
return found
assert f(
["001: a", "002: b", "003: c"],
"003: c",
1
) == 2
|
benchmark_functions_edited/f12481.py
|
def f(it):
first = True
out = None
for v in it:
if first:
out = v
first = False
else:
if out != v:
raise ValueError("More than one value")
if first:
raise ValueError("Empty sequence")
return out
assert f(list(range(1))) == 0
|
benchmark_functions_edited/f6526.py
|
def f(p_temp, h_temp):
# pylint: disable=unused-argument
return h_temp
assert f(35.2, 0) == 0
|
benchmark_functions_edited/f11226.py
|
def f(dimension: int, size: int, stride: int) -> int:
assert size % stride == 0
overlapping = (size // stride) - 1 if stride != size else 0
return (dimension // stride) - overlapping
assert f(30, 5, 5) == 6
|
benchmark_functions_edited/f1309.py
|
def f(*args):
mul = 1.0
for arg in args:
mul *= arg
return mul
assert f(1, 3) == 3
|
benchmark_functions_edited/f13903.py
|
def f(x):
# Check x is positive
if x < 0:
print("Error: Negative value given")
return -1
else:
print("Calculating..")
# Initial guess for the square root
z = x / 2.0
# Continously improve guess
# Adapted from https://tour.golang.org/flowcontrol/8
while abs(x - (z*z)) > 0.0000001:
z = z - ((z*z) - x) / (2 * z)
return z
assert f(0) == 0
|
benchmark_functions_edited/f3855.py
|
def f(num_points: int) -> int:
return max((num_points // 1000), 1)
assert f(10) == 1
|
benchmark_functions_edited/f14406.py
|
def f(in_exp, f):
modified_in_exp = f(in_exp)
if modified_in_exp is not None:
return modified_in_exp
if type(in_exp) not in (tuple, list):
return in_exp
res = tuple()
for e in in_exp:
res += (f(e, f),)
if type(in_exp) == list:
res = list(res)
return res
assert f(0, lambda x: None) == 0
|
benchmark_functions_edited/f1773.py
|
def f(x: int, n: int) -> int:
return n * round(x / n)
assert f(8, 3) == 9
|
benchmark_functions_edited/f10462.py
|
def f(cents_per_kWh, wattage, dollar_amount):
return 1 / (cents_per_kWh) * 1e5 * dollar_amount / wattage
assert f(1, 1000, 0) == 0
|
benchmark_functions_edited/f3417.py
|
def f(xyz1, xyz2):
dx=xyz1[0]-xyz2[0]
dy=xyz1[1]-xyz2[1]
dz=xyz1[2]-xyz2[2]
return dx*dx+dy*dy+dz*dz
assert f( (1,2,3), (2,3,3) ) == 2
|
benchmark_functions_edited/f12441.py
|
def f(value, matrix):
for i, line in enumerate(matrix, 1):
if line == value:
return i
assert f(1, [0, 1, 1]) == 2
|
benchmark_functions_edited/f9464.py
|
def f(keys, pop_dict):
if isinstance(keys, list):
for key in keys:
f(key, pop_dict)
elif keys in pop_dict:
return pop_dict.pop(keys)
return None
assert f(1, {0: 1, 1: 2}) == 2
|
benchmark_functions_edited/f8766.py
|
def f(value, minimum, maximum):
return max(minimum, min(value, maximum))
assert f(0, -100, 100) == 0
|
benchmark_functions_edited/f4373.py
|
def f(value):
try:
return int(value)
except ValueError:
pass
return value
assert f("5") == 5
|
benchmark_functions_edited/f5485.py
|
def f(candidate):
try:
parent = candidate.parent
except AttributeError:
return candidate
else:
return f(parent)
assert f(0) == 0
|
benchmark_functions_edited/f13632.py
|
def f(query: str, score: float) -> float:
words = len(query.split())
expected_max_score = (words + 1) * .5
return min(score / expected_max_score, 1)
assert f(
"one two three",
0
) == 0
|
benchmark_functions_edited/f6349.py
|
def f(d, v=None):
if type(None) == type(v):
return d
return v
assert f(1) == 1
|
benchmark_functions_edited/f7088.py
|
def f(reference: str, target: str) -> int:
return sum([ref != "-" and tgt != "-" for ref, tgt in zip(reference, target)])
assert f("GTTA-GGG", "---ATGGC") == 4
|
benchmark_functions_edited/f12435.py
|
def f(movies):
ratings = [
m.score for m in movies
] # make a list of all the movie scores of the specific director
average = sum(ratings) / max(
1, len(ratings)
) # add the list and divide by the number of items in the list. the max is to avoid divide by zeros
return round(average, 1)
assert f([]) == 0
|
benchmark_functions_edited/f8224.py
|
def f(text, full_term, case_sensitive):
if not case_sensitive:
text = text.lower()
full_term = full_term.lower()
return 1 if text == full_term else 0
assert f(
'20200202_194559',
'20200202_194559',
True) == 1
|
benchmark_functions_edited/f4141.py
|
def f(r: float, g: float, b: float) -> int:
return int(r * 255) << 16 | int(g * 255) << 8 | int(b * 255)
assert f(0.0, 0.0, 0.0) == 0
|
benchmark_functions_edited/f5508.py
|
def f(bbox):
assert bbox[2] > bbox[0]
assert bbox[3] > bbox[1]
return int(bbox[2] - bbox[0]) * (bbox[3] - bbox[1])
assert f( [1, 2, 2, 3] ) == 1
|
benchmark_functions_edited/f13656.py
|
def f(element, level):
assert isinstance(element, list)
level_sum = 0
if len(element) == 0:
return 0
for x in element:
if not isinstance(x, list):
level_sum += x
else:
level_sum += f(x, level + 1)
return level_sum * level
assert f([], 0) == 0
|
benchmark_functions_edited/f4085.py
|
def f(n, m):
mod = 10**m
res = 1
for _ in range(n):
res = (res << 1) % mod
return res
assert f(3, 1) == 8
|
benchmark_functions_edited/f1745.py
|
def f(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
assert f(
(3, 4),
(0, 0)
) == 7
|
benchmark_functions_edited/f3612.py
|
def f(step: int, base_lr: float) -> float:
lr = base_lr
_lr = lr * 0.9 ** (step // 25)
return max(_lr, lr * 1e-3)
assert f(0, 1) == 1
|
benchmark_functions_edited/f6118.py
|
def f(x,y):
if (x >= 2):
return x%2
else:
return (x+y)%2
assert f(*[3,2]) == 1
|
benchmark_functions_edited/f10600.py
|
def f(d, key):
current = d
for subkey in key.split("."):
try:
current = current[subkey]
except KeyError:
return None
return current
assert f(
{
"a": 1,
"b": {
"c": 2,
"d": 3
}
},
"a"
) == 1
|
benchmark_functions_edited/f8405.py
|
def f(value_list):
from math import sqrt
from math import pow
n = len(value_list)
average_value = sum(value_list) * 1.0 / n
return sqrt(sum([pow(e - average_value,2) for e in value_list]) * 1.0 / (n - 1))
assert f([2, 2, 2]) == 0
|
benchmark_functions_edited/f1415.py
|
def f(location, grid):
return grid[location[0]][location[1]]
assert f( (0,1), [[0, 0], [0, 0]] ) == 0
|
benchmark_functions_edited/f3660.py
|
def f(state):
node = state
for key in ("layers", "mode"):
node = node.get(key, {})
return node.get("index", 0)
assert f({"layers": {}, "mode": {}}) == 0
|
benchmark_functions_edited/f10891.py
|
def f(iterable, minimum=0):
try:
result = max(map(len, iterable))
except ValueError:
return minimum
return max(result, minimum)
assert f(['spam', 'ham']) == 4
|
benchmark_functions_edited/f2978.py
|
def f(n, k):
return (2*n**2 - n)*k
assert f(0, 100) == 0
|
benchmark_functions_edited/f13126.py
|
def f(nd, nF, nC):
V = (nd - 1)/(nF - nC)
return V
assert f(2, 2, 1) == 1
|
benchmark_functions_edited/f1246.py
|
def f(a, b):
return max(0, min(a[1], b[1]) - max(a[0], b[0]))
assert f(
(1, 5),
(2, 4)
) == 2
|
benchmark_functions_edited/f7047.py
|
def f(L_HP_d, L_dashdash_d, L_dashdash_s_d):
return L_dashdash_s_d - L_HP_d * (L_dashdash_s_d / L_dashdash_d)
assert f(0, 1, 0) == 0
|
benchmark_functions_edited/f3193.py
|
def f(f,x,h):
h = float(h)
return (1/(2*h))*(f(x-2*h) - 4*f(x-h) + 3*f(x))
assert f(lambda x: 0*x + 1, 1, 1) == 0
|
benchmark_functions_edited/f8191.py
|
def f(n, i, j):
if i < j:
return n * i - (i * (i + 1) // 2) + (j - i - 1)
elif i > j:
return n * j - (j * (j + 1) // 2) + (i - j - 1)
assert f(5, 3, 2) == 7
|
benchmark_functions_edited/f10066.py
|
def f(n, a, c, b):
count = 0
if n >= 1:
first = f(n - 1, a, b, c)
c.append(a.pop())
count += 1
second = f(n - 1, b, c, a)
count += first + second
return count
assert f(0, ['a', 'b', 'c'], [], []) == 0
|
benchmark_functions_edited/f1366.py
|
def f(value, value_max=1, value_min=0):
return max(min(value, value_max), value_min)
assert f(3, 3, 2) == 3
|
benchmark_functions_edited/f662.py
|
def f(a, b):
return b if a == 0 else f(b % a, a)
assert f(12, 30) == 6
|
benchmark_functions_edited/f5428.py
|
def f(x):
if x == 0 or x == 1:
return 1
else:
return f(x-1) + f(x-2)
assert f(0) == 1
|
benchmark_functions_edited/f6997.py
|
def f(int_type):
length = 0
while int_type:
int_type >>= 1
length += 1
return length
assert f(15) == 4
|
benchmark_functions_edited/f3862.py
|
def f(u, l, alpha, x):
return (u-l) + 2/alpha * (l-x) * (x < l) + 2/alpha * (x-u)*(x > u)
assert f(1, 1, 0.2, 1) == 0
|
benchmark_functions_edited/f10448.py
|
def f(num_mask_bits,value):
return (((1<<(num_mask_bits))-1)<<(8-num_mask_bits)) & value
assert f(0,list(b'\\x00')[0]) == 0
|
benchmark_functions_edited/f3591.py
|
def f(x, y, M):
if (x,y) in M:
return M[(x,y)]
elif (y,x) in M:
return M[(y,x)]
else:
return 0
pass
assert f(0,0,{(0,0):1, (1,1):3, (2,2):4}) == 1
|
benchmark_functions_edited/f2275.py
|
def f(dlist, b=10):
y = 0
for d in dlist:
y = y * b + d
return y
assert f([1, 0], 1) == 1
|
benchmark_functions_edited/f3412.py
|
def f(metafeatures_spec):
return sum([len(m[2]) if m[1] is str else 1 for m in metafeatures_spec])
assert f(
[
('Numerical', 'A', [0, 1, 2, 3, 4]),
('Numerical', 'B', [0, 1, 2, 3, 4, 5]),
]
) == 2
|
benchmark_functions_edited/f5151.py
|
def f(value, nonchar=''):
if value is None:
return nonchar
return value
assert f(0,'') == 0
|
benchmark_functions_edited/f419.py
|
def f(data, item):
return data.__getitem__(item)
assert f(range(3), 2) == 2
|
benchmark_functions_edited/f12263.py
|
def f(ilist, start):
prev = ilist[start]
length = len(ilist)
ind = start
for ind in range(start+1, length+1):
if ind == length: break
if ilist[ind] != prev + 1:
break
prev = ilist[ind]
if ind == start: length = 1
else: length = ind-start
return length
assert f(range(3), 2) == 1
|
benchmark_functions_edited/f1817.py
|
def f(offset, align):
return (align - (offset % align)) % align
assert f(10, -1) == 0
|
benchmark_functions_edited/f5220.py
|
def f(a, b):
while b != 0:
a, b = b, a % b
return a
assert f(1, 1) == 1
|
benchmark_functions_edited/f8532.py
|
def f(a, b):
if a == b:
return a
elif a == 1:
return b
elif b == 1:
return a
else:
raise ValueError("failed to broadcast {0} and {1}".format(a, b))
assert f(1, 1) == 1
|
benchmark_functions_edited/f13895.py
|
def f(array):
swap = 0
for i, x in enumerate(array):
k = i
while k > 0 and array[k] < array[k-1]:
array[k], array[k-1] = array[k-1], array[k]
swap += 1
k -= 1
return swap
assert f(
[1, 2, 3, 4, 5]) == 0
|
benchmark_functions_edited/f7236.py
|
def f(e):
try:
return e.errno
except AttributeError:
return e.args[0]
assert f(IOError(2,'message')) == 2
|
benchmark_functions_edited/f744.py
|
def f(left: int, right: int):
print(left + right)
return 0
assert f(0, 0) == 0
|
benchmark_functions_edited/f11251.py
|
def f(checkpoint_dir):
checkpoint_name = checkpoint_dir.split('/')[-1]
return int(checkpoint_name.split('-')[-1])
assert f('a-b-2') == 2
|
benchmark_functions_edited/f9955.py
|
def f(redemptions, costs, traders):
surplus = 0
transactions = 0.5 * traders
for redemption, cost in zip(redemptions, costs):
if redemption >= cost:
surplus += ((redemption - cost) * transactions)
return surplus
assert f(
[1, 2, 3, 4],
[1, 2, 3, 4],
1
) == 0
|
benchmark_functions_edited/f11691.py
|
def f(aa1, aa2, match=1, penaltyA=-10000, penaltyX=0, gap_penalty=-1):
aa1 = aa1.upper()
aa2 = aa2.upper()
if not aa1.isalpha() or not aa2.isalpha():
return gap_penalty
if aa1 == aa2:
return 1
elif aa1=='X' or aa2=='X':
return penaltyX
else:
return penaltyA
assert f( 'C', 'C') == 1
|
benchmark_functions_edited/f8797.py
|
def f(dictionary, key):
values = []
for item in dictionary:
values.append(item[key])
return min(values)
assert f(
[{"a": 1, "b": 2, "c": 3}, {"a": 3, "b": 2, "c": 1}],
"b") == 2
|
benchmark_functions_edited/f11553.py
|
def f(x: float, y: float) -> float:
return abs(x - y)
assert f(1, 0) == 1
|
benchmark_functions_edited/f4128.py
|
def f(anchor_info):
anch_id = list(anchor_info.keys())
min_id_ind = anch_id.index(min(anch_id))
return min_id_ind
assert f({1: 1, 2: 3, 3: 2, 4: 0}) == 0
|
benchmark_functions_edited/f11266.py
|
def f(A, key):
for i in range(len(A)):
if A[i] == key:
return i
return -1
assert f(
[1, 2, 3, 4, 5, 6],
1) == 0
|
benchmark_functions_edited/f12364.py
|
def f(input_length, output_length, stride):
offset = (input_length) - (stride * ((input_length - output_length) // stride) + output_length)
return offset
assert f(224, 112, 4) == 0
|
benchmark_functions_edited/f12889.py
|
def f(a, b):
smallerNumber = a if a < b else b
biggestFactor = 1
temp = 0
while temp < smallerNumber:
temp += 1
if a % temp == 0 and b % temp == 0:
biggestFactor = temp
return biggestFactor
assert f(12, 30) == 6
|
benchmark_functions_edited/f5405.py
|
def f(func_arg1, call_arg1, func_mult, call_mult):
return (func_arg1 + call_arg1) * func_mult * call_mult
assert f(2, 3, 4, 0) == 0
|
benchmark_functions_edited/f8141.py
|
def f(dist, alpha, r):
res = 0.0
for n in dist:
for i in range(n):
res += 1.0/(i*r+alpha)
for i in range(sum(dist)):
res -= 1.0/(i+alpha)
return res
assert f( [1], 0.0001, 2.0) == 0
|
benchmark_functions_edited/f7247.py
|
def f(*nums: int) -> int:
result = sum(nums)
return result
assert f(1) == 1
|
benchmark_functions_edited/f4142.py
|
def f(actions):
total_profit = 0
for action in actions:
action_profit = action[2]
total_profit += action_profit
return total_profit
assert f([]) == 0
|
benchmark_functions_edited/f300.py
|
def f(x, g):
return int(x/g)
assert f(10, 100) == 0
|
benchmark_functions_edited/f385.py
|
def f(actions):
return len([x for x in actions if x.islower()])
assert f(list('AbCaDe')) == 3
|
benchmark_functions_edited/f9790.py
|
def f(a):
if (a[0] >= a[1]):
return 0
N = a.length()
if (a[N - 1] >= a[N - 2]):
return N - 1;
for i in range(1, N - 1):
if (a[i] >= a[i - 1] and a[i] >= a[i + 1]):
return i
return -1
assert f(list(range(10, 0, -1))) == 0
|
benchmark_functions_edited/f12771.py
|
def f(lst, predicate):
for i, e in enumerate(lst):
if predicate(e):
return i
return None
assert f(range(10), lambda x: x % 2 == 0) == 0
|
benchmark_functions_edited/f11260.py
|
def f(propertyValue):
if not propertyValue:
return 0
elif isinstance(propertyValue, list):
return propertyValue[0]
# then it's integer
return propertyValue
assert f([0]) == 0
|
benchmark_functions_edited/f2260.py
|
def f(board):
return sum(sum(len(cell) for cell in row) for row in board)
assert f([]) == 0
|
benchmark_functions_edited/f7409.py
|
def f(pos, lbox):
return (pos+lbox/2.) % lbox - lbox/2.
assert f(0, 2) == 0
|
benchmark_functions_edited/f2653.py
|
def f(r, n):
return (1 - r**(n + 1)) / (1 - r)
assert f(0.0, 0) == 1
|
benchmark_functions_edited/f9786.py
|
def f(f, seq):
if not seq:
return 0
elif isinstance(seq[0], list):
return f(f, seq[0])
elif len(seq) == 1:
return seq[0]
else:
return f(seq[0], f(f, seq[1:]))
assert f(lambda a, b: a+b, [[[[[[[0]]]]]]]) == 0
|
benchmark_functions_edited/f13874.py
|
def f(op, elements, accumulator):
for element in elements:
accumulator = op((accumulator, element))
return accumulator
assert f(lambda x, y: x + y, range(0), 5) == 5
|
benchmark_functions_edited/f3537.py
|
def f(n_1, n_2) -> int:
if n_1 == n_2:
return 1
else:
return 0
assert f(4, 3) == 0
|
benchmark_functions_edited/f7226.py
|
def f(tpa, tpb):
ca, cb = tpa[0], tpb[0]
num_diff_field = 0
for k in ca:
if ca[k] != cb[k]:
num_diff_field += 1
return num_diff_field
assert f(
(
{"a": 0, "b": 0, "c": 0},
{"a": 1, "b": 0, "c": 0},
{"a": 1, "b": 1, "c": 0},
),
(
{"a": 0, "b": 1, "c": 0},
{"a": 1, "b": 0, "c": 0},
{"a": 1, "b": 0, "c": 0},
)
) == 1
|
benchmark_functions_edited/f8017.py
|
def f(top, bottom, amount, fee=0):
ratio = top / (bottom + amount)
return int(amount * ratio * (1-fee))
assert f(1,1,10,1) == 0
|
benchmark_functions_edited/f7175.py
|
def f(seq1, seq2):
if len(seq1) != len(seq2):
raise ValueError("Unequal sequence lengths:", seq1, seq2)
return sum(1 for i, j in zip(seq1, seq2) if i != j)
assert f(str(1), str(1)) == 0
|
benchmark_functions_edited/f13533.py
|
def f(dct, key):
if '/' in key:
base, newkey = key.split('/', maxsplit=1)
return f(dct[base], newkey)
else:
try:
ret = dct[key]
except KeyError:
# int keys would have been converted to strings
ret = dct[int(key)]
return ret
assert f(
{'a': {'b': 1, 'c': 2}, 'b': 3},
'a/c'
) == 2
|
benchmark_functions_edited/f4246.py
|
def f(input):
return sum(1 if input[i] < input[i+1] else 0 for i in range(len(input)-1))
assert f(
[199, 200, 208, 210, 200, 207, 240, 269, 260, 263]) == 7
|
benchmark_functions_edited/f10491.py
|
def f(n, memo = {}):
if n == 0 or n == 1:
return 1
try:
return memo[n]
except KeyError:
result = f(n-1, memo) + f(n-2, memo)
memo[n] = result
return result
assert f(1) == 1
|
benchmark_functions_edited/f3814.py
|
def f(x, x0, x1):
x=int(x)
if x < x0: return x0
if x > x1: return x1
return x
assert f(1.9, 2, 3) == 2
|
benchmark_functions_edited/f11499.py
|
def f(lCells):
nbRows = max(int(x.get('row')) for x in lCells)
try:
return max(int(x.get('rowSpan')) for x in filter(lambda x: x.get('row') == "0" and x.get('rowSpan') != str(nbRows+1), lCells))
except ValueError :
return 1
assert f(
[{'row': '0', 'rowSpan': '1'}, {'row': '0', 'rowSpan': '1'}]
) == 1
|
benchmark_functions_edited/f6470.py
|
def f(bytearr):
unsigned=(bytearr[2]<<16)+(bytearr[3]<<8)+bytearr[4]
return unsigned-16777216 if bytearr[2]&128 else unsigned
assert f(bytearray([0,0,0,0,0])) == 0
|
benchmark_functions_edited/f9133.py
|
def f(s1, s2):
if len(s1) != len(s2): raise ValueError('strings of unequal length')
return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
assert f('foo', 'bar') == 3
|
benchmark_functions_edited/f13935.py
|
def f(probabilities, random_function) -> int:
assert type(probabilities) is list
random_value = random_function()
for index in range(len(probabilities)):
if random_value <= probabilities[index]:
return index
return len(probabilities)
assert f(
[0.5, 0.25, 0.125, 0.125],
lambda: 0.5,
) == 0
|
benchmark_functions_edited/f1033.py
|
def f(x, _min, _max):
return min(_max, max(_min, x))
assert f(10, 1, 9) == 9
|
benchmark_functions_edited/f4357.py
|
def f(D1, D2):
result = 0.
for key in D1:
if key in D2:
result += D1[key] * D2[key]
return result
assert f({1: 1, 2: 2}, {1: 1, 2: 2}) == 5
|
benchmark_functions_edited/f12033.py
|
def f(x,C0,C1,C2,C3,C4):
return C0+C1*x+C2*x**2+C3*x**3+C4*x**4
assert f(2,0,0,0,0,0) == 0
|
benchmark_functions_edited/f12132.py
|
def f(set_one: list, set_two: list) -> float:
intersection = len(set(set_one) & set(set_two))
union = len(set(set_one) | set(set_two))
return float(intersection) / float(union)
assert f(set(['a']), set(['a'])) == 1
|
benchmark_functions_edited/f14161.py
|
def f(priority):
priority_grade_map = {
'Low': 1,
'Medium': 2,
'High': 3,
'Critical': 4
}
grade = priority_grade_map.get(priority, 0)
return grade
assert f('Low') == 1
|
benchmark_functions_edited/f4525.py
|
def f(n,dic= {0:0,1:1}):
if n in dic.keys():
return dic[n]
else:
dic[n] = f(n-1) + f(n-2)
return dic[n]
assert f(5) == 5
|
benchmark_functions_edited/f1298.py
|
def f(number):
del number
return 1
assert f(17) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.