file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f10412.py | def f(label):
return_val = None
try:
return_val = label.split('-').pop()
return_val = int(return_val)
except:
pass
return return_val
assert f('copy-s3-data-4') == 4 |
benchmark_functions_edited/f1329.py | def f(i, N):
i=i+1 #THIS IS SO THE DISPERSION IS THE SAME AS IN mathematica
return -1 + (2/(N+1) * i)
assert f(0, 1) == 0 |
benchmark_functions_edited/f4462.py | def f(x: float) -> float:
if x > 0:
return 1.0
elif x < 0:
return -1.0
else:
return 0.0
assert f(f(0.0)) == 0 |
benchmark_functions_edited/f10736.py | def f(axis_name):
axis_name = axis_name.replace("-", "")
if axis_name == 'x':
return 0
elif axis_name == 'y':
return 1
elif axis_name == 'z':
return 2
else:
raise ValueError("'{}' is not a valid axisname.".format(axis_name))
assert f('z') == 2 |
benchmark_functions_edited/f11597.py | def f(b,e,n):
accum = 1; i = 0; bpow2 = b
while ((e>>i)>0):
if((e>>i) & 1):
accum = (accum*bpow2) % n
bpow2 = (bpow2*bpow2) % n
i+=1
return accum
assert f(5,0,31) == 1 |
benchmark_functions_edited/f7847.py | def f(lst):
for i, e in enumerate(lst):
if e.startswith("list_"):
return i
return -1
assert f(
['prop1', 'prop2', 'prop3', 'list_prop', 'list_prop2']) == 3 |
benchmark_functions_edited/f12896.py | def f(target, start, end):
assert target >= start
assert target <= end
epoch_delta = end - start
if epoch_delta == 0:
return 0
else:
return (target - start) / epoch_delta
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f13304.py | def f(height, width):
if (width == 0) and (height in (0,1)):
return 1
if (width == 1) and (height in (1,2)):
return 1
if height > width:
return f(height - 1, width) + f(height - 2, width)
if width == height:
return f(height - 1, width - 1) + f(height - 2, width - 2)
return 0
assert f(3,1) == 2 |
benchmark_functions_edited/f11713.py | def f(labels, predictions):
loss = 0
for l, p in zip(labels, predictions):
loss = loss + (l - p) ** 2
loss = loss / len(labels)
return loss
assert f([1, 2, 3], [1, 2, 3]) == 0 |
benchmark_functions_edited/f9496.py | def f(field: str) -> int:
if field != "":
hour = int(field[0:2])
minute = int(field[3:5])
second = int(field[6:8])
return 1000000 * ((3600 * hour) + (60 * minute) + second)
else:
return 0
assert f("00:00:00") == 0000000 |
benchmark_functions_edited/f4781.py | def f(x, y):
if x % y == 0: # if statement to identify
return y
else:
return f(y, x % y)
assert f(100, 1) == 1 |
benchmark_functions_edited/f2320.py | def f(l):
if ".txt" in str(l):
return 1
else:
return 0
assert f("abc.abc") == 0 |
benchmark_functions_edited/f6182.py | def f(recpat_bag:list):
return max([len(recpat) for recpat in recpat_bag])
assert f([(0, 0), (0, 1), (1, 1)]) == 2 |
benchmark_functions_edited/f13274.py | def f(input_array, value):
num = len(input_array)
index = round(num / 2 + 0.1) - 1
while 0 <= index < num:
current = input_array[index]
if current < value:
index = round((num - 1 - index) / 2 + 0.1) + index
elif current > value:
index = index - round((num - 1 - index + 0.1) / 2)
else:
return index
return -1
assert f(list(range(10)), 4) == 4 |
benchmark_functions_edited/f12283.py | def f(sentence):
vowels = ['a', 'e', 'i', 'o', 'u']
count = 0
for ch in sentence:
if ch in vowels:
count += 1
return count
assert f("aaaa") == 4 |
benchmark_functions_edited/f6262.py | def f(lis, alternatives):
for alt in alternatives:
try:
return lis.f(alt)
except ValueError:
pass
return None
assert f((1, 2, 3, 4), (3,)) == 2 |
benchmark_functions_edited/f2286.py | def f(cl_i, int_, n_term):
return cl_i * ((int_ * (1 + int_) ** n_term) / ((1 + int_) ** n_term - 1))
assert f(0, 0.08, 10) == 0 |
benchmark_functions_edited/f6875.py | def f(pairs_list, key):
for pair in pairs_list:
if pair[0] == key:
return pair[1]
raise ValueError('Attribute not found: {}'.format(key))
assert f(
[('a', 4), ('a', 3)], 'a') == 4 |
benchmark_functions_edited/f1936.py | def f(value, default):
if (value is None): return default
return value
assert f(None, 1) == 1 |
benchmark_functions_edited/f10211.py | def f(solution, answer):
score =0
for i in range(len(answer)):
score += (abs(solution[i]-answer[i]))
return score
assert f(b'Hello', b'Hello') == 0 |
benchmark_functions_edited/f13220.py | def f(value, conversions, default):
return conversions.get(value, default)
assert f(0.1, {0.1: 0}, 3) == 0 |
benchmark_functions_edited/f7429.py | def f(n_words):
n = int(0.5 + ((1 + 4 * n_words)**0.5)/2) - 1
assert n_words == (n * (n + 1)), "Could not infer a square matrix from file"
return n
assert f(0) == 0 |
benchmark_functions_edited/f5536.py | def f(codelChooser: int) -> int:
return int(not codelChooser)
assert f(0) == 1 |
benchmark_functions_edited/f614.py | def f(n):
return n * f(n-1) if n else 1
assert f(1) == 1 |
benchmark_functions_edited/f824.py | def f(x1, y1, x2, y2):
return abs(x1-x2) + abs(y1-y2)
assert f(1, 3, -1, 8) == 7 |
benchmark_functions_edited/f13541.py | def f(nums):
if len(nums) == 0: return 0
sums = []
sums.append(nums[0])
mini = maxi = 0
for i in range(1, len(nums)):
sums.append(sums[-1] + nums[i])
mini = i if sums[mini] > sums[-1] else mini
maxi = i if sums[maxi] < sums[-1] else maxi
return max(nums[mini], nums[maxi]) if maxi <= mini else sums[maxi] - sums[mini]
assert f([]) == 0 |
benchmark_functions_edited/f1710.py | def f(*args):
res = 0
for arg in args:
res |= arg
return res
assert f(1, 1, 0) == 1 |
benchmark_functions_edited/f10036.py | def f(predicate, it):
return next(
(v for v in it if (predicate(v) if predicate else v is not None)),
None,
)
assert f(lambda x: x > 3, [1, 2, 3, 4, 5]) == 4 |
benchmark_functions_edited/f435.py | def f(x):
def inner_fn(y):
return y
return inner_fn(x)
assert f(4) == 4 |
benchmark_functions_edited/f9120.py | def f(x1: float, x2: float) -> float:
return abs(x1 - x2)
assert f(10, 10) == 0 |
benchmark_functions_edited/f84.py | def f(*args):
return min(*args)
assert f(1, 2, 3, 4) == 1 |
benchmark_functions_edited/f8200.py | def f(n):
if n <= 1:
return n
previous = 0
current = 1
sum = 1
for _ in range(n - 1):
previous, current = current, previous + current
sum += current
return sum % 10
assert f(1) == 1 |
benchmark_functions_edited/f11798.py | def f(a, b, c):
p = a + b - c
pa = abs(p - a)
pb = abs(p - b)
pc = abs(p - c)
if pa <= pb and pa <= pc:
return a
elif pb <= pc:
return b
else:
return c
assert f(1, 0, 0) == 1 |
benchmark_functions_edited/f13677.py | def f(nums):
if len(nums) != 3:
raise ValueError('I only work on lists of size 3.')
if nums[1] < nums[0]:
if nums[2] < nums[1]:
return nums[0]
if nums[2] < nums[0]:
return nums[0]
return nums[2]
if nums[1] < nums[2]:
return nums[2]
return nums[1]
assert f( [3, 3, 2] ) == 3 |
benchmark_functions_edited/f1543.py | def f(condition, a, b):
if condition: return a
else: return b
assert f(True, 3, 4) == 3 |
benchmark_functions_edited/f10244.py | def f(s):
num_vowels = 0
for char in s:
if char in 'aeiouAEIOU':
num_vowels = num_vowels + 1
return num_vowels
assert f('Mmmm') == 0 |
benchmark_functions_edited/f5036.py | def f(ring_size: int) -> int:
return (ring_size - 1).bit_length()
assert f(123) == 7 |
benchmark_functions_edited/f3043.py | def f(x, y, param_0):
return (x + y ** 2) * param_0
assert f(1, 2, 1) == 5 |
benchmark_functions_edited/f1278.py | def f(offset):
return ((offset + 3) >> 2) << 2
assert f(6) == 8 |
benchmark_functions_edited/f5919.py | def f(registers, opcodes):
test_result = registers[opcodes[1]] * opcodes[2]
return test_result
assert f(
[0, 1, 2, 3, 4],
[9, 0, 3]
) == 0 |
benchmark_functions_edited/f10957.py | def f(room_temp, radiator_temp):
conductance = 25 # thermal conductance [W/K]
return (radiator_temp - room_temp) * conductance
assert f(20, 20) == 0 |
benchmark_functions_edited/f13888.py | def f(struct_str):
# assert s[0] == '('
left_paren_count = 0
for index, single_char in enumerate(struct_str):
if single_char == '(':
left_paren_count += 1
elif single_char == ')':
left_paren_count -= 1
if left_paren_count == 0:
return index
else:
pass
return None
assert f('()') == 1 |
benchmark_functions_edited/f5327.py | def f(letter):
letter_index = ord(letter) - 97
return letter_index
assert f('b') == 1 |
benchmark_functions_edited/f4095.py | def f(v1, v2):
return sum(vv1 * vv2 for vv1, vv2 in zip(v1, v2))
assert f( (0, 2), (1, 1) ) == 2 |
benchmark_functions_edited/f8325.py | def f(valores_acumulados):
for val in valores_acumulados:
if val == 2:
return 1
return 0
assert f( [3,4,5] ) == 0 |
benchmark_functions_edited/f3088.py | def f(name):
index = name.find("_")
numRaid = int(name[:index])
#assert(numRaid > 0)
return numRaid
assert f("3_1") == 3 |
benchmark_functions_edited/f13523.py | def f(n, odd_term, even_term):
def helper(f, g, k):
if k == n:
return f(k)
# Swap even and odd, starting from 1 so order is clear
return f(k) + helper(g, f, k + 1)
return helper(odd_term, even_term, 1)
assert f(2, lambda x: 1, lambda x: x) == 3 |
benchmark_functions_edited/f2209.py | def f(in_: list):
out = in_[3] - in_[2]
return out
assert f(
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
) == 1 |
benchmark_functions_edited/f11922.py | def f(text):
if(text == ''):
text = '-1'
elif(text == 'today'):
text = '0'
elif(text == 'tomorrow'):
text = '1'
date = int(text) # Converts to int
return date
assert f(3) == 3 |
benchmark_functions_edited/f4297.py | def f(s, start=0):
i, end = 0, len(s)
while start+i < end and s[start+i].isspace():
i += 1
return i
assert f(' hello') == 3 |
benchmark_functions_edited/f8833.py | def f(incompleteObject, knownObject):
matchvalue = 0
for catkey, catval in incompleteObject.items():
if knownObject[catkey] == catval:
matchvalue += 1
return matchvalue
assert f(
{'eyeColor': 'brown', 'age': 2},
{'name': 'Peter', 'eyeColor': 'brown', 'age': 2, 'favoriteColor': 'blue'}
) == 2 |
benchmark_functions_edited/f3727.py | def f(n):
prod = 1
for i in range(1, n + 1):
prod *= i
return prod
assert f(1) == 1 |
benchmark_functions_edited/f7551.py | def f(rgb):
red = rgb[0]
green = rgb[1]
blue = rgb[2]
RGBint = (red << 16) + (green << 8) + blue
return RGBint
assert f( (0, 0, 0) ) == 0 |
benchmark_functions_edited/f7097.py | def f(refr, new):
new = set(new.split(' '))
refr = [set(x.split(' ')) for x in refr if x!=new]
refr = [len(x&new) for x in refr]
return max(refr)
assert f(
"This is a test sentence",
"This is a test sentence"
) == 1 |
benchmark_functions_edited/f8417.py | def f(cache, f, arg):
res = cache.get(arg)
if arg in cache:
return cache[arg]
else:
res = f(arg)
cache[arg] = res
return res
assert f(dict(), lambda x: x+1, 2) == 3 |
benchmark_functions_edited/f2461.py | def f(t, x):
return 1 / (1 + x**2)
assert f(1.0, 0) == 1 |
benchmark_functions_edited/f10809.py | def f(x) -> int:
x = int(x)
if x < 0:
raise ValueError("A positive integer is expected")
return x
assert f(0) == 0 |
benchmark_functions_edited/f12515.py | def f(morningSchedule:str) -> int:
morningScheduleMappingDict = {"B": 1, "B+SL": 2, "BC": 3, "BC+SL": 4, "SL": 5, "S": 6, "LL": 7}
return morningScheduleMappingDict[morningSchedule]
assert f("B") == 1 |
benchmark_functions_edited/f5915.py | def f(targetVal, valList):
diffs = [abs(x-targetVal) for x in valList]
return diffs.index(min(diffs))
assert f(100, [15, 20, 100, 8, 100]) == 2 |
benchmark_functions_edited/f6743.py | def f(string: str):
counter = 0
for i in string:
if ord(i) > 10000: # emoji is double width
counter += 1
counter += 1
return counter
assert f(u'🙃') == 2 |
benchmark_functions_edited/f4957.py | def f(slist):
values = [v / 60**(i) for (i,v) in enumerate(slist[1:])]
value = sum(values)
return -value if slist[0] == '-' else value
assert f( ('-',0,0,0,0,0) ) == 0 |
benchmark_functions_edited/f1651.py | def f(value: bool):
if value is True:
return 1
else:
return 0
assert f(True) == 1 |
benchmark_functions_edited/f1816.py | def f(x):
return x * (1.0 - x)
assert f(1) == 0 |
benchmark_functions_edited/f10483.py | def f(item1, item2):
try:
result = item1 / item2
return result
except Exception:
return "None"
assert f(1, 1) == 1 |
benchmark_functions_edited/f9594.py | def f(n, k):
if 0 <= k <= n:
n_tok = 1
k_tok = 1
for t in range(1, min(k, n - k) + 1):
n_tok *= n
k_tok *= t
n -= 1
return n_tok // k_tok
else:
return 0
assert f(0, 0) == 1 |
benchmark_functions_edited/f734.py | def f(x, x_mean, x_std):
return (x * x_std) + x_mean
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f13377.py | def f(Letter, Word, i):
LWord = len(Word)
if i >= LWord - 1: return 0
if Word[i].lower() == Letter.lower(): return 0
if i > 0:
if Word[i - 1].lower() == Letter.lower(): return -1
if i < LWord:
if Word[i + 1].lower() == Letter.lower(): return 1
return 0
assert f(u"x", u"HELLO", 0) == 0 |
benchmark_functions_edited/f7724.py | def f(values, q):
values = sorted(values)
size = len(values)
idx = int(round(size * q)) - 1
if idx == 0:
raise ValueError("Sample size too small: %s" % len(values))
return values[idx]
assert f(list(range(10)), 1.0) == 9 |
benchmark_functions_edited/f11536.py | def f(
image_size: int,
patch_size: int,
stride: int,
num_scales: int,
scale_factor: int,
) -> int:
largest_patch_size = int(patch_size * (scale_factor**(num_scales - 1)))
residual = image_size - largest_patch_size
return (residual // stride) + 1
assert f(100, 10, 10, 3, 2) == 7 |
benchmark_functions_edited/f2807.py | def f(lis):
return sum(x for x in lis if x % 10 != 3)
assert f([3, 3, 3]) == 0 |
benchmark_functions_edited/f7264.py | def f(t, D, V):
return D * t + V * (t ** 2)
assert f(1, 2, 3) == 5 |
benchmark_functions_edited/f8114.py | def f(cluster_num, i=0): # 3 closest is 4 so return 2; 6 closest is 9 so return 3; 11 closest is 16 so return 4, etc.
while i**2 < cluster_num:
i+=1;
return i
assert f(16) == 4 |
benchmark_functions_edited/f8521.py | def f(byte, k):
return 1 if byte & (0b1000_0000 >> k) else 0
assert f(0b0000_0000, 2) == 0 |
benchmark_functions_edited/f6412.py | def f(dictionary):
index = 0
while True:
if index in dictionary:
index += 1
else:
return index
assert f({0, 1, 2, 3, 4, 5, 6}) == 7 |
benchmark_functions_edited/f14459.py | def f(tripleo_environment_parameters):
total = 0
if 'CephAnsibleDisksConfig' in tripleo_environment_parameters:
disks_config = tripleo_environment_parameters['CephAnsibleDisksConfig']
for key in ['devices', 'lvm_volumes']:
if key in disks_config:
total = total + len(disks_config[key])
return total
assert f(
{'CephAnsibleDisksConfig': {'devices': [],
'lvm_volumes': [{'name': 'block0'}, {'name': 'block1'}]}}
) == 2 |
benchmark_functions_edited/f3786.py | def f(number):
digits = [int(digit) for digit in str(number)]
return sum(digits)
assert f(10000) == 1 |
benchmark_functions_edited/f943.py | def f(value, arg):
return round(value/arg *100)
assert f(0, 50) == 0 |
benchmark_functions_edited/f14341.py | def f(d, key, default=None):
stack = [iter(d.items())]
while stack:
for k, v in stack[-1]:
if isinstance(v, dict):
stack.append(iter(v.items()))
break
elif k == key:
return v
else:
stack.pop()
return default
assert f(dict(), "key", 1) == 1 |
benchmark_functions_edited/f8990.py | def f(ms, fs):
return ms * fs / 1000.0
assert f(0, 5000) == 0 |
benchmark_functions_edited/f8843.py | def f(a, b, c):
dis = (b **2) - (4 * a * c)
if dis < 0:
return "Error: No real solutions"
else:
s = (-b - (dis ** 0.5)) / (2 * a)
return s
assert f(1, 0, 0) == 0 |
benchmark_functions_edited/f8999.py | def f(thing):
if isinstance(thing, dict):
return frozenset([(f(k), f(v)) for k, v in thing.items()])
elif isinstance(thing, list):
return tuple([f(i) for i in thing])
return thing
assert f(1) == 1 |
benchmark_functions_edited/f11844.py | def f(in_size, ker_size, stride, pad):
return stride * (in_size - 1) + ker_size - 2 * pad
assert f(3, 3, 2, 1) == 5 |
benchmark_functions_edited/f11878.py | def f(idx):
return 1 + idx // 2
assert f(0) == 1 |
benchmark_functions_edited/f1840.py | def f(n):
return int(str(n).replace("-", "")) * -1 if "-" in n else int(n)
assert f("00001") == 1 |
benchmark_functions_edited/f3581.py | def f(prevsum, prevmean, mean, x):
newsum = prevsum + abs((x - prevmean) * (x - mean))
return newsum
assert f(1, 1, 2, 3) == 3 |
benchmark_functions_edited/f3376.py | def f(x, c):
ddf_x = 0
for i in range(2, len(c)):
ddf_x += pow(x, i - 2) * c[i] * i * (i - 1)
return ddf_x
assert f(0, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 0 |
benchmark_functions_edited/f9908.py | def f(n: int, size: int) -> int:
size *= 8
if n >> (size - 1): # Is the hi-bit set?
return n - (1 << size)
return n
assert f(1, 4) == 1 |
benchmark_functions_edited/f11005.py | def f(input_number):
try:
number_str = str(input_number)
_, decimalpart = number_str.split(".")
return len(decimalpart)
except Exception:
return 0
assert f(123.4) == 1 |
benchmark_functions_edited/f9332.py | def f(array: list) -> int:
pairs_from_array = list(zip(array[::2], array[1::2]))
count = 0
for i, j in pairs_from_array:
if (i - j == 1) or (i - j == -1):
count += 1
return count
assert f(range(10)) == 5 |
benchmark_functions_edited/f8270.py | def f(file1, file2):
count = 0
for i in range(min(len(file1), len(file2))):
if file1[i] != file2[i]:
count += 1
count = count + max(len(file1), len(file2)) - min(len(file1), len(file2))
return count
assert f(b"", b"") == 0 |
benchmark_functions_edited/f14553.py | def f(TOP, P, AM):
try:
TOP_sum = sum(TOP.values())
P_sum = sum(P.values())
return abs(AM) / (P_sum + TOP_sum)
except (ZeroDivisionError, TypeError, AttributeError):
return "None"
assert f(
{'positive': 0, 'negative': 0},
{'positive': 0, 'negative': 1},
2) == 2 |
benchmark_functions_edited/f12308.py | def f(seats):
sort_s = [False] * 2**10
for i in seats:
sort_s[i] = True
our_s = 0
for i, _ in enumerate(sort_s):
if not sort_s[i] and sort_s[i - 1] and sort_s[i + 1]:
our_s = i
break
return our_s
assert f([]) == 0 |
benchmark_functions_edited/f5074.py | def f(mjd_start, mjd_end):
return round((mjd_end - mjd_start) * 86400)
assert f(59981.597291, 59981.597291) == 0 |
benchmark_functions_edited/f1738.py | def f(a,b):
if(a < b):
return a
else:
return b
assert f(3,3) == 3 |
benchmark_functions_edited/f144.py | def f(x):
return x * (x > 0)
assert f(-2) == 0 |
benchmark_functions_edited/f26.py | def f(a, b):
a |= b
return a
assert f(2, 1) == 3 |
benchmark_functions_edited/f13634.py | def f(integer_value):
assert type(integer_value) == int and integer_value >= 0, "The given number must be an integer greater than or equal to zero."
# The bin built-in function converts the value to a binary string, but adds an '0b' prefix.
# Count the length of the string, but subtract 2 for the '0b' prefix.
return len(bin(integer_value)) - 2
assert f(9) == 4 |
benchmark_functions_edited/f3621.py | def f(a,b):
if a is None:
a = ''
if b is None:
b = ''
return (a > b) - (a < b)
assert f(None, None) == 0 |
benchmark_functions_edited/f10040.py | def f(mass: float, acceleration: float) -> float:
force = float()
try:
force = mass * acceleration
except Exception:
return -0.0
return force
assert f(1, 2) == 2 |
benchmark_functions_edited/f10614.py | def f(v):
if v[0] == 'subject':
return 0
elif v[0] == 'predicate':
return 1
elif v[0] == 'object':
return 2
elif v[0] == 'page':
return 3
return 4
assert f(
('subject', 'http://b.example/s2')) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.