file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f13064.py | def f(values):
min_value = float('Inf')
min_index = 0
for i in range(len(values)):
if values[i] < min_value:
min_value = values[i]
min_index = i
return min_index
assert f([1, 2, 3]) == 0 |
benchmark_functions_edited/f3870.py | def f(number):
floored = number // 1
if number == floored:
return number
else:
return floored + 1
assert f(9) == 9 |
benchmark_functions_edited/f3154.py | def f(rgb1, rgb2):
return (rgb1[0]-rgb2[0])**2 + (rgb1[1]-rgb2[1])**2 + (rgb1[2]-rgb2[2])**2
assert f( (255, 0, 0), (255, 0, 0) ) == 0 |
benchmark_functions_edited/f3301.py | def f(val0, val1):
if val1 == 0:
return val0
return f(val1, val0 % val1)
assert f(5, 5) == 5 |
benchmark_functions_edited/f531.py | def f(arg):
num = int(arg)
return num-1
assert f(3) == 2 |
benchmark_functions_edited/f3974.py | def f(value):
if value:
return value
else:
return
assert f(1) == 1 |
benchmark_functions_edited/f12222.py | def f(bins, val):
for i in range(len(bins) - 1):
if bins[i] <= val <= bins[i + 1]: return i
return -1
assert f(list(range(10)), 0) == 0 |
benchmark_functions_edited/f13231.py | def f(n_samples_in, n_samples_out):
downsample = int(n_samples_in // n_samples_out)
if downsample < 1:
raise ValueError("Number of samples should always decrease")
if n_samples_in % n_samples_out != 0:
raise ValueError("Number of samples for two consecutive blocks "
... |
benchmark_functions_edited/f7943.py | def f(n=0):
return bin(n).count('1')
assert f(29) == 4 |
benchmark_functions_edited/f6514.py | def f(number):
try:
return int(number)
except (TypeError, ValueError) as e:
return {"zero": 0,
"one": 1,
"first": 0}.get(number, number)
assert f("zero") == 0 |
benchmark_functions_edited/f7769.py | def f(parsed):
if len(parsed) > 0:
return int(parsed[0])
else:
return None
assert f(list("0")) == 0 |
benchmark_functions_edited/f595.py | def f(z):
return z*(z > 0)
assert f(-3) == 0 |
benchmark_functions_edited/f349.py | def f(range, x, y):
return y * range + x
assert f(2, 1, 0) == 1 |
benchmark_functions_edited/f9256.py | def f(s):
names_part = ["habituation", "hab", "hab1", "hab2", "hab3", "hab4", "hab5"]
temp = s.split("/")
for name in temp:
for parts in names_part:
if parts in name:
return 1
return 0
assert f("ab") == 0 |
benchmark_functions_edited/f14192.py | def f(tup):
while True:
if not isinstance(tup, list):
return tup
if len(tup) != 1:
return tup
tup = tup[0]
assert f(1) == 1 |
benchmark_functions_edited/f14105.py | def f(x_value, c0, c1, c2, c3):
return 3 * c3 * x_value ** 2 + 2 * c2 + c1
assert f(100, 0, 0, 0, 0) == 0 |
benchmark_functions_edited/f2438.py | def f(vel_l, vel_r):
return (vel_l + vel_r) / 2
assert f(2, 2) == 2 |
benchmark_functions_edited/f14269.py | def f(numbers):
max_count = 1
mode_number = numbers[0]
for number in numbers:
count = 0
for temp in numbers:
if temp == number:
count += 1
if count > max_count:
max_count = count
mode_number = number
return mode_number
assert... |
benchmark_functions_edited/f5573.py | def f(score: int) -> int:
return score // 2 - 5
assert f(10) == 0 |
benchmark_functions_edited/f6201.py | def f(s):
p = 131
m = pow(10, 9) +7
tmp = 0
s = s [::-1] # invert the string
for i in range(len(s)):
tmp += ord(s[i]) * pow(p, i)
return int(tmp % m)
assert f(b"") == 0 |
benchmark_functions_edited/f9385.py | def f(x):
n = len(x)
return min(range(n), key=lambda i: x[i])
assert f(list(range(10))) == 0 |
benchmark_functions_edited/f5411.py | def f(bitList):
res = 0
for i, r in enumerate(bitList):
res |= (r & 0x1) << i
return res
assert f([0, 0]) == 0 |
benchmark_functions_edited/f11504.py | def f(data):
n, mean, M2 = 0, 0, 0
for x in data:
n = n + 1
delta = x - mean
mean = mean + delta/n
M2 = M2 + delta*(x-mean)
variance = M2/(n-1)
return variance
assert f([]) == 0 |
benchmark_functions_edited/f9087.py | def f(dom):
# not a string variable ?
if not isinstance(dom, list):
return dom
return (0, len(dom) - 1)
assert f(0) == 0 |
benchmark_functions_edited/f14455.py | def f(rotational_constant: float):
return 1 / (rotational_constant / 134.901)
assert f(134.901) == 1 |
benchmark_functions_edited/f2083.py | def f(x1, y1, x2, y2):
return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
assert f(0, 0, 0, 0) == 0 |
benchmark_functions_edited/f2689.py | def f(n):
return 1 + f(n & n - 1) if n else 0
assert f(31) == 5 |
benchmark_functions_edited/f5251.py | def f(mapping, path):
if ':' not in path:
return mapping[path]
else:
key, sub = path.split(':', 1)
return f(mapping[key], sub)
assert f(
{"a": {"b": {"c": 5}}},
"a:b:c",
) == 5 |
benchmark_functions_edited/f4314.py | def f(lower, value, upper):
return max(lower, min(value, upper))
assert f(2, -2, 4) == 2 |
benchmark_functions_edited/f12484.py | def f(seq, items):
found = None
for i, s in enumerate(seq):
if s not in items:
found = i
return found
assert f(range(3), {3, 2}) == 1 |
benchmark_functions_edited/f10751.py | def f(iterable):
it = iterable.__iter__()
try:
s = next(it)
count = 1
except StopIteration:
raise ValueError("empty average")
for value in it:
s = s + value
count += 1
return s/count
assert f([1, 2, 3]) == 2 |
benchmark_functions_edited/f13223.py | def f(S, start, stop):
if start >= stop: # zero elements in slice
return 0
elif start == stop - 1: # one element in slice
return S[start]
else: # two or more elements in slice
mid = (start + stop) // 2
return f(S, start, mid) + f(S, mid, stop)
assert f(range(10), 5, 5) ==... |
benchmark_functions_edited/f7522.py | def f(data: bytes) -> int:
return data.count(b'\n')
assert f(b'a\n\nb') == 2 |
benchmark_functions_edited/f3359.py | def f(x):
if x > 0:
return 1
elif x < 0:
return -1
else:
return 0
assert f(123) == 1 |
benchmark_functions_edited/f4258.py | def f(num1, num2):
return(num1 - num2)
assert f(10, 5) == 5 |
benchmark_functions_edited/f6655.py | def f(src, value, default):
if value in src:
return src[value]
else:
return default
assert f(dict(), 'a', 2) == 2 |
benchmark_functions_edited/f13735.py | def f(n):
try:
# Assume that abs will work, and try to run it.
return abs(n)
except TypeError:
# If it doesn't work, catch the exception, and try to apply map to it.
return list(map(abs, n))
assert f(0) == 0 |
benchmark_functions_edited/f13061.py | def f(x, f):
return f(x) if x else x
assert f(1, lambda x: x + 1) == 2 |
benchmark_functions_edited/f8978.py | def f(theta, r_in, r_out):
return (r_out ** 2 - r_in ** 2) / theta ** 2
assert f(1, 0, 1) == 1 |
benchmark_functions_edited/f7644.py | def f(idx, matrix_size):
if idx == 0:
return matrix_size - 1
else:
return idx - 1
assert f(0, 5) == 4 |
benchmark_functions_edited/f8658.py | def f(poly, x, prime):
accum = 0
for coeff in reversed(poly):
accum *= x
accum += coeff
accum %= prime
return accum
assert f((0, 1), 0, 1) == 0 |
benchmark_functions_edited/f5063.py | def f(x, y):
if x != 0:
return (x**2 + y**2) / abs(2 * x)
else:
return y**2
assert f(1, -1) == 1 |
benchmark_functions_edited/f4881.py | def f(ground, found):
ground = set(ground)
return len(ground.intersection(found))/float(len(found))
assert f(set(), set(['A'])) == 0 |
benchmark_functions_edited/f525.py | def f(mass):
return mass // 3 - 2
assert f(12) == 2 |
benchmark_functions_edited/f352.py | def f(direction):
return (direction + 1) % 4
assert f(f(f(f(0)))) == 0 |
benchmark_functions_edited/f501.py | def f(row, column):
return row * 8 + column
assert f(1, 0) == 8 |
benchmark_functions_edited/f5310.py | def f(n):
power_of_9 = 9**n
k = 1
while k*power_of_9 >= 10 ** k:
k += 1
return k
assert f(0) == 1 |
benchmark_functions_edited/f8945.py | def f(fp: float, tp: float) -> float:
try:
calc = fp / (fp + tp)
except ZeroDivisionError:
calc = 0
return calc
assert f(0, 0.4) == 0 |
benchmark_functions_edited/f11082.py | def f(mode, memory, ptr):
# position mode
if mode == 0:
return memory[ptr]
# immediate mode
elif mode == 1:
# immediate mode is not supported
raise Exception
else:
raise Exception
assert f(0, [0, 0, 0, 0], 0) == 0 |
benchmark_functions_edited/f10191.py | def f(n: int, m: int) -> int:
return m + ((n - (m % n)) % n)
assert f(2, 6) == 6 |
benchmark_functions_edited/f1261.py | def f(x,mu,ma):
if x!=0 and ((abs(x-ma)/mu)>1.4826):
return 1
else: return 0
assert f(1000,1,2) == 1 |
benchmark_functions_edited/f8962.py | def f(method, params):
prm = dict()
if params is not None:
for key, val in params.items():
prm[key] = eval(str(val))
return eval(method)(**prm)
assert f(
'lambda x, y=1: x + y',
{'x': 4}
) == 5 |
benchmark_functions_edited/f4054.py | def f(c):
try:
return int(c)
except ValueError:
return c
assert f(0) == 0 |
benchmark_functions_edited/f3511.py | def f(dA, cache):
# Because dg=1, codes below are disabled to speed up
dZ=dA
return dZ
assert f(0, [0, 0, 1, 0]) == 0 |
benchmark_functions_edited/f11887.py | def f(a, b, q):
assert a >= 0 and b >= 0 and q >= 1
result = 1
while b:
if b % 2 == 1:
result = (result * a) % q
a = (a * a) % q
b >>= 1
return result
assert f(2, 0, 1) == 1 |
benchmark_functions_edited/f6031.py | def f(list_) -> int:
if isinstance(list_, list) and len(list_) >= 1:
return 1 + max(f(item) for item in list_)
else:
return 0
assert f([1, 2, 3]) == 1 |
benchmark_functions_edited/f12410.py | def f(title):
tmp = ""
for l in title:
if l in [".", ",", " ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]:
tmp += l
else:
break
try:
return float(tmp)
except ValueError:
return 0
assert f(u"Foo") == 0 |
benchmark_functions_edited/f9140.py | def f(n, digit):
if n == 0:
return 0
else:
if n%10 == digit:
return f(n//10, digit) + 1
else:
return f(n//10, digit)
assert f(123, 2) == 1 |
benchmark_functions_edited/f11516.py | def f(base_minor, base_major, height):
base_minor = float(base_minor)
base_major = float(base_major)
height = float(height)
if (base_minor < 0.0 or base_major < 0.0 or height < 0.0):
raise ValueError('Negative numbers are not allowed')
return (base_minor + base_major) * height / 2.0
assert... |
benchmark_functions_edited/f12720.py | def f(line):
num_str = line.rstrip()
if len(num_str) <= 10:
numlist = list(num_str)
for x in range(len(numlist)): # pylint: disable=invalid-name
if int(numlist[x]) == numlist.count(str(x)):
continue
else:
return 0
return 1
ret... |
benchmark_functions_edited/f8053.py | def f(rt, membrane_geometry):
J = rt
if (membrane_geometry=='FMM' or membrane_geometry=='FMS'):
J = 1.
return J
assert f(1, 'MSS') == 1 |
benchmark_functions_edited/f3455.py | def f(a,b):
if len(a)!=len(b):
raise RuntimeError('Vector dimensions not equal')
return sum([a[i]*b[i] for i in range(len(a))])
assert f( [1, 1, 1], [1, 1, 1] ) == 3 |
benchmark_functions_edited/f2647.py | def f(iterable):
prod = 1
for item in iterable:
prod *= item
return prod
assert f((1,)) == 1 |
benchmark_functions_edited/f6868.py | def f(n, r):
# Base case.
if n == 0:
return 1
return pow(r, n) + f(n - 1, r)
assert f(5, 0) == 1 |
benchmark_functions_edited/f4016.py | def f(base1, base2, height):
return 1 / 2 * (base1 + base2) * height
assert f(-1, 1, 1) == 0 |
benchmark_functions_edited/f14162.py | def f(value):
if value == 0:
return 1
value = abs(value)
result = 0
while value > 0:
result += 1
value //= 10
return result
assert f(1024) == 4 |
benchmark_functions_edited/f3739.py | def f(IA, IB, IC):
Si = IB / (IA*IC)
return Si
assert f(1, 0, 1) == 0 |
benchmark_functions_edited/f13476.py | def f(bernoulli: int) -> int:
if bernoulli == 1:
return 1
elif bernoulli == 0:
return -1
else:
raise Exception(f'Unexpected value of Bernoulli distribution: {bernoulli}')
assert f(1) == 1 |
benchmark_functions_edited/f3409.py | def f(files):
tmax = [files[name].date for name in files]
if tmax:
return max(tmax)
else:
return 0
assert f(dict()) == 0 |
benchmark_functions_edited/f619.py | def f(x, a, b, c, d, e):
return a*x + b*x*x + c*x*x*x +d*x*x*x*x +e
assert f(0, 1, 2, 3, 4, 5) == 5 |
benchmark_functions_edited/f12569.py | def f(stat):
io_list = stat['blkio_stats']['io_service_bytes_recursive']
if len(io_list)>0:
total_dics = list(filter(lambda dic: dic['op'] == 'Total', io_list))
if len(total_dics)>0:
return total_dics[0]['value']
else:
return 0
assert f(
{'blkio_stats': {'io_service_... |
benchmark_functions_edited/f2729.py | def f(factors):
prod = 1
for f in factors:
prod *= f
return prod
assert f([]) == 1 |
benchmark_functions_edited/f13854.py | def f(n):
if n < 0 or not isinstance(n, int):
raise ValueError("%s is not a natural number. Only natural "
"numbers are allowed." % n)
a, b = 0, 1
while n != 0:
a, b = b, a+b
n -= 1
return int(a)
assert f(2) == 1 |
benchmark_functions_edited/f4404.py | def f(iterator):
return sum(1 for _ in iterator)
assert f(range(3)) == 3 |
benchmark_functions_edited/f7752.py | def f(config_blob: dict):
if "cfgpull" not in config_blob:
return 0
elif "version" not in config_blob["cfgpull"]:
return 0
return config_blob["cfgpull"]["version"]
assert f(
{
"cfgpull": {
},
"new_key": 1
}
) == 0 |
benchmark_functions_edited/f8315.py | def f( string ):
string = string.upper()
return string.count( 'A' ) + string.count( 'T' ) + string.count( 'C' ) + string.count( 'G' ) + string.count( 'N' ) + string.count( '-' )
assert f( 'AA' ) == 2 |
benchmark_functions_edited/f13175.py | def f(index, time_span, remainder):
# This needs -1 because the end hour is inclusive. For example, if the period
# represents [2, 26), the end hour is 25.
#
# Index is added 1 because, in our SQL, we subtract the remainder, divide,
# and floor. So, in order to get the original hour, we need to add 1 to the
... |
benchmark_functions_edited/f2548.py | def f(p_hPa):
if p_hPa is None:
return None
return p_hPa / 33.86389
assert f(0) == 0 |
benchmark_functions_edited/f3392.py | def f(val, min, max):
if val <= min:
return min
elif val >= max:
return max
return val
assert f(-10, 1, 3) == 1 |
benchmark_functions_edited/f9678.py | def f(passwords):
valid = 0
for (pos_a, pos_b, key_letter, password) in passwords:
if (password[pos_a - 1] == key_letter) ^ (password[pos_b - 1] == key_letter):
valid += 1
return valid
assert f([]) == 0 |
benchmark_functions_edited/f3717.py | def f(age):
age = 0
return age
assert f(17) == 0 |
benchmark_functions_edited/f13611.py | def f(converging, branches, args):
return converging(*[f(args) for f in branches])
assert f(sum, [lambda x: x], [2]) == 2 |
benchmark_functions_edited/f12186.py | def f(alignment, current_size, next_element_size):
if alignment == 1:
return 0 # Always aligned
elem_size = min(alignment, next_element_size)
remainder = current_size % elem_size
if remainder == 0:
return 0
return elem_size - remainder
assert f(1, 4, 2) == 0 |
benchmark_functions_edited/f13519.py | def f(iterable, condition=lambda x: True, default=None):
try:
return next(x for x in iterable if condition(x))
except StopIteration:
return default
assert f(range(5)) == 0 |
benchmark_functions_edited/f2258.py | def f(data, index):
return (data[index+1] << 8) + data[index]
assert f(b'\x00\x00', 0) == 0 |
benchmark_functions_edited/f8903.py | def f(global_step, start_step, end_step, start_val, end_val):
interp = (global_step - start_step) / (end_step - start_step)
interp = max(0.0, min(1.0, interp))
return start_val * (1.0 - interp) + end_val * interp
assert f(0, 0, 100, 0, 10) == 0 |
benchmark_functions_edited/f10733.py | def f(items, predicate):
for item in items:
if predicate(item):
return item
return None
assert f(range(10), lambda x: x % 10 == 5) == 5 |
benchmark_functions_edited/f13091.py | def f(lines: list, column_number: int) -> int:
cb = 0
for bits in lines:
if bits[column_number] == 0:
cb -= 1
elif bits[column_number] == 1:
cb += 1
return cb
assert f(
[
'00100',
'11110',
'10110',
'10111',
'10101',
... |
benchmark_functions_edited/f938.py | def f(p1, p2):
x1, y1 = p1
x2, y2 = p2
return abs(x1 - x2) + abs(y1 - y2)
assert f((0, 0), (1, 0)) == 1 |
benchmark_functions_edited/f3793.py | def f(item, list):
try:
return list.index(item)
except ValueError:
# x not in list
return -1
assert f(1, [2, 4, 1, 3, 1, 1, 5]) == 2 |
benchmark_functions_edited/f1273.py | def f(r, g, b):
return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3
assert f(1, 2, 3) == 0 |
benchmark_functions_edited/f2148.py | def f(val, tol):
return round((1.0 * val) / tol) * tol
assert f(1, 1) == 1 |
benchmark_functions_edited/f7877.py | def f(v):
if v>=64: return 7
if v>=32: return 6
if v>=16: return 5
if v>=8: return 4
if v>=4: return 3
if v>=2: return 2
if v>=1: return 1
return 0
assert f(19) == 5 |
benchmark_functions_edited/f7737.py | def f(n):
assert n >= 0
size = 1
while n >= 128:
size += 1
n >>= 7
return size
assert f(128) == 2 |
benchmark_functions_edited/f10199.py | def f(p1, p2):
if p1 and p2:
if None not in p1 and None not in p2:
d = ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5
return int(d)
return 100000
assert f((1, 1), (1, 2)) == 1 |
benchmark_functions_edited/f11633.py | def f(s, d):
return (s * (s - 1) / (2 * (d + 1)) + (s * (2 * s - 1) ** 2) /
(4 * (d + 1) ** 2) + (s ** 2 * d * (s - 1) ** 2) /
(4 * (d + 1) ** 4))
assert f(0, 0) == 0 |
benchmark_functions_edited/f6435.py | def f(k,n):
val = 1
fact = 1
for i in range(n):
val *= 3 * k + i
fact *= i + 1;
val /= fact
return int(val)
assert f(1, 2) == 6 |
benchmark_functions_edited/f11829.py | def f(p,xax):
xdiff=xax-p[0]
lfit=(p[2]*xdiff+p[1])*(xdiff < 0)
ufit=(p[3]*xdiff+p[1])*(xdiff >= 0)
return lfit+ufit
assert f([0, 0, 0, 0], 0) == 0 |
benchmark_functions_edited/f7345.py | def f(predicate):
import time
seconds = 0
while not predicate():
print('Waiting...')
time.sleep(1.0)
seconds += 1
print('Done!')
return seconds
assert f(lambda: 'foo'!= 'bar') == 0 |
benchmark_functions_edited/f11977.py | def f(num):
if num == "Sunday":
return 0
elif num == "Monday":
return 1
elif num == "Tuesday":
return 2
elif num == "Wednesday":
return 3
elif num == "Thursday":
return 4
elif num == "Friday":
return 5
elif num == "Saturday":
return 6
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.