file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f6291.py
|
def f(x, sep=None):
try:
return len(set(str(x).split(sep)))
except Exception as e:
print(f"Exception raised:\n{e}")
return 0
assert f("hello, world") == 2
|
benchmark_functions_edited/f10999.py
|
def f(message):
# Use Python's naive 32bit integer hashing for now. It's fast and simple.
return hash(message)
assert f(b"") == 0
|
benchmark_functions_edited/f1754.py
|
def f(equation: str) -> int:
code = compile(equation, "<string>", "eval")
return eval(code)
assert f(r"2 * 3") == 6
|
benchmark_functions_edited/f11409.py
|
def f(tab):
max_val = 0
n = 0
index = 0
for i in tab:
n+=1
if i > max_val:
max_val = i
index = n
return index
assert f([1]) == 1
|
benchmark_functions_edited/f13478.py
|
def f(message):
if message is None:
return None
if isinstance(message, int):
return message
try:
if message.SUBCLASS_OF_ID == 0x790009e3:
# hex(crc32(b'Message')) = 0x790009e3
return message.id
except AttributeError:
pass
raise TypeError('Invalid message type: {}'.format(type(message)))
assert f(0) == 0
|
benchmark_functions_edited/f3251.py
|
def f(k, p):
if k < 0:
assert p & 1
return pow((p + 1) >> 1, -k, p)
return pow(2, k, p)
assert f(-5, 3) == 2
|
benchmark_functions_edited/f774.py
|
def f(s, sub):
return len(s) - s[::-1].index(sub) - len(sub)
assert f( 'Hello, world!', 'll') == 2
|
benchmark_functions_edited/f9715.py
|
def f(x, limit):
try:
value = int(x)
if 1 <= value <= limit:
return value
else:
return None
except ValueError:
return None
assert f('2', 4) == 2
|
benchmark_functions_edited/f7196.py
|
def f(value: int) -> int:
if value > 0:
return max(1, round((value / 255) * 99))
return 0
assert f(-1) == 0
|
benchmark_functions_edited/f6620.py
|
def f(n):
#base case
if n == 0:
return 1
#recursive case
else:
fact = n * f(n-1)
return fact
assert f(1) == 1
|
benchmark_functions_edited/f2353.py
|
def f(x):
top = x & (7 << 5)
return top | top >> 3 | top >> 6
assert f(1) == 0
|
benchmark_functions_edited/f14532.py
|
def f(possible_value_, solution_):
for key, value in possible_value_.items():
if len(value) == 1:
solution_[key[0] - 1][key[1] - 1] = value[0]
possible_value_[key] = []
return 0
assert f(
{ (1,1): [5], (1,2): [2], (1,3): [2], (2,1): [3], (2,2): [4], (2,3): [3], (3,1): [3], (3,2): [2], (3,3): [5] },
[ [0,0,0], [0,0,0], [0,0,0] ] ) == 0
|
benchmark_functions_edited/f10097.py
|
def f(generation, reflection):
if generation != 0:
loss = (1.0 - reflection / generation)*100
else:
loss = (1.0 - reflection / (generation+0.1))*100
return loss if loss >=0 else 0
assert f(0, 3) == 0
|
benchmark_functions_edited/f12024.py
|
def f(instructions):
floor = 0
for step, instruction in enumerate(instructions):
if instruction == '(':
floor += 1
elif instruction == ')':
floor -= 1
if floor == -1:
return step + 1
raise RuntimeError('Failed to reach basement.')
assert f(list(')')) == 1
|
benchmark_functions_edited/f13986.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,0,1], 0, 0) == 0
|
benchmark_functions_edited/f12362.py
|
def f(ground_truth, predictions, match_labels):
max_confidence = 0.
matched_idx = -1
for i, pred in enumerate(predictions):
if match_labels(ground_truth, pred[1]) and max_confidence < pred[0]:
max_confidence = pred[0]
matched_idx = i
return matched_idx
assert f(1, [(0.5, 2), (0.5, 3), (0.5, 4), (0.5, 1)], lambda x, y: x == y) == 3
|
benchmark_functions_edited/f5581.py
|
def f(a_str, b_str):
if a_str.lower() < b_str.lower():
return -1
if a_str.lower() > b_str.lower():
return 1
return 0
assert f(
"File 1.txt", "file 1.txt"
) == 0
|
benchmark_functions_edited/f11701.py
|
def f(list_, sublist):
for i in reversed(range(len(list_) - len(sublist) + 1)):
if list_[i] == sublist[0] and list_[i:i + len(sublist)] == sublist:
return i
return None
assert f(list([1, 2, 3]), list([1, 2, 3])) == 0
|
benchmark_functions_edited/f907.py
|
def f(pressure, loading):
return loading * (1 - pressure)
assert f(1, 0) == 0
|
benchmark_functions_edited/f8067.py
|
def f(string: str) -> int:
return int("".join("1" if char in ("R", "B") else "0" for char in string), 2)
assert f(R"0000") == 0
|
benchmark_functions_edited/f11424.py
|
def f(p):
if p > 0:
x = p
else:
x = -p
y = 0
while x != 0:
n = x % 10
y = y * 10 + n
x = x // 10
if p > 0:
retu = y
else:
retu = -y
if retu > 2147483647 or retu < -2147483648:
return 0
else:
return retu
assert f(-2147483648) == 0
|
benchmark_functions_edited/f14092.py
|
def f(num1: int, num2: int) -> int:
for num in (num1, num2):
if not isinstance(num, int):
raise TypeError(f"{num} is not integer")
while num2:
num1, num2 = num2, num1 % num2
return num1
assert f(12, 20) == 4
|
benchmark_functions_edited/f11042.py
|
def f(poles, special_poles, var):
expression = 1
for p in poles:
if not p in special_poles:
expression *= (var - p)
return expression
assert f((), (), "x") == 1
|
benchmark_functions_edited/f12540.py
|
def f(string, sub_string):
# List Comprehension
return(sum([1 for i in range(0, len(string) - len(sub_string) + 1) if (string[i:(len(sub_string)+i)] == sub_string)]))
assert f("abcabc", "bc") == 2
|
benchmark_functions_edited/f10886.py
|
def f(step, warmup_steps, model_size,
rate, decay_steps, start_step=0):
return (
model_size ** (-0.5) *
min(step ** (-0.5), step * warmup_steps**(-1.5)) *
rate ** (max(step - start_step + decay_steps, 0) // decay_steps))
assert f(1, 1, 1, 1, 1) == 1
|
benchmark_functions_edited/f9777.py
|
def f(P1, P2):
if len(P1) != len(P2):
raise ValueError('Different dimension of given points.')
square_sum = 0
for i in range(len(P1)):
square_sum += (P1[i] - P2[i])**2
return square_sum**(1 / 2)
assert f([0, 0, 0, 0], [0, 0, 0, 0]) == 0
|
benchmark_functions_edited/f5693.py
|
def f(rho, phi):
return 252 * rho**10 \
- 630 * rho**8 \
+ 560 * rho**6 \
- 210 * rho**4 \
+ 30 * rho**2 \
- 1
assert f(1, 0) == 1
|
benchmark_functions_edited/f13546.py
|
def f(source, target=None):
if not source:
return 0
i, length = 0, len(source)
while i < length:
if source[i] not in ' \t':
if (target and source[i] == target) or target is None:
return i
return 0
i += 1
return 0
assert f(u'a \t\t') == 0
|
benchmark_functions_edited/f2570.py
|
def f(b, n):
if n == 0:
return 1
else:
return b * f(b, n-1)
assert f(2, 2) == 4
|
benchmark_functions_edited/f7733.py
|
def f(raw_item, record_level):
if not record_level:
return raw_item
record = raw_item
for x in record_level.split(","):
record = record[x.strip()]
return record
assert f({"x": {"y": 3}}, "x,y") == 3
|
benchmark_functions_edited/f9347.py
|
def f(v, threshold):
if v >= threshold:
return (v - threshold)
elif v <= - threshold:
return (v + threshold)
else:
return 0
assert f(0, 3) == 0
|
benchmark_functions_edited/f5404.py
|
def f(v: int, bits: int) -> int:
mask = 1 << (bits - 1)
count = 0
while (count < bits) and (v & mask) == 0:
count += 1
v = v * 2
return count
assert f(7, 4) == 1
|
benchmark_functions_edited/f11148.py
|
def f(phi, e):
d = 1
top1 = phi
top2 = phi
while e != 1:
k = top1 // e
oldTop1 = top1
oldTop2 = top2
top1 = e
top2 = d
e = oldTop1 - e * k
d = oldTop2 - d * k
if d < 0:
d = d % phi
return d
assert f(2, 3) == 1
|
benchmark_functions_edited/f10322.py
|
def f(n_features, n_components):
if n_components is None:
return n_features
if 0 < n_components <= n_features:
return n_components
raise ValueError('Invalid n_components, must be in [1, %d]' % n_features)
assert f(1, 1) == 1
|
benchmark_functions_edited/f5047.py
|
def f(n: int) -> int:
a = 0
b = 1
for i in range(n):
a, b = b, a + b
return a
assert f(-3) == 0
|
benchmark_functions_edited/f12684.py
|
def f(mass_1, mass_2):
return (mass_1 * mass_2) ** 0.6 / (mass_1 + mass_2) ** 0.2
assert f(0, 2) == 0
|
benchmark_functions_edited/f3356.py
|
def f(x, y, width):
return y * width + x
assert f(0, 0, 3) == 0
|
benchmark_functions_edited/f10800.py
|
def f(t, n):
# This is intended for tiles. As the lengths of x and y diverge, the
# resulting geometry will approach 2Nx0
f = 1
if len(t) > 1:
a = t[0]
b = t[1]
f = 2*n / (a + b) if (a + b) > 0 else 1
return f
assert f((), 0) == 1
|
benchmark_functions_edited/f6022.py
|
def f(base_dir_path):
if not base_dir_path.endswith('/'):
return len(base_dir_path) + 1
return len(base_dir_path)
assert f('/a/b/c/') == 7
|
benchmark_functions_edited/f13695.py
|
def f(number):
count = 0
lower_bound = 0
upper_bound = 100
while True:
count += 1
guess = lower_bound + (upper_bound - lower_bound) // 2
if guess == number:
return count
if guess > number:
upper_bound = guess
elif guess == lower_bound:
lower_bound += 1
else:
lower_bound = guess
assert f(13) == 6
|
benchmark_functions_edited/f3979.py
|
def f(now_step, total_step, final_value):
decay = (1 - final_value) / total_step
return max(final_value, 1 - decay * now_step)
assert f(0, 5, 1) == 1
|
benchmark_functions_edited/f5507.py
|
def f(heat_utilities, filter_savings=True):
return - sum([i.duty for i in heat_utilities if i.flow * i.duty < 0]) / 1e6
assert f([]) == 0
|
benchmark_functions_edited/f1303.py
|
def f(num: int) -> int:
if num % 2 != 0:
num += 1
return int(num)
assert f(0) == 0
|
benchmark_functions_edited/f7960.py
|
def f(string):
vowels = "aeiouy"
counter = 0
if string:
for ch in string.lower():
if ch in vowels:
counter += 1
return counter
assert f("aeiou") == 5
|
benchmark_functions_edited/f11212.py
|
def f(n, k):
if k < 0 or k > n:
return 0
if k == 0 or k == n:
return 1
k = min(k, n - k) # take advantage of symmetry
c = 1
for i in range(k):
c = c * (n - i) / (i + 1)
return c
assert f(-100, 10) == 0
|
benchmark_functions_edited/f8087.py
|
def f(number, base):
if number <= 1: return 0
k = 0
if base > 1:
while number % base == 0:
number /= base
k += 1
return k if number == 1 else None
assert f(16, 2) == 4
|
benchmark_functions_edited/f10160.py
|
def f(fname, line):
line = line.strip()
comment = '--' if fname.endswith('.lua') else '#'
if '[====[' in line or not line.startswith(comment):
print('Error: no leading comment in ' + fname)
return 1
return 0
assert f(
'file.lua',
' -- [====[') == 1
|
benchmark_functions_edited/f7736.py
|
def f(i_list: list) -> int:
max = i_list[0]
for element in i_list[1:]:
if element>max:
max=element
return max
assert f(range(4)) == 3
|
benchmark_functions_edited/f5775.py
|
def f(a, b):
return -(-a // b)
assert f(2, 3) == 1
|
benchmark_functions_edited/f10745.py
|
def f(pg, roof_slope, W):
pg_le_20psf_and_nonzero = (pg <= 20) & (pg > 0)
low_slope = roof_slope < (W/50)
return 5 * (pg_le_20psf_and_nonzero | low_slope)
assert f(0, 0, 0) == 0
|
benchmark_functions_edited/f5399.py
|
def f(text):
total_words = 0
for word in text.split("\n"):
if word.strip():
total_words += 1
return total_words
assert f("\n") == 0
|
benchmark_functions_edited/f5483.py
|
def f(n):
if n < 10:
return n
else:
total = 0
for i in str(n):
total += int(i)
return f(total)
assert f(12345) == 6
|
benchmark_functions_edited/f2043.py
|
def f(lst):
return sum(f(el) if isinstance(el, (list, tuple)) else 1 for el in lst)
assert f([1, 2]) == 2
|
benchmark_functions_edited/f6117.py
|
def f(tap_pos, step_voltage_increment, ndigits=4):
return round(tap_pos * step_voltage_increment / 100 + 1, ndigits)
assert f(0, 0.0001) == 1
|
benchmark_functions_edited/f712.py
|
def f(s):
return int(s, 36)
assert f('1') == 1
|
benchmark_functions_edited/f14047.py
|
def f(slope, intercept, power, cho_list):
# Calculate CHO consumption based on linear function
cho = slope * power + intercept
# scaled down from CHO per day to 1 hour
cho = cho/24
# Add the calculated value to list
cho_list.append(round(cho))
# Scale down to recording intervall of 1s
cho = cho/60/60
# Return the cho conspumtion per s
return cho
assert f(-1, 1, 1, []) == 0
|
benchmark_functions_edited/f10455.py
|
def f(x: int, i: int) -> int:
assert i >= 0 # Do not support negative indexes, ATM
return (x >> i) & 0x01
assert f(0b0101, 2) == 1
|
benchmark_functions_edited/f3686.py
|
def f(context, scope):
return context.get("progress", {}).get(scope)
assert f(
{"progress": {"a": 1, "b": 2, "c": 3}}, "c"
) == 3
|
benchmark_functions_edited/f7770.py
|
def f(c):
if c < 0:
return 0
elif c < 0.04045:
return c / 12.92
else:
return ((c + 0.055) / 1.055) ** 2.4
assert f(0) == 0
|
benchmark_functions_edited/f4848.py
|
def f(main_iv, main_iv_label):
if main_iv_label is None:
return main_iv
else:
return main_iv_label
assert f(2, 4) == 4
|
benchmark_functions_edited/f3971.py
|
def f(n, k):
a, b = 1, 1
for i in range(2, n):
a, b = b, b + a * k
return b
assert f(1, 2) == 1
|
benchmark_functions_edited/f4535.py
|
def f(strategy):
try:
return strategy.num_replicas_in_sync
except AttributeError:
return 1
assert f("foo") == 1
|
benchmark_functions_edited/f13853.py
|
def f(value: float, min_value: float, max_value: float) -> float:
return max(min_value, min(value, max_value))
assert f(1, 0, 2) == 1
|
benchmark_functions_edited/f2187.py
|
def f(a, b):
c = float(a) / float(b)
if c == int(c):
return int(c)
return int(c) + 1
assert f(10, 3) == 4
|
benchmark_functions_edited/f1060.py
|
def lenc (val=None):
global _lenc
if val is not None:
_lenc = val
return _lenc
assert f(3) == 3
|
benchmark_functions_edited/f10944.py
|
def f(n, memo):
if n == 1 or n == 2 or n == 3:
return memo[n]
else:
for i in range(4, n+1):
memo[i] = memo[i-1] + memo[i-2] + memo[i-3]
return memo[n]
assert f(2, {1: 1, 2: 2}) == 2
|
benchmark_functions_edited/f4102.py
|
def f(a, b, c, d):
result = (a + b) - (c + d)
return result
assert f(0, 0, 0, 0) == 0
|
benchmark_functions_edited/f1812.py
|
def f(n):
a = 0
b = 1
for _ in range(n):
a, b = b, a + b
return a
assert f(3) == 2
|
benchmark_functions_edited/f14144.py
|
def f(tb37v, tb37h, tiepts):
ow37v = tiepts[0]
ow37h = tiepts[3]
fy37v = tiepts[2]
fy37h = tiepts[5]
my37v = tiepts[1]
my37h = tiepts[4]
cf = ((tb37h - ow37h)*(my37v - ow37v) - (tb37v - ow37v)*(my37h - ow37h))/((fy37h - ow37h)*(my37v - ow37v) - (fy37v - ow37v)*(my37h - ow37h))
cm = ((tb37h - ow37h) - cf*(fy37h - ow37h))/(my37h - ow37h)
ct = cf + cm
return ct
assert f(1, 0, [1, 1, 2, 2, 1, 1]) == 2
|
benchmark_functions_edited/f557.py
|
def f(a, b):
return len([1 for w in b if w == a])
assert f('a', 'aa') == 2
|
benchmark_functions_edited/f7065.py
|
def f(high, low):
if low == high:
return 1
if high < low:
return 0
i = low + 1
ans = 1
while i <= high:
ans *= i
i += 1
return ans
assert f(3, 2) == 3
|
benchmark_functions_edited/f975.py
|
def f(x: int, y: int) -> int:
return (x + y - 1) // y
assert f(10, 4) == 3
|
benchmark_functions_edited/f14316.py
|
def f(base, growth_factor, attempts):
if base <= 0:
raise ValueError("The 'base' param must be greater than 0, "
"got: %s" % base)
time_to_sleep = base * (growth_factor ** (attempts - 1))
return time_to_sleep
assert f(1, 2, 1) == 1
|
benchmark_functions_edited/f5834.py
|
def f(neg_th):
return neg_th / (1 - neg_th)
assert f(0) == 0
|
benchmark_functions_edited/f8127.py
|
def f(bitstring):
return int(bitstring, 2)
assert f('01') == 1
|
benchmark_functions_edited/f3272.py
|
def f(units):
return sum([i.purchase_cost for i in units]) / 1e6
assert f([]) == 0
|
benchmark_functions_edited/f1172.py
|
def f(diagonal_1, diagonal_2):
return diagonal_1 * diagonal_2 / 2
assert f(1, 2) == 1
|
benchmark_functions_edited/f8619.py
|
def f(dataset):
return max([len(line) for line in dataset])
assert f(
["I", "like", "a", "cat"]) == 4
|
benchmark_functions_edited/f1222.py
|
def f(raw_table, base_index):
val = raw_table[base_index]
return val & 0x007F
assert f(bytearray(b'\x00\x00\x00\x00\x00'), 4) == 0
|
benchmark_functions_edited/f2718.py
|
def f(t):
if t is None:
return 0
else:
return 1 + f(t.left) + f(t.right)
assert f(None) == 0
|
benchmark_functions_edited/f2745.py
|
def f(a, b):
while not (a%b == 0):
a += 1
return a
assert f(1, 5) == 5
|
benchmark_functions_edited/f389.py
|
def f(x):
return 1 if x > 0 else -1 if x < 0 else 0
assert f(-0.0) == 0
|
benchmark_functions_edited/f10966.py
|
def f(f, x):
if isinstance(x, list):
return f([f(f, y) for y in x])
if isinstance(x, tuple):
return f([f(f, y) for y in x])
if isinstance(x, dict):
return f([f(f, v) for (_, v) in x.items()])
return x
assert f(max, [[1, 3], [2, -1], [2, 3]]) == 3
|
benchmark_functions_edited/f891.py
|
def f(a, b, c=8):
return a * b - c
assert f(3, 4) == 4
|
benchmark_functions_edited/f8974.py
|
def f(a_para_list):
num_lt = [float(i) for i in a_para_list] # Arjun Mehta
min_val = min(num_lt)
return min_val
assert f([5, 6, 9, 2, 11]) == 2
|
benchmark_functions_edited/f8368.py
|
def f(clip):
frame = 0
if not clip:
return frame
# This raises if its not been set
try:
frame = clip.posterFrame()
except RuntimeError:
pass
return frame
assert f(None) == 0
|
benchmark_functions_edited/f6870.py
|
def f(seq):
# Counter for the As
result = 0
for b in seq:
if b == "A":
result += 1
# Return the result
return result
assert f(
"AAAA"
) == 4
|
benchmark_functions_edited/f4252.py
|
def f(redirects, index_map, k):
k = redirects.get(k, k)
return index_map.setdefault(k, len(index_map))
assert f(
{'A': 'A'},
{},
'A') == 0
|
benchmark_functions_edited/f13826.py
|
def f(n, input_base):
return sum(c * input_base ** i for i, c in enumerate(n[::-1]))
assert f( (1,), 10 ) == 1
|
benchmark_functions_edited/f2630.py
|
def f(x):
return sorted(x, key=abs)[-1]
assert f([5, 2, 3]) == 5
|
benchmark_functions_edited/f9205.py
|
def f(n, lowest, highest):
skip = highest - lowest + 1
while n > highest or n < lowest:
if n > highest:
n -= skip
if n < lowest:
n += skip
return n
assert f(10, 1, 9) == 1
|
benchmark_functions_edited/f13806.py
|
def f(inputs):
num_increased = 0
for i in range(1, len(inputs) - 2):
# sum_prev = inputs[i-1] + inputs[i] + inputs[i+1]
# sum_curr = inputs[i] + inputs[i+1] + inputs[i+2]
# (sum_curr - sum_prev) = inputs[i+2] - inputs[i-1]
if inputs[i + 2] > inputs[i - 1]:
num_increased += 1
return num_increased
assert f([3, 3, 3]) == 0
|
benchmark_functions_edited/f12065.py
|
def f(V, E0, B0, B1, V0):
E = (E0
+ 9.0/8.0*B0*V0*((V0/V)**(2.0/3.0) - 1.0)**2
+ 9.0/16.0*B0*V0*(B1-4.)*((V0/V)**(2.0/3.0) - 1.0)**3)
return E
assert f(18, 0, 0, 0, 0) == 0
|
benchmark_functions_edited/f14482.py
|
def f(content, letter):
if (not isinstance(letter, str)) or len(letter) != 1:
raise ValueError('`letter` must be a single character string.')
return len([char for char in content if char == letter])
assert f(
"The rain in Spain",
"e"
) == 1
|
benchmark_functions_edited/f7653.py
|
def f(parser, arg):
if arg != "auto":
try:
arg = int(arg)
except parser.error:
parser.error('Value {0} is not an int or "auto"'.format(arg))
return arg
assert f(None, "1") == 1
|
benchmark_functions_edited/f12107.py
|
def f(sig_name, sigs, errors):
if sig_name not in [x['name'] for x in sigs]:
print('ERROR! sig named {} does not exist in sigs.yaml.'.format(sig_name))
errors += 1
return errors
assert f('sig-foo', [], 0) == 1
|
benchmark_functions_edited/f10601.py
|
def f(n: int) -> int:
res, i = n, 2
while i * i <= n:
if n % i == 0:
while n % i == 0:
n //= i
res -= res // i
i += 1
if n > 1:
res -= res // n
return res
assert f(12) == 4
|
benchmark_functions_edited/f10555.py
|
def f(m: int, n: int) -> int:
while n != 0:
m, n = n, m % n
return m
assert f(8, 16) == 8
|
benchmark_functions_edited/f11137.py
|
def f(event):
times = []
for m, v in event['geodata']['watchTimes'].items():
times += [int(m)] * v
return times[len(times) // 2]
assert f({'geodata': {'watchTimes': {'1': 1}}}) == 1
|
benchmark_functions_edited/f9084.py
|
def f(q, k, dx, U1):
Ug = q / k * 2 * dx + U1
return Ug
assert f(1, 1, 1, 1) == 3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.