file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f13849.py | def f(ip_port):
if isinstance(ip_port,bytes):
ip_port = int.from_bytes(ip_port,byteorder='big')
if 0 <= ip_port <= 1023:
return 1
elif 1024 <= ip_port <= 49151 :
return 2
elif 49152 <= ip_port <= 65535 :
return 3
else:
return 0
assert f(b'\xff\xff') == 3 |
benchmark_functions_edited/f9243.py | def f(n, p):
if n % p == 0:
raise ZeroDivisionError()
a = n, 1, 0
b = p, 0, 1
while b[0]:
q = a[0] // b[0]
a = a[0] - q*b[0], a[1] - q*b[1], a[2] - q*b[2]
b, a = a, b
assert abs(a[0]) == 1
return a[1]*a[0]
assert f(3, 5) == 2 |
benchmark_functions_edited/f8902.py | def f(x_i, base, y, p):
if x_i % 3 == 2:
return (y*x_i) % p
elif x_i % 3 == 0:
return pow(x_i, 2, p)
elif x_i % 3 == 1:
return base*x_i % p
else:
print("[-] Something's wrong!")
return -1
assert f(0, 1, 2, 3) == 0 |
benchmark_functions_edited/f797.py | def f(x, y):
return x if x >= y else y
assert f(1, 1) == 1 |
benchmark_functions_edited/f4711.py | def f(x,y):
if x[1] > y[1]:
return -1
elif x[1] < y[1]:
return 1
else:
return 0
assert f( (1,1), (1,2) ) == 1 |
benchmark_functions_edited/f519.py | def f(v2D):
return (v2D[0]**2 + v2D[1]**2)**0.5
assert f( [0, 0] ) == 0 |
benchmark_functions_edited/f12037.py | def f(func):
while hasattr(func, "__wrapped__"):
func = func.__wrapped__
return func
assert f(1) == 1 |
benchmark_functions_edited/f13059.py | def f(funct, fmsg, default, *args, **kwds):
try:
return funct(*args, **kwds)
except Exception as e:
print('WARNING: %s: %s' % (fmsg, e))
return default
assert f(lambda: 1/0, 'oops', 2) == 2 |
benchmark_functions_edited/f12015.py | def f(ref_component: int) -> int:
if ref_component <= 0:
raise ValueError("Reference to a component must be positive.")
return ref_component
assert f(2) == 2 |
benchmark_functions_edited/f10613.py | def f(creatinine_level: float) -> int:
if creatinine_level >= 5.0:
return 4
if creatinine_level >= 3.5:
return 3
if creatinine_level >= 2.0:
return 2
if creatinine_level >= 1.2:
return 1
return 0
assert f(5.0) == 4 |
benchmark_functions_edited/f7880.py | def f(value, s):
value_str = bin(value)[2:].zfill(s)
if(value_str[0] == '0'):
return value
else:
value = value - 1
value = value ^ 2**s-1
return 0-value
assert f(2, 1) == 0 |
benchmark_functions_edited/f8316.py | def f(i, ell):
if i == ell:
return 1
else:
return 0
assert f(0, 3) == 0 |
benchmark_functions_edited/f13808.py | def f(string: str):
assert string.startswith("("), "string has to start with '('"
stack = []
for index, letter in enumerate(string):
if letter == "(":
stack.append(letter)
elif letter == ")":
stack.pop()
if not stack:
return index
raise SyntaxError(f"Transonic syntax error for string {string}")
assert f("()") == 1 |
benchmark_functions_edited/f6729.py | def f(num1, num2):
## @@: integer not required with negative num1...?
return num1**num2
assert f(1, 2) == 1 |
benchmark_functions_edited/f6021.py | def f(curr_iter, decay_iters):
for idx, decay_iter in enumerate(decay_iters):
if curr_iter < decay_iter:
return idx
return len(decay_iters)
assert f(5, [1, 2]) == 2 |
benchmark_functions_edited/f8140.py | def flipBit ( bitVal ):
flipBitVal = 1 - bitVal
return flipBitVal
assert f(0) == 1 |
benchmark_functions_edited/f10404.py | def f(key, length=10):
try:
return abs(hash(key)) % (10 ** length)
except TypeError:
return abs(hash(str(key))) % (10 ** length)
assert f(3.0) == 3 |
benchmark_functions_edited/f3047.py | def f(model, input):
output = model(input)
return output
assert f(lambda x: x + 1, 2) == 3 |
benchmark_functions_edited/f9371.py | def f(s):
toret = 0
if (s
and s.strip()):
s = s.strip()
try:
toret = int(s)
except ValueError:
toret = 0
return toret
assert f('0') == 0 |
benchmark_functions_edited/f14168.py | def f(spec: str) -> int:
if "-" in spec:
parts = spec.split("-")
return (int(parts[0]) * 64) + (int(parts[1]))
return int(spec)
assert f("2") == 2 |
benchmark_functions_edited/f2596.py | def f(cls_list):
for cls in cls_list:
print(cls.help())
return 0
assert f([]) == 0 |
benchmark_functions_edited/f11118.py | def f(parser, arg):
_VALID_SEVERITIES = {'info': 0, 'warning': 1, 'error': 2}
if arg.strip().lower() not in _VALID_SEVERITIES:
parser.error("Invalid severity. Options are error, warning, or info")
else:
return _VALID_SEVERITIES[arg.strip().lower()]
assert f(None, "Warning") == 1 |
benchmark_functions_edited/f7846.py | def f(*var_arr):
level = -1
for index, var in enumerate(var_arr):
if var is not None:
level = index + 1
return level
assert f(1, 2, 3) == 3 |
benchmark_functions_edited/f1287.py | def f(time_min):
ans = time_min * 60
return ans
assert f(0) == 0 |
benchmark_functions_edited/f325.py | def f(v, dfs_data):
return dfs_data['parent_lookup'][v]
assert f(1, {'parent_lookup': {0: None, 1: 0}}) == 0 |
benchmark_functions_edited/f4249.py | def f(number: int, n: int) -> int:
return number // 10 ** n % 10
assert f(123456, 8) == 0 |
benchmark_functions_edited/f1783.py | def f(stop, steps):
return int(round(stop // steps * steps))
assert f(3, 1) == 3 |
benchmark_functions_edited/f12775.py | def f(number: int) -> int:
result = 0
for n in range(1, number):
if n % 3 == 0 or n % 5 == 0:
result += n
return result
assert f(4) == 3 |
benchmark_functions_edited/f1904.py | def f(L):
L = set(L)
n = 0
while n in L:
n += 1
return n
assert f([1, 2, 3, 4, 5, 0]) == 6 |
benchmark_functions_edited/f6991.py | def f(str1, str2):
diffs = 0
for ch1, ch2 in zip(str1, str2):
if ch1 != ch2:
diffs += 1
#
#
return diffs
assert f('abc', 'abc') == 0 |
benchmark_functions_edited/f1138.py | def f(val, minval, maxval):
return max(min(maxval, val), minval)
assert f(3, 4, 4) == 4 |
benchmark_functions_edited/f2203.py | def f(atm):
vlnc_dct = {'H': 1, 'C': 4, 'N': 3, 'O': 2, 'S': 2, 'Cl': 1}
return vlnc_dct[atm]
assert f('O') == 2 |
benchmark_functions_edited/f5127.py | def f(a, b):
try:
return a / b
except ZeroDivisionError as e:
raise ValueError('Invalid inputs') from e
assert f(12, 3) == 4 |
benchmark_functions_edited/f12513.py | def f():
return 0
# m = alsaaudio.Mixer(get_mixer_name())
# return int(m.getvolume()[0])
assert f(*[], **{}) == 0 |
benchmark_functions_edited/f11942.py | def f(coord, a0, a1, a2, a3, a4, a5, a6, a7, a8):
x, y = coord
#return a*x**2 + b*x*y + c*y**2 + d
return a0*x**2*y**2 + a1*x**2*y + a2*x**2 \
+ a3*x*y**2 + a4*x*y + a5*x \
+ a6*y**2 + a7*y + a8
assert f((1, 2), 1, 0, 0, 0, 0, 0, 0, 0, 0) == 4 |
benchmark_functions_edited/f2327.py | def f(condition) -> int:
if condition():
return 1
return 0
assert f(lambda: 0 and 1) == 0 |
benchmark_functions_edited/f11293.py | def f(width, height):
total = width*height
scale_dict = {0.2: 6500000, 0.3: 4000000, 0.4: 2250000, 0.5: 1000000, 0.8: 500000, 1: 0}
for k, v in scale_dict.items():
if total > v:
return k
assert f(100, 500) == 1 |
benchmark_functions_edited/f8433.py | def f(source):
try:
with open(source, "r", encoding="utf-8") as f:
return len(f.readlines())
except IOError:
print("Lecture du fichier", source, "impossible.")
return 0
assert f("abc") == 0 |
benchmark_functions_edited/f50.py | def f(me: int):
return me*2+1
assert f(2) == 5 |
benchmark_functions_edited/f4269.py | def f(handler):
while hasattr(handler, "wrapped"):
handler = handler.wrapped
return handler
assert f(1) == 1 |
benchmark_functions_edited/f5510.py | def f(i_dim, k, padding=0, stride=1, dilation=1):
return int(1 + (i_dim + 2 * padding - dilation * (k - 1) - 1) / stride)
assert f(7, 1) == 7 |
benchmark_functions_edited/f13930.py | def f(p, p1, p2):
x = p1[0]
y = p1[1]
dx = p2[0] - x
dy = p2[1] - y
if dx != 0 or dy != 0:
t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy)
if t > 1:
x = p2[0]
y = p2[1]
elif t > 0:
x += dx * t
y += dy * t
dx = p[0] - x
dy = p[1] - y
return dx * dx + dy * dy
assert f([0, 0], [1, 0], [1, 1]) == 1 |
benchmark_functions_edited/f2840.py | def f(xy1, xy2):
return abs(xy1[0] - xy2[0]) + abs(xy1[1] - xy2[1])
assert f((-10, 0), (-5, 0)) == 5 |
benchmark_functions_edited/f10803.py | def f(p1, p2):
x1, y1 = p1
x2, y2 = p2
return abs(x1 - x2) + abs(y1 - y2)
assert f((0, 0), (3, 3)) == 6 |
benchmark_functions_edited/f8716.py | def f(x, y, coeffs=[1]*3, return_coeff=False):
a0 = (x*0+1)*coeffs[0]
a1 = x*coeffs[1]
a2 = y*coeffs[2]
if return_coeff:
return a0, a1, a2
else:
return a0+a1+a2
assert f(1, 1) == 3 |
benchmark_functions_edited/f3711.py | def f(v, count, bits):
mask = (1 << bits) - 1
count = count % bits
return (((v << count) & mask) | (v >> (bits - count)))
assert f(0, 10, 32) == 0 |
benchmark_functions_edited/f13576.py | def f(text, pattern):
n = 0
for i in range(len(text)-len(pattern)+1):
if text[i:i+len(pattern)] == pattern:
n += 1
return n
assert f(
"GCGCG",
"GCG"
) == 2 |
benchmark_functions_edited/f912.py | def f(x, y):
if x >= y:
return x
else:
return y
assert f(2, 1) == 2 |
benchmark_functions_edited/f1352.py | def f(vals):
return max([abs(v) for v in vals])
assert f([-2, 3, -2]) == 3 |
benchmark_functions_edited/f5321.py | def f(indexes):
return sum(1 << i for i in indexes)
assert f((0,)) == 1 |
benchmark_functions_edited/f6018.py | def f(transcripts):
names = set()
for t in transcripts:
if t not in names:
names.add(t)
return len(names)
assert f( [] ) == 0 |
benchmark_functions_edited/f8683.py | def f(indexlst, array):
while indexlst:
array = array[indexlst[0]]
indexlst = indexlst[1:]
return array
assert f([2], [1, 2, 3]) == 3 |
benchmark_functions_edited/f14219.py | def f(value):
try:
value = int(value)
except ValueError:
error_template = ("convertCharToInt received '{0}' when num "
"expected")
raise ValueError(error_template.format(value))
if value > 9 or value < 0:
error_template = "Value larger or smaller than 1 digit: {0}"
raise ValueError(error_template.format(value))
return value
assert f(3) == 3 |
benchmark_functions_edited/f14218.py | def f(j,I,p):
# NOTES:
# Any ONE of the input arguments can be an array, but the others
# must be scalar.
# INPUTS:
# p -> Periodic payment amount
# I -> Interest, as annual rate. If 9%, enter 0.09.
# j -> The number of payments
# OUTPUT:
# PV -> The present value of the annuity
PV = p * ( ( 1 - (1+I)**(-j) )/I )
return PV
assert f(20,0.05,0) == 0 |
benchmark_functions_edited/f10711.py | def f(temp_fahr):
return (temp_fahr -32)/(1.8)
assert f(32) == 0 |
benchmark_functions_edited/f6771.py | def f(amount=1):
global VERBOSE
VERBOSE = amount
return VERBOSE
assert f(False) == 0 |
benchmark_functions_edited/f12618.py | def f(pad, in_siz, out_siz, stride, ksize):
if pad == 'SAME':
return (out_siz - 1) * stride + ksize - in_siz
elif pad == 'VALID':
return 0
else:
return pad
assert f(1, 10, 10, 1, 3) == 1 |
benchmark_functions_edited/f2889.py | def f(i, j):
return 1 if i == j else 0
assert f(3, 2) == 0 |
benchmark_functions_edited/f7753.py | def f(s):
if s.isnumeric():
return int(s)
else:
try:
fval = float(s)
return fval
except ValueError:
return s
assert f("1") == 1 |
benchmark_functions_edited/f12080.py | def f(s, base):
v = 0
p = len(s)-1
for i in range(p+1):
v += ord(s[i]) * (base ** p)
p -= 1
return v
assert f(u'', 16) == 0 |
benchmark_functions_edited/f1648.py | def f(f, seq):
for item in seq:
if f(item):
return item
assert f(lambda x: x > 2, [1, 1, 3, 4]) == 3 |
benchmark_functions_edited/f52.py | def f( argv ):
# Return success.
return 0
assert f( [] ) == 0 |
benchmark_functions_edited/f5863.py | def f(data):
data = [x[0].split() for x in data]
return sum([len(x) for x in data]) / float(len(data))
assert f([['']]) == 0 |
benchmark_functions_edited/f4302.py | def f(subject, name):
if hasattr(subject, "__ref__"):
return subject.__ref__(name)
else:
return subject
assert f(2, "foo.bar.baz") == 2 |
benchmark_functions_edited/f3385.py | def f(x, m, p):
return m * (1 - ((m - p) / m) ** x)
assert f(1, 3, 2) == 2 |
benchmark_functions_edited/f7530.py | def f(results):
result = results[0]
if isinstance(result, Exception):
raise result
return result
assert f([1]) == 1 |
benchmark_functions_edited/f5224.py | def f(n, start, end, value):
mask = ( 1 << end ) - ( 1 << start )
return (int(n) & ~mask) | (int(value) << start) & mask
assert f(0x00000000, 0, 1, 0) == 0 |
benchmark_functions_edited/f11041.py | def f(pos, L, move):
pos += move
if pos == L: # moved off right or bottom
return(0)
if pos == -1: # moved off top or left
return(L - 1)
return(pos)
assert f(1, 3, 2) == 0 |
benchmark_functions_edited/f8564.py | def f(field, attribute):
if tuple == type(field):
return f(f(field[0], field[1]), attribute)
return getattr(field, attribute)
assert f(1,'real') == 1 |
benchmark_functions_edited/f11492.py | def f(b, m):
return (b+1) / (m+1)
assert f(10000000, 10000000) == 1 |
benchmark_functions_edited/f6304.py | def f(x):
chrom = x
if x.startswith('chr'):
chrom = chrom.strip('chr')
try:
chrom = int(chrom)
except ValueError as e:
pass
return chrom
assert f('chr3') == 3 |
benchmark_functions_edited/f6278.py | def f(pattern: str, string: str) -> int:
n = len(string) - len(pattern) + 1
return sum(string[i:].startswith(pattern) for i in range(n))
assert f('abc', 'abcdef') == 1 |
benchmark_functions_edited/f10493.py | def f(axis, ndim):
if not isinstance(axis, int):
raise TypeError(f'axes should be integers, not {type(axis)}')
if not -ndim <= axis < ndim:
raise ValueError(f'axis {axis} is out of bounds for array of dimension {ndim}')
return axis % ndim
assert f(0, 3) == 0 |
benchmark_functions_edited/f11019.py | def f(dictionary: dict, n=0):
if n < 0:
n += len(dictionary)
for i, key in enumerate(dictionary.keys()):
if i == n:
return dictionary[key]
raise IndexError('ERROR: Index out of bounds in dictionary.')
assert f({1: 'a', 'b': 2}, 1) == 2 |
benchmark_functions_edited/f11458.py | def f(score_count):
if score_count < 7:
return 1
if score_count < 9:
return 2
if score_count < 11:
return 3
if score_count < 13:
return 4
if score_count < 15:
return 5
if score_count < 17:
return 6
if score_count < 19:
return 7
return 8
assert f(11) == 4 |
benchmark_functions_edited/f5380.py | def f(_coconut_f, *args, **kwargs):
return _coconut_f(*args, **kwargs)
assert f(sum, []) == 0 |
benchmark_functions_edited/f3339.py | def f(a,b):
c = [v for v in a if v in b]
return float(len(c))/(len(a)+len(b)-len(c))
assert f(set([1,2]),set([1,2])) == 1 |
benchmark_functions_edited/f9049.py | def f(text):
if text.strip():
val = int(text)
if val >= 0.:
return int(text)
else:
raise ValueError("Value should be positive.")
else:
return 0
assert f(' ') == 0 |
benchmark_functions_edited/f4137.py | def f(i, j, mul_matrix, max_j):
return mul_matrix[(i - 1) * max_j + j]
assert f(2, 2, [1, 2, 3, 4, 5, 6], 3) == 6 |
benchmark_functions_edited/f12341.py | def f(iter):
for item in iter:
return item
raise ValueError("iterable is empty")
assert f(range(1, 5)) == 1 |
benchmark_functions_edited/f13280.py | def f(board_list):
if not board_list:
return 0
board_counts = {}
for bs in board_list:
for bsl in bs.ScoreBoard():
hr = bsl.hr()
board_counts[hr.ns_pair_no()] = 1 + board_counts.get(hr.ns_pair_no(), 0)
board_counts[hr.ew_pair_no()] = 1 + board_counts.get(hr.ew_pair_no(), 0)
return max(board_counts.values())
assert f([]) == 0 |
benchmark_functions_edited/f4669.py | def f(a, b):
q, r = divmod(a, b)
return q + (2 * r + (q & 1) > b)
assert f(15, 5) == 3 |
benchmark_functions_edited/f1698.py | def f(values, mean):
return sum(map(lambda v: (v - mean)**2, values)) / len(values)
assert f([1, 2, 3, 4, 5], 3) == 2 |
benchmark_functions_edited/f12440.py | def f(num):
from math import floor
num_int = floor(num)
decimal = num - num_int
if num_int < 1:
return 1
else:
if decimal >= 0.85:
return num_int + 1
else:
return num_int
assert f(0.17) == 1 |
benchmark_functions_edited/f1913.py | def f(value, divisor):
return (value + divisor - 1) / divisor
assert f(10, 3) == 4 |
benchmark_functions_edited/f3949.py | def f(val):
return round(float(val))
assert f(2.8) == 3 |
benchmark_functions_edited/f3513.py | def f(s, *args):
return s.f(*args)
assert f(u'abc', u'') == 0 |
benchmark_functions_edited/f10518.py | def f(n, greater):
if n != 0:
if n % 10 > greater:
greater = n % 10
return f(n//10, greater)
return greater
assert f(281, 8) == 8 |
benchmark_functions_edited/f9306.py | def f(x, y):
return (x + y)
assert f(-2, 3) == 1 |
benchmark_functions_edited/f3843.py | def f(D_c, redshift):
return D_c/(1 + redshift)
assert f(0, 0) == 0 |
benchmark_functions_edited/f1150.py | def f(rot_type):
return 1 if rot_type >= 4 else 0
assert f(7) == 1 |
benchmark_functions_edited/f13585.py | def f(start, end) -> int:
sd, sh = start
ed, eh = end
hours = int(ed - sd) * 24 + (eh - sh) // 100 + 1
return hours
assert f(
(20180101, 1300),
(20180101, 1330),
) == 1 |
benchmark_functions_edited/f4735.py | def f(labels, preferred_nr: int) -> float:
return 1 - max(len(labels) / preferred_nr, preferred_nr / len(labels))
assert f(set([1, 2, 3]), 3) == 0 |
benchmark_functions_edited/f8465.py | def f(fn, *x):
if len(x) > 0 and isinstance(x[-1], (tuple, list)):
return f(fn, *(x[:-1] + tuple(x[-1])))
else:
return fn(*x)
assert f(lambda a, b: a + b, 1, 2) == 3 |
benchmark_functions_edited/f10898.py | def f(x, *coefs):
if len(coefs) == 0:
raise Exception(
"you've not provided any coefficients")
result = x * 0
for power, c in enumerate(coefs):
result += c * (x**(power + 1))
return result
print(args)
assert f(1, 1) == 1 |
benchmark_functions_edited/f10064.py | def f(a, b):
return max(0, min(a[1], b[1]) - max(a[0], b[0]))
assert f( (5, 10), (0, 10) ) == 5 |
benchmark_functions_edited/f1847.py | def f(list1):
length = len(list1)
mid = length//2
return mid
assert f({1,2,3,4,5}) == 2 |
benchmark_functions_edited/f11682.py | def f(n_electron, n_eigs=None):
if n_eigs is not None: return n_eigs
if n_electron > 2:
n_eigs = int(1.2 * ((0.5 * n_electron) + 5))
else:
n_eigs = n_electron
return n_eigs
assert f(1) == 1 |
benchmark_functions_edited/f3171.py | def f(list):
p = 1
for i in list:
p *= i
return p
assert f([0, 1]) == 0 |
benchmark_functions_edited/f4689.py | def f(day, data):
count = 0
for pid in data:
count = count + data[pid]["avail"][day]
return count
assert f(1, {}) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.