file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f13085.py | def f(poly, x):
return sum(c*(x**i) for i, c in enumerate(poly))
assert f((), 2) == 0 |
benchmark_functions_edited/f2554.py | def f(annual_interest, years):
return (1.0 + annual_interest)**years - 1.0
assert f(0.0, 1) == 0 |
benchmark_functions_edited/f7527.py | def f(first, second):
if first == second:
return 0
try:
return (abs(first - second) / second) * 100.0
except ZeroDivisionError:
return float("inf")
assert f(10, 10) == 0 |
benchmark_functions_edited/f5448.py | def f(data, char):
for i in range(len(data)):
if data[i] != char:
return i
return len(data)
assert f(b"abcd", b"d") == 0 |
benchmark_functions_edited/f3266.py | def f(priority: str) -> int:
return ('low','medium','high').index(priority.lower())
assert f("HIGH") == 2 |
benchmark_functions_edited/f6268.py | def f(*args, **kwargs):
result = 0
for arg in args:
result += 1
for kwarg in kwargs:
result += 1
return result
assert f(1) == 1 |
benchmark_functions_edited/f12649.py | def f(lst, lst_size=None):
lst = sorted(lst)
if lst_size:
n = lst_size
n_diff = n - len(lst)
i = (n - 1) // 2 - n_diff
if i < 0:
if i == -1 and not n % 2:
return lst[0] / 2.
return 0
else:
n = len(lst)
i = (n - 1) // 2
return lst[i] if n % 2 else (lst[i] + lst[i + 1]) / 2.
assert f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
len(range(1, 16))) == 8 |
benchmark_functions_edited/f12639.py | def f(temperatures):
closest_to_zero = temperatures[0]
for temperature in temperatures:
if (abs(temperature) < abs(closest_to_zero) or
(abs(temperature) == abs(closest_to_zero) and temperature > 0)):
closest_to_zero = temperature
return closest_to_zero
assert f(range(10)) == 0 |
benchmark_functions_edited/f9978.py | def f(input):
input = [int(c) for c in input]
result = 0
previous = input[0]
for c in input[1:]:
if c == previous:
result += c
previous = c
if previous == input[0]:
result += previous
# print 'result=' + str(result)
return result
assert f('0123456789012345678901234567890123456789012345678901234567890123456789') == 0 |
benchmark_functions_edited/f9135.py | def f(n):
if n < 0:
raise ValueError('')
return 1 if n<=2 else f(n-1) + f(n-2)
assert f(0) == 1 |
benchmark_functions_edited/f5132.py | def f(seconds: int) -> int:
hours = seconds // (60 * 60)
if hours < 24:
return hours
return hours % 24
assert f(7201) == 2 |
benchmark_functions_edited/f5638.py | def f(list1, list2):
return len(list(set(list1).intersection(list2)))
assert f(
[3, 5, 4, 1, 2],
[3, 5, 4, 1, 2, 10, 11, 12, 13, 14],
) == 5 |
benchmark_functions_edited/f5705.py | def f(MIN: int, n: int, MAX: int) -> int:
if MIN < MAX:
return max(MIN, min(n, MAX - 1))
else:
raise ValueError("MAX value must be greater than MIN value")
assert f(0, 5, 10) == 5 |
benchmark_functions_edited/f13098.py | def f(name, num_layers):
if name in ["cls_token", "pos_embed"]:
return 0
elif name.startswith("patch_embed"):
return 0
elif name.startswith("blocks"):
return int(name.split(".")[1]) + 1
else:
return num_layers
assert f(
"patch_embed.proj", 3
) == 0 |
benchmark_functions_edited/f11687.py | def f(uint, bits):
if (uint & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255
uint = uint - (1 << bits) # compute negative value
return uint
assert f(2, 3) == 2 |
benchmark_functions_edited/f9489.py | def f(intf, ints):
try:
return float(intf) % float(ints)
except ValueError:
raise ValueError("%s/%s is not a number" % (intf, ints))
assert f(1, 1) == 0 |
benchmark_functions_edited/f9691.py | def f(incpwi):
if incpwi == 0 or incpwi == 7:
return 0
elif 1 <= incpwi <= 6:
return 1
elif incpwi == 8:
return 88
else:
raise KeyError('incpwi: %s' % incpwi)
assert f(0) == 0 |
benchmark_functions_edited/f1331.py | def f(num, n):
shifted = num >> n
return shifted & 1
assert f(7, 1) == 1 |
benchmark_functions_edited/f7493.py | def f(l):
mp = dict()
for i in l:
if i not in mp.keys():
mp[i] = 1
else:
mp[i]+=1
return sorted(list(mp.values()),reverse=True)[0]
assert f([1, 2, 2, 2, 3]) == 3 |
benchmark_functions_edited/f10811.py | def f(val, candidates, name):
if val not in candidates:
message = \
"{0} can not be used for {1}. " \
"Available values are {2}." \
.format(val, name, candidates)
raise ValueError(message)
return val
assert f(1, {1, 2, 3}, 'a') == 1 |
benchmark_functions_edited/f8768.py | def f(y, transformers):
# Note that transformers have to be undone in reversed order
for transformer in reversed(transformers):
if transformer.transform_y:
y = transformer.untransform(y)
return y
assert f(0, []) == 0 |
benchmark_functions_edited/f5373.py | def f(n, memo):
if n in memo: return memo[n]
if n <= 2: return 1
memo[n] = f(n-1, memo) + f(n-2, memo)
print("here", memo)
return memo[n]
assert f(4, {}) == 3 |
benchmark_functions_edited/f9071.py | def f(c):
return next(iter(c))
assert f(set([1,2,3])) == 1 |
benchmark_functions_edited/f3517.py | def f(field, operation):
if operation['key'] in field:
result = field[operation['key']]
return len(result)
return 0
assert f(
{'title': 'The Lord of the Rings', 'genres': ['fantasy', 'adventure']},
{'operation': 'len', 'key': 'genres'}
) == 2 |
benchmark_functions_edited/f2116.py | def f(x,rmin,rmax,smin,smax):
r = (smax-smin)/(rmax-rmin)
x_ = smin + r * (x-rmin)
return x_
assert f(0, 0, 400, 0, 200) == 0 |
benchmark_functions_edited/f11988.py | def f(nest_spec):
def count_each_nest(spec, count):
if isinstance(spec, dict):
return count + sum([count_each_nest(alt, count) for alt in spec['alternatives']])
else:
return 1
return count_each_nest(nest_spec, 0) if nest_spec is not None else 0
assert f({'alternatives': [1, 2]}) == 2 |
benchmark_functions_edited/f3708.py | def f(frame_rate, number_of_seconds):
return int(number_of_seconds * frame_rate)
assert f(1, 2) == 2 |
benchmark_functions_edited/f1440.py | def f(r):
return int(r.get("wedWinst", 0))
assert f(
{"wedWinst":"0"}) == 0 |
benchmark_functions_edited/f9635.py | def f(value):
if isinstance(value, bool):
return int(value)
else:
return 0
assert f("") == 0 |
benchmark_functions_edited/f4673.py | def f(state, actions, Q, U):
def EU(action):
return Q(state, action, U)
return max(actions(state), key=EU)
assert f(1, lambda s: [0, 1], lambda s, a, u: 1 if a == 1 else 0, lambda s, a: 1) == 1 |
benchmark_functions_edited/f5979.py | def f(manifest: dict):
return sum([x.get("size", 0) for x in manifest.get("layers", [])])
assert f({"layers": []}) == 0 |
benchmark_functions_edited/f11914.py | def f(x):
if "Elementary" in str(x):
return 0
elif "Intermediate" in str(x):
return 1
elif "Advanced" in str(x):
return 2
elif "B2" and "C1" in str(x):
return 1
elif "B1" and not "C1" in str(x):
return 0
else:
return 0
assert f(30) == 0 |
benchmark_functions_edited/f8133.py | def f(array):
prev = None
inc = 0
for n in array:
if prev and n > prev:
inc += 1
prev = n
return inc
assert f([1, 1]) == 0 |
benchmark_functions_edited/f2865.py | def f(vw_example):
return float(vw_example.split('|')[0])
assert f('\t1.0') == 1 |
benchmark_functions_edited/f13021.py | def f(v):
if v is None or v > 0:
return v
return v + 8
assert f(2) == 2 |
benchmark_functions_edited/f8765.py | def f(component_limit, overall_limit):
limits = [limit for limit in [component_limit, overall_limit] if limit is not None]
return min(limits) if limits else None
assert f(123, 0) == 0 |
benchmark_functions_edited/f9502.py | def f(inlist):
if isinstance(inlist, (list, tuple)):
return inlist[-1]
return inlist
assert f(0) == 0 |
benchmark_functions_edited/f13234.py | def f(x, y):
if x is None and y is None:
return 0
elif x is None:
return -1
elif y is None:
return 1
return (x > y) - (x < y)
assert f(2, 2.0) == 0 |
benchmark_functions_edited/f781.py | def f(fd, nbTicks):
return int( (fd % 1) * nbTicks)
assert f(0, 10) == 0 |
benchmark_functions_edited/f1562.py | def f(a: str, b: str) -> int:
return sum([1 for c in b if c in a])
assert f(b'10110', b'') == 0 |
benchmark_functions_edited/f3571.py | def f(record):
return record['valley_idx'] - record['start_idx']
assert f({'start_idx': 0, 'valley_idx': 1, 'foo': 'bar'}) == 1 |
benchmark_functions_edited/f13630.py | def f(selectpicker_id: str) -> int:
min_values = {
"1": 0,
"2": 1,
"3": 2,
"4": 3,
"5": 4,
"6": 5,
"7": 6,
"8": 7,
"9": 8,
"10": 9,
"11": 10,
"12": 15,
"13": 20,
"14": 30,
"15": 40,
"16": 50
}
return min_values.get(selectpicker_id, 0)
assert f(
"8") == 7 |
benchmark_functions_edited/f4471.py | def f(num_str):
try:
return int(num_str)
except:
pass
return None
assert f("5") == 5 |
benchmark_functions_edited/f14102.py | def f(x, high, low, threshold):
if x < threshold:
return high
else:
return low
assert f(0.01, 1, 2, 1) == 1 |
benchmark_functions_edited/f11351.py | def f(chaffy_val, chaff_val = 98127634):
val, chaff = divmod(chaffy_val, chaff_val)
if chaff != 0:
raise ValueError("Invalid chaff in value")
return val
assert f(0) == 0 |
benchmark_functions_edited/f9571.py | def f(a, b, c, d, e):
return a + b + c + d
assert f(1, 1, 1, 1, 1) == 4 |
benchmark_functions_edited/f7690.py | def f(line: str) -> int:
if not line:
return 0
for n, char in enumerate(line, start=0):
if char != "#":
return n
return len(line)
assert f("hello, world! #") == 0 |
benchmark_functions_edited/f10785.py | def f(o, a, b):
return (a[0] - o[0]) * (b[1] - a[1]) - (a[1] - o[1]) * (b[0] - a[0])
assert f(
(0, 0),
(0, 1),
(0, 0),
) == 0 |
benchmark_functions_edited/f9274.py | def f(number, decimals):
number = float(number)
out = round(number, decimals)
return out
assert f(0.45, 0) == 0 |
benchmark_functions_edited/f14261.py | def f(agent_traits, neighbor_traits):
overlap = len(agent_traits.intersection(neighbor_traits))
#log.debug("overlap: %s", overlap)
return overlap
assert f(set(['a','b','c','d']), set(['a','b','c'])) == 3 |
benchmark_functions_edited/f5100.py | def f(p1, p2):
tx, ty = p2[0]-p1[0], p2[1]-p1[1]
return tx*tx + ty*ty
assert f( (-2, 0), (0, 2) ) == 8 |
benchmark_functions_edited/f1380.py | def f(a, b):
x, y = a[0] - b[0], a[1] - b[1]
return x**2 + y**2
assert f(
(0, 0),
(0, 0)
) == 0 |
benchmark_functions_edited/f4542.py | def f( s, target, i=0 ):
result = s.f( target, i )
if result == -1: result = len( s )
return result
assert f( "abcdef", "cdef" ) == 2 |
benchmark_functions_edited/f10725.py | def f(num):
if num > 0:
return 1
elif num < 0:
return -1
return 0
assert f(0) == 0 |
benchmark_functions_edited/f8445.py | def f(x):
m = 1
count = 0
for i in range(x // 2 + 1):
if x & m == m:
count += 1
m = m << 1
return count
assert f(33) == 2 |
benchmark_functions_edited/f459.py | def f(*args):
sum = 0.0
for arg in args:
sum += arg
return sum
assert f(1, 3) == 4 |
benchmark_functions_edited/f1472.py | def f(x):
if x == 0 or x == 1:
return 1
return f(x - 1) + f(x - 2)
assert f(5) == 8 |
benchmark_functions_edited/f12874.py | def f(first, second):
sum = 0
for i in range(len(first)):
if first[i] != second[i]:
sum += 1
return sum
assert f('G', 'G') == 0 |
benchmark_functions_edited/f11905.py | def f(bits_a, bits_b):
return sum([abs(bits_a[i] - bits_b[i]) for i in range(0, len(bits_a))])
assert f((1,), (0,)) == 1 |
benchmark_functions_edited/f6701.py | def f(discrimination, ratio, _, __, interpolate_function):
return interpolate_function(discrimination, ratio)
assert f(0.5, 0.05, 0, 1, lambda _, __: 1) == 1 |
benchmark_functions_edited/f10349.py | def f(value):
if isinstance(value, str) and len(value) == 1:
return ord(value)
elif isinstance(value, int):
if value > 127:
return f(value - 256)
if value < -128:
return f(256 + value)
return value
assert f(-255) == 1 |
benchmark_functions_edited/f13980.py | def f(list1, list2):
# Make sure we're working with lists
# Sorry, no other iterables are permitted
assert isinstance(list1, list)
assert isinstance(list2, list)
dist = 0
# 'zip' is a Python builtin, documented at
# <http://www.python.org/doc/lib/built-in-funcs.html>
for item1, item2 in zip(list1, list2):
if item1 != item2: dist += 1
return dist
assert f(list("a"), list("a")) == 0 |
benchmark_functions_edited/f5866.py | def f(Omega, k, l, m, f, N2, w=0):
K2 = k**2 + l**2 + m**2
return (-1*(k**2 + l**2) * m * (N2 - f**2)) / (K2**2 * Omega)
assert f(5, 1, 1, 1, 0, 0) == 0 |
benchmark_functions_edited/f14212.py | def f(sorting: list, left: int, right: int) -> int:
pivot = sorting[right]
store_index = left
for i in range(left, right):
if sorting[i] < pivot:
sorting[store_index], sorting[i] = sorting[i], sorting[store_index]
store_index += 1
sorting[right], sorting[store_index] = sorting[store_index], sorting[right]
return store_index
assert f([0, 5, 7, 6], 0, 3) == 2 |
benchmark_functions_edited/f10451.py | def f(address, mesh):
# X runs first in XYZ
# (*In spglib, Z first is possible with MACRO setting.)
m = mesh
return (address[0] % m[0] +
(address[1] % m[1]) * m[0] +
(address[2] % m[2]) * m[0] * m[1])
assert f(
(1, 0, 0),
(4, 4, 4)) == 1 |
benchmark_functions_edited/f7533.py | def f(n, r):
import operator as op
from functools import reduce
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer // denom
assert f(4, 2) == 6 |
benchmark_functions_edited/f3919.py | def f(textlist):
maxlen = 0
for text in textlist:
maxlen = max(maxlen,len(text))
return maxlen
assert f([]) == 0 |
benchmark_functions_edited/f7695.py | def f(x):
# Rely on the fact that Python's "bin" method prepends the string
# with "0b": https://docs.python.org/3/library/functions.html#bin
return len(bin(x)[2:])
assert f(6) == 3 |
benchmark_functions_edited/f4483.py | def f(precision, recall):
return 2.0 * ((precision * recall) / (precision + recall))
assert f(1, 0) == 0 |
benchmark_functions_edited/f5679.py | def f(numbers):
max_number = max(numbers)
final_list = [number for number in numbers if max_number > number]
return max(final_list)
assert f(list(range(1, 10))) == 8 |
benchmark_functions_edited/f1367.py | def f(i):
r = i % 4
return i if not r else i + 4 - r
assert f(3) == 4 |
benchmark_functions_edited/f13324.py | def f(time_unit):
scalings = {'ms': 1000, 's': 1, 'unknown': 1}
if time_unit in scalings:
return scalings[time_unit]
else:
raise RuntimeError(f'The time unit {time_unit} is not supported by '
'MNE. Please report this error as a GitHub '
'issue to inform the developers.')
assert f('unknown') == 1 |
benchmark_functions_edited/f10323.py | def f(seq, pred):
for i, v in enumerate(seq):
if pred(v):
return i
return None
assert f(range(10), lambda x: x >= 4 and x < 7) == 4 |
benchmark_functions_edited/f11045.py | def f(val):
return int.from_bytes(val, byteorder='little')
assert f(b'') == 0 |
benchmark_functions_edited/f6917.py | def f(age):
if age >= 75:
return 15
else:
return age // 5
assert f(1) == 0 |
benchmark_functions_edited/f11786.py | def f(min, max, value):
if max < min:
raise ValueError(
"\
min must not be greater than max in f(min, max, value)"
)
if value > max:
return max
if value < min:
return min
return value
assert f(2, 5, 1) == 2 |
benchmark_functions_edited/f11741.py | def f(index, tp):
if isinstance(index, tuple):
return sum([f(i, tp) for i in index])
elif isinstance(index, tp):
return 1
else:
return 0
assert f(slice(None, None, -1), slice) == 1 |
benchmark_functions_edited/f3252.py | def f(a,value):
return min(range(len(a)),key=lambda i: abs(a[i] - value))
assert f(
[1,2,3],
-4
) == 0 |
benchmark_functions_edited/f6286.py | def f(ctx, param, value):
try:
count = value.replace(",", "")
return int(count)
except ValueError:
return int(value)
assert f(None, None, "1") == 1 |
benchmark_functions_edited/f10640.py | def f(obj, *attrs):
for attr in attrs:
try:
return getattr(obj, attr)
except AttributeError:
pass
obj_name = obj.__name__
raise AttributeError("'{}' object has no attribute in {}", obj_name, attrs)
assert f(complex(3, 4), "real") == 3 |
benchmark_functions_edited/f13118.py | def f(j, n=None):
if type(j) is not int:
try:
j = j.__index__()
except AttributeError:
raise IndexError("Invalid index a[%r]" % (j,))
if n is not None:
if j < 0:
j += n
if not (j >= 0 and j < n):
raise IndexError("Index out of range: a[%s]" % j)
return int(j)
assert f(-1, 2) == 1 |
benchmark_functions_edited/f5163.py | def f(array, element):
if element in array:
return array.index(element)
else:
return -1
assert f(range(10), 3) == 3 |
benchmark_functions_edited/f8059.py | def f(num_tiles):
num_partitions = max(min(num_tiles // 1500, 128), 8)
return num_partitions
assert f(100) == 8 |
benchmark_functions_edited/f9995.py | def f(metric_fn, prediction, ground_truths):
scores_for_ground_truths = []
for ground_truth in ground_truths:
score = metric_fn(prediction, ground_truth)
scores_for_ground_truths.append(score)
return max(scores_for_ground_truths)
assert f(lambda prediction, ground_truth: 0, 'p', ['g1', 'p']) == 0 |
benchmark_functions_edited/f10993.py | def f(lst):
sorted_lst = sorted(lst)
length = len(sorted_lst)
if length % 2:
return sorted_lst[length // 2]
return (sorted_lst[length // 2 - 1] + sorted_lst[length // 2]) / 2
assert f([2]) == 2 |
benchmark_functions_edited/f12690.py | def f(x, y, max_iters):
i = 0
c = complex(x, y)
z = 0.0j
for i in range(max_iters):
z = z * z + c
if (z.real * z.real + z.imag * z.imag) >= 4:
return i
return 255
assert f(-2, 0, 10) == 0 |
benchmark_functions_edited/f5303.py | def f(bits):
bits_per_byte = 8
return (bits + (bits_per_byte - 1)) // bits_per_byte
assert f(24) == 3 |
benchmark_functions_edited/f1629.py | def f(size, value):
return (value + size - 1)/size*size
assert f(6, 1) == 6 |
benchmark_functions_edited/f9773.py | def f(s, enc, cc):
s = s.encode('UTF-32LE')
clen = cc * 4
if clen > len(s):
raise IndexError
return len(s[:clen].decode('UTF-32LE').encode(enc))
assert f(u'abcd', *('utf-32-le', 2)) == 8 |
benchmark_functions_edited/f12383.py | def f(n):
"*** YOUR CODE HERE ***"
if n <= 3:
return n
else:
return f(n - 1) + 2 * f(n - 2) + 3 * f(n - 3)
assert f(2) == 2 |
benchmark_functions_edited/f14313.py | def f(geoact, geoacs, subff2):
if geoact == 2 or (geoact == 1 and 2 <= geoacs <= 4):
cga = 1
elif geoact == 8 or geoacs == 8:
cga = 88
else:
cga = 0
if cga == 1 and subff2 == 2:
cga = 0
return cga
assert f(1, 4, 0) == 1 |
benchmark_functions_edited/f1762.py | def f(x, y):
return 0 if x <= 0 else round(x / y)
assert f(0, 200) == 0 |
benchmark_functions_edited/f8391.py | def f(vertices):
assert len(vertices) == 2
width = abs(vertices[0][0] - vertices[1][0])
height = abs(vertices[0][1] - vertices[1][1])
dot_count = (width + 1) * (height + 1)
return dot_count
assert f(
[(1, 1), (1, 3)]
) == 3 |
benchmark_functions_edited/f3110.py | def f(pl: list) -> int:
return sum(pl) % 2
assert f(bytearray([0x00, 0x00, 0x00])) == 0 |
benchmark_functions_edited/f2914.py | def f(diff):
if diff["action"] == "delete":
return 1
else:
return 2
assert f(
{"action": "create", "path": "b"}
) == 2 |
benchmark_functions_edited/f8928.py | def f(values, n=0.95):
sorted_vals = sorted(values)
ind = int(len(sorted_vals) * n)
return sorted_vals[ind]
assert f(range(10),.99) == 9 |
benchmark_functions_edited/f881.py | def f(e,t):
return (int(e(t+1)) % 256)
assert f(lambda t: 1, 1) == 1 |
benchmark_functions_edited/f4084.py | def f(component):
component /= 255.0
return component / 12.92 if component <= 0.04045 else ((component+0.055)/1.055)**2.4
assert f(0) == 0 |
benchmark_functions_edited/f2397.py | def f(x):
if x is None:
return -1
else:
return x
assert f(0) == 0 |
benchmark_functions_edited/f7911.py | def f(concentration=1,molWeight=17,density=1.347):
concentration_mg_ml = concentration*molWeight
volume_fraction = concentration_mg_ml/density/1e3
return volume_fraction
assert f(1,0,1.347) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.