file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f10004.py | def f(diff):
index = -1
minimum = 999999999
for i in range(len(diff)):
if (not diff[i][1] and
minimum > diff[i][0]):
minimum = diff[i][0]
index = i
return index
assert f(
[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (0, 0), (0, 0), (0, 0)]) == 5 |
benchmark_functions_edited/f4018.py | def f(number: float, divisions: int, base: int = 1024) -> float:
return number / base**divisions
assert f(2**23, 2) == 8 |
benchmark_functions_edited/f4798.py | def f(maxhrs, points2sec=126/(5**3 * 6)):
return maxhrs * 3600 * points2sec**-1
assert f(0) == 0 |
benchmark_functions_edited/f9230.py | def f(L):
return L * 2 + 1
assert f(2.0) == 5 |
benchmark_functions_edited/f4003.py | def f(a, b, c):
maximum = a
if b > maximum:
maximum = b
if c > maximum:
maximum = c
return maximum
assert f(3, 1, 0) == 3 |
benchmark_functions_edited/f6276.py | def f(term, string):
if term.lower() in string.lower():
if term.lower() == string.lower():
return 2
else:
return 1
else:
return 0
assert f(
'javascript',
'Python is a scripting language.') == 0 |
benchmark_functions_edited/f8657.py | def f(nums):
count = 0
for num in nums:
if num % 2 == 0:
count += 1
return count
assert f([2, 4]) == 2 |
benchmark_functions_edited/f13764.py | def f(level):
if not isinstance(level, int):
raise TypeError('Expect an int level, found {}'.format(type(level)))
if level >= 0:
# C++ log levels must be >= 0
return 0
else:
return -level
assert f(8) == 0 |
benchmark_functions_edited/f7252.py | def f(value):
return 2 ** (2 - value)
assert f(1) == 2 |
benchmark_functions_edited/f9032.py | def f(a: tuple, b: tuple):
ax, ay, bx, by = a[0], a[1], b[0], b[1]
dx = abs(ax - bx)
dy = abs(ay - by)
return dx + dy
assert f( (0, 0), (0, 0) ) == 0 |
benchmark_functions_edited/f5912.py | def f(number):
return len(str(number))
assert f(12) == 2 |
benchmark_functions_edited/f4888.py | def f(tree):
if type(tree) == str:
return 1
else:
score = 0
for child in tree:
score += f(child)
return score
assert f('Hi') == 1 |
benchmark_functions_edited/f14.py | def f(t,x,p,q):
return p[1] + q[0]*x
assert f(1,1,[1,2],[1,2]) == 3 |
benchmark_functions_edited/f12134.py | def f(dataset, colors):
colorsDict = colors
try:
colorVal = colorsDict[dataset][4:-1].split(',')[1]
return int(colorVal)
except KeyError:
return 0
assert f(1, {1: 'rgb(0,0,0)'}) == 0 |
benchmark_functions_edited/f8357.py | def f(ep,ed):
k = ep
return k*(ed[1]-ed[0]);
assert f(1,[0,1]) == 1 |
benchmark_functions_edited/f12941.py | def f(n, m):
if n < 0:
n = n * -1
if m == 0:
return 0
count = 0
while n != 0:
digit = n % 10
remainder = digit % m
if remainder == 0:
count += 1
n = n // 10
return count
assert f(10, 1) == 2 |
benchmark_functions_edited/f4228.py | def f(rgb1, rgb2):
r1, g1, b1 = rgb1
r2, g2, b2 = rgb2
return abs(r2-r1) + abs(g2-g1) + abs(b2-b1)
assert f( (255, 255, 255), (254, 254, 254) ) == 3 |
benchmark_functions_edited/f6379.py | def f(n, sigma):
return int(round(n / sigma))
assert f(6, 10) == 1 |
benchmark_functions_edited/f1072.py | def f(list):
return len(list) + 1
assert f(list([1, 2, 3])) == 4 |
benchmark_functions_edited/f10144.py | def f(i, d):
return 2 * i + d
assert f(0, 0) == 0 |
benchmark_functions_edited/f3101.py | def f(r):
return (4 * 3.14159 / 3)*r**3
assert f(0) == 0 |
benchmark_functions_edited/f1725.py | def sign (x):
return 0 if x == 0 else (1 if x > 0 else -1)
assert f(2.3) == 1 |
benchmark_functions_edited/f7917.py | def f(n, r):
if r > n//2 + 1:
r = n - r
numerator = 1
denominator = 1
for i in range(n, n - r, -1):
numerator *= i
denominator *= (n - i + 1)
return(numerator//denominator)
assert f(5, 1) == 5 |
benchmark_functions_edited/f13643.py | def f(m_name, members):
count = 0
for d in members:
if d["name"] == m_name:
return count
count += 1
return -1
assert f("asdf", [{"name": "asdf"}]) == 0 |
benchmark_functions_edited/f9002.py | def f(cell):
lines = cell.splitlines(keepends=True)
if not lines:
return 0
for i, line in enumerate(lines):
if line and not line.isspace():
return i
return len(lines)
assert f(r'Hello world!') == 0 |
benchmark_functions_edited/f7588.py | def f(value):
negative = (value & 1) == 1
value >>= 1
return -value if negative else value
assert f(0) == 0 |
benchmark_functions_edited/f1214.py | def f(f):
if not f:
return 0
else:
return f[-1]
assert f(tuple()) == 0 |
benchmark_functions_edited/f4853.py | def f(num: int) -> int:
return num.bit_length() - 1
assert f(3) == 1 |
benchmark_functions_edited/f11269.py | def f(gltf, idname):
if gltf.get('cameras') is None:
return -1
index = 0
for camera in gltf['cameras']:
key = 'id' if camera.get('id') != None else 'name'
if camera.get(key) == idname:
return index
index += 1
return -1
assert f(
{'cameras': [{'name': '... |
benchmark_functions_edited/f10969.py | def f(steps_in_current_epoch, steps_per_epoch, steps_per_loop):
if steps_per_loop <= 0:
raise ValueError('steps_per_loop should be positive integer.')
if steps_per_loop == 1:
return steps_per_loop
return min(steps_per_loop, steps_per_epoch - steps_in_current_epoch)
assert f(10, 10, 3) == 0 |
benchmark_functions_edited/f3610.py | def f(i):
count = 0
while i:
i &= i - 1
count += 1
return count
assert f(26) == 3 |
benchmark_functions_edited/f5160.py | def f(x, y):
x, y = max(x, y), min(x, y)
while y:
x, y = y, x%y
return x
assert f(12, 8) == 4 |
benchmark_functions_edited/f5634.py | def f(filename="", text=""):
with open(filename, "w", encoding="utf-8") as f:
return f.write(text)
assert f("test.txt", "test") == 4 |
benchmark_functions_edited/f12695.py | def f(n, max_n):
# Base Case
if n == 0: # return largest digit
return max_n
# Recursive Case
else:
remainder = n % 10 # pick digit
if remainder > max_n:
return f(n//10, remainder) # replace largest digit then recurs
else:
return f(n//10, max_n)
assert f(3333333, 0) == 3 |
benchmark_functions_edited/f7801.py | def f(inthing):
try:
outhing = int(inthing)
except:
outhing = None
return outhing
assert f(0) == 0 |
benchmark_functions_edited/f204.py | def f(n):
return 1 if n < 2 else n * f(n - 1)
assert f(1) == 1 |
benchmark_functions_edited/f906.py | def f(m, x, b):
return (m*x) + b
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f14464.py | def f(instance, **kwargs):
if instance is None:
return instance
for name, value in kwargs.items():
if hasattr(instance, name):
delattr(instance, name)
setattr(instance, name, value)
return instance
assert f(1) == 1 |
benchmark_functions_edited/f114.py | def f(x):
return x*(x*x+x)+x
assert f(0) == 0 |
benchmark_functions_edited/f4774.py | def f(px, py, qx, qy, rx, ry):
return (qx - px) * (ry - py) - (qy - py) * (rx - px)
assert f(1, 2, 3, 4, 2, 3) == 0 |
benchmark_functions_edited/f4394.py | def f(buf):
integer = 0
shift = 0
for byte in buf:
integer |= ord(byte) << shift
shift += 8
return integer
assert f(chr(0x01) + chr(0x00)) == 1 |
benchmark_functions_edited/f5194.py | def f(low, high, max):
if (low < 0 or low > high):
return 0
if (high < 0 or high > max):
return 0
return 1
assert f(10, -10, 20) == 0 |
benchmark_functions_edited/f13100.py | def f(index, lines):
if index < lines:
return 1
elif index == lines:
return 2
elif index >= (lines - 1) * lines:
return lines
else:
for line in range(2, lines):
if index >= (line - 1) * lines and index < line * lines:
return line
return -1
... |
benchmark_functions_edited/f1478.py | def f(x1, y1, x2, y2):
num = y2 - y1
den = x2 - x1
return float(num) / float(den)
assert f(10, 3, 11, 5) == 2 |
benchmark_functions_edited/f1659.py | def f(f, seq):
for item in seq:
if f(item):
return item
assert f(lambda x: x % 7 == 4, range(100)) == 4 |
benchmark_functions_edited/f1010.py | def f(p: bool, q: bool) -> bool:
return bool(p and q)
assert f(True, False) == 0 |
benchmark_functions_edited/f4996.py | def f(bit_array):
num = 0
for i, bit in enumerate(bit_array):
num += int(bit) << (len(bit_array) - i - 1)
return num
assert f(list("000000")) == 0 |
benchmark_functions_edited/f13636.py | def f(line_segment):
if '.' in line_segment:
return line_segment.rindex('.') + 1
elif ' ' in line_segment:
return line_segment.rindex(' ') + 1
else:
return -1
assert f(
"where x.pers") == 8 |
benchmark_functions_edited/f6768.py | def f(v1, v0, t1, t0):
if t1 > t0:
return (v1 - v0) / (t1 - t0)
else:
return 0
assert f(2, 2, 1, 1) == 0 |
benchmark_functions_edited/f3960.py | def f(probs_ratio, advantages):
unclipped_objective = probs_ratio * advantages
return unclipped_objective
assert f(2, 3) == 6 |
benchmark_functions_edited/f7537.py | def f(fp_size, kernel_size, padding, stride):
return (fp_size - kernel_size + 2 * padding) / stride + 1
assert f(5, 3, 0, 2) == 2 |
benchmark_functions_edited/f3444.py | def f(fm, fmp):
return (fm - fmp) / fmp
assert f(1000, 1000) == 0 |
benchmark_functions_edited/f868.py | def f(n):
return 1 / n ** 2
assert f(1) == 1 |
benchmark_functions_edited/f4716.py | def f(x):
try:
y=int(x)
except ValueError:
y=0
return y
assert f(' ')==0 |
benchmark_functions_edited/f6122.py | def f(n):
if n in [0, 1]:
return n
return f(n - 1) + f(n - 2)
assert f(2) == 1 |
benchmark_functions_edited/f10052.py | def f(p1, p2, p3):
det = float(p1[0]) * float(p2[1]) + float(p2[0]) * float(p3[1]) + float(p3[0]) * float(p1[1])
det -= float(p1[0]) * float(p3[1]) + float(p2[0]) * float(p1[1]) + float(p3[0]) * float(p2[1])
return det
assert f(
[0, 0],
[0, 0],
[0, 0]) == 0 |
benchmark_functions_edited/f7140.py | def f(x, singular=False, order=0):
if singular:
return 1 if x>0 else 0
return x**order if x>0 else 0
assert f(1, False, 2) == 1 |
benchmark_functions_edited/f5285.py | def f(peptide, motif):
for i in range(len(motif)):
if peptide[i]!=motif[i] and motif[i]!='x':
return 0
return 1
assert f(
'ATGGCGGTAG', 'xGGCG') == 0 |
benchmark_functions_edited/f10985.py | def f(node):
if not isinstance(node, dict):
return 1
else:
s = 0
for _, v in node.items():
s += f(v)
return s
assert f({'a': {'b': {'c': {'d': {'e': {'f': 1, 'g': 2, 'h': 3}}}}}}) == 3 |
benchmark_functions_edited/f8264.py | def f(results):
score1 = results[0]['score']
score2 = results[1]['score']
return (1 - score2 / score1)
assert f(
[{'score': 100000}, {'score': 100000}]
) == 0 |
benchmark_functions_edited/f4929.py | def f(predicate, iterable):
return next((item for item in iterable if predicate(item)), None)
assert f(lambda x: x == 1, [1, 2]) == 1 |
benchmark_functions_edited/f4173.py | def f(initial_velocity, t):
return (t + 1) * (2 * initial_velocity - t) / 2
assert f(1, 1) == 1 |
benchmark_functions_edited/f13143.py | def f(msg, q):
try:
q.send(msg)
return 1 # success
except Exception as ex:
print('[SERVER] Error:', ex)
return 0
assert f('123', '1') == 0 |
benchmark_functions_edited/f9671.py | def f(x, bias=0) -> int:
indicator = 1 if x >= bias else 0
return indicator
assert f(1) == 1 |
benchmark_functions_edited/f2574.py | def f(t):
return t*t*t*(t*(t*6 - 15) + 10)
assert f(0) == 0 |
benchmark_functions_edited/f7394.py | def f(interp):
if isinstance(interp, int):
return interp
order_map = {None: 0, "nearest": 0, "linear": 1, "quadratic": 2, "cubic": 3}
return order_map.get(interp, None)
assert f('nearest') == 0 |
benchmark_functions_edited/f4482.py | def f(a, b):
q, r = divmod(a, b)
return q + (2*r + (q&1) > b)
assert f(2, 1) == 2 |
benchmark_functions_edited/f3000.py | def f(t):
return 35*t**4 -84*t**5 + 70*t**6 -20*t**7
assert f(0) == 0 |
benchmark_functions_edited/f8703.py | def f(num):
# `- 2` is due the output format of `bin`: `0bXXXXXXX`
return len(bin(num)) - 2
assert f(6) == 3 |
benchmark_functions_edited/f4184.py | def f(list_values):
min_score = min(list_values)
return min_score
assert f(list(range(3,6))) == 3 |
benchmark_functions_edited/f2197.py | def f(x):
try:
return int(x)
except:
return x
assert f(5.999) == 5 |
benchmark_functions_edited/f11486.py | def f(true_entities, pred_entities):
nb_correct = len(true_entities & pred_entities)
nb_pred = len(pred_entities)
nb_true = len(true_entities)
p = nb_correct / nb_pred if nb_pred > 0 else 0
r = nb_correct / nb_true if nb_true > 0 else 0
score = 2 * p * r / (p + r) if p + r > 0 else 0
retur... |
benchmark_functions_edited/f6824.py | def f(results):
if len(results) == 1:
return results[0][2]
return max(results, key=lambda x: x[2])[2]
assert f(
[
(['1', '2', '3', '4'], 'test.txt', 1),
(['1', '2', '3', '4'], 'test.txt', 2),
(['1', '2', '3', '4'], 'test.txt', 4),
]
) == 4 |
benchmark_functions_edited/f13901.py | def f(k, n):
hi = 1
while pow(hi, k) < n:
hi *= 2
lo = hi // 2
while hi - lo > 1:
mid = (lo + hi) // 2
midToK = pow(mid, k)
if midToK < n:
lo = mid
elif n < midToK:
hi = mid
else:
return mid
if pow(hi, k) == n:
... |
benchmark_functions_edited/f11035.py | def f(pixel, gamma=2):
return pixel[0] if len(pixel) == 1 else ((pixel[0]**gamma + pixel[1]**gamma + pixel[2]**gamma)/3)**(1/gamma) if len(pixel) == 3 else ((pixel[0]**gamma + pixel[1]**gamma + pixel[2]**gamma)/3)**(1/gamma) * pixel[3] / 255
assert f((0, 0, 0)) == 0 |
benchmark_functions_edited/f12223.py | def f(val, min, max):
val = float(val)
min = float(min)
max = float(max)
if val < min:
return min
elif val > max:
return max
else:
return val
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f9811.py | def f(a, b):
if a+1 == b:
if a%2 == 0:
return 'EvenOdd'
else:
return 'OddEven'
if a == b+1:
if a%2 == 0:
return 'OddEven'
else:
return 'EvenOdd'
return b - a
assert f(2, 2) == 0 |
benchmark_functions_edited/f1160.py | def f(number: int) -> int:
return 1 << (number - 1)
assert f(1) == 1 |
benchmark_functions_edited/f3032.py | def f(p1, p2):
e = p1[0]*p2[0]
px = p1[1]*p2[1]
py = p1[2]*p2[2]
pz = p1[3]*p2[3]
return e - px - py - pz
assert f( (0,0,0,0), (1,0,0,1) ) == 0 |
benchmark_functions_edited/f5026.py | def f(s1, s2):
return abs(len(s1) - len(s2)) + sum(
map(lambda p: 0 if p[0] == p[1] else 1, zip(s1.lower(), s2.lower())))
assert f(
"a",
"b"
) == 1 |
benchmark_functions_edited/f12091.py | def f(n):
x = 0
y = 1
if n == 1:
return 1
for i in range(n):
_tmp = x # the current `x' is stored in a tmp variable
x = y # `x' becomes the previous `y'
y = _tmp + x # `y' becomes the sum of the previous `x' and `y'
return y
assert f(1) == 1 |
benchmark_functions_edited/f8874.py | def f(text):
text = text.lower()
return text == "1" or text.startswith("y") or text == "true" or text == "on"
assert f("yEs") == 1 |
benchmark_functions_edited/f7941.py | def f(data):
if isinstance(data, dict):
return 1 + (max(map(depth, data.values())) if data else 0)
return 0
assert f({'a': 1}) == 1 |
benchmark_functions_edited/f9015.py | def f(value, mod=1):
if value == None:
return None
elif mod <= 0:
return None
elif value < 0:
return (value % mod + mod) % mod
else:
return value % mod
assert f(-2, 2) == 0 |
benchmark_functions_edited/f3896.py | def f(value, total_sum):
if total_sum == 0:
return 0
else:
return round(100 * float(value) / float(total_sum))
assert f(0, 20) == 0 |
benchmark_functions_edited/f4569.py | def f(values1, values2):
return sum((v1 - v2) ** 2 for v1, v2 in zip(values1, values2))
assert f({1, 2}, {1, 2}) == 0 |
benchmark_functions_edited/f5223.py | def f(base, exponent):
if base>0:
return abs(base)**exponent
else:
return -(abs(base)**exponent)
assert f(1, 5) == 1 |
benchmark_functions_edited/f4962.py | def f(i, n):
return (1 + i) ** n
assert f(0.1, 0) == 1 |
benchmark_functions_edited/f4596.py | def f(instance, path):
for key in path:
instance = instance[key]
return instance
assert f(
{"a": {"b": 1}},
["a", "b"]
) == 1 |
benchmark_functions_edited/f4358.py | def f(value, fn, undefined):
if fn(value):
return undefined
return value
assert f(1, lambda x: x < 2, 3) == 3 |
benchmark_functions_edited/f5386.py | def f(x):
result = 1/x # Raises a ZeroDivisionError if x is 0
print('Never printed if x is 0')
return result
assert f(0.5) == 2 |
benchmark_functions_edited/f433.py | def f(val):
return isinstance(val, bool)
assert f(0) == 0 |
benchmark_functions_edited/f12765.py | def f(haystack, needle, lo, hi):
while lo < hi:
mid = (lo + hi) // 2
if haystack[mid] > needle:
hi = mid
elif haystack[mid] < needle:
lo = mid + 1
else:
return mid
return hi
assert f((1, 2, 3, 4, 5, 6), 2, 2, 6) == 2 |
benchmark_functions_edited/f6958.py | def f(f, x0, eps=1e-6):
e = 1e-6
return ((f(x0 + (eps/2))) - (f(x0 - (eps/2)))) / eps
assert f(lambda x: 2*x, 0) == 2 |
benchmark_functions_edited/f8809.py | def f(input_, condition=lambda x: True):
return sum(condition(item) for item in input_)
assert f("abc", lambda x: x!= "a") == 2 |
benchmark_functions_edited/f7764.py | def f(eligible_year):
if not eligible_year:
return -1
if eligible_year[0].isdigit():
return int(eligible_year[0])
return -1
assert f('1') == 1 |
benchmark_functions_edited/f2516.py | def f(a, b):
while b:
a, b = b, a % b
return a
assert f(10, 5) == 5 |
benchmark_functions_edited/f4526.py | def f(c1, c2):
return len(set(c1).intersection(c2))*1./len(set(c1).union(c2))
assert f(set([1, 2, 3]), set([])) == 0 |
benchmark_functions_edited/f6510.py | def f(cost, dis):
gain = dis - cost
ROI = (gain/cost)
return round(ROI, 4)
assert f(100, 100) == 0 |
benchmark_functions_edited/f12726.py | def f(ids, obj):
if id(obj) in ids:
return
ids.add(id(obj))
if isinstance(obj, (list, tuple, set, frozenset)):
for e in obj:
f(ids, e)
elif isinstance(obj, dict):
for k, v in obj.items():
f(ids, k)
f(ids, v)
return len(ids)
assert f(set(),... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.