file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f12295.py | def f(chk, name, requires_chk):
if chk is None:
if name in requires_chk:
raise ValueError(f"must provide chk for '{name}'")
else:
chk = -1 # dummy value required for string substitution
return chk
assert f(0, "0", ["0"]) == 0 |
benchmark_functions_edited/f6972.py | def f(coord_ref, coord_list):
return len([coord for coord in coord_list if coord < coord_ref])
assert f(3, [5, 2, 1]) == 2 |
benchmark_functions_edited/f11192.py | def f(time, informationGain):
beta = 4
if informationGain < 1/beta:
informationGain = 1/beta
# return time/(beta*informationGain)
return 0
assert f(1, 0.5) == 0 |
benchmark_functions_edited/f13256.py | def f(condition, true_result, false_result):
if condition:
return true_result
else:
return false_result
assert f(3<2, 2, 3) == 3 |
benchmark_functions_edited/f11063.py | def f(idx):
return 1 + idx // 3
assert f(6) == 3 |
benchmark_functions_edited/f11530.py | def f(vector1, vector2):
dotp_res = sum(v1_i * v2_i for v1_i, v2_i in zip(vector1, vector2))
return dotp_res
assert f(
[3, 2, 1],
[1, 1, 1]
) == 6 |
benchmark_functions_edited/f6854.py | def f(n):
if n<=3:
return n-1
rest=n%3
if rest==0:
return 3**(n//3)
elif rest==1:
return 3**(n//3-1)*4
else:
return 3**(n//3)*2
assert f(5) == 6 |
benchmark_functions_edited/f1733.py | def f(Om, z):
return ((Om) * (1 + z)**3. + (1 - Om))**0.5
assert f(1, -1) == 0 |
benchmark_functions_edited/f2291.py | def f(X):
if isinstance(X[0], (list, dict)):
return 2
else:
return 1
assert f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 1 |
benchmark_functions_edited/f2332.py | def f(xs):
return xs[-1]
assert f([3]) == 3 |
benchmark_functions_edited/f6990.py | def f(a,b):
return a - int(a/b) * b
assert f(4.0, 1.0) == 0 |
benchmark_functions_edited/f5992.py | def f(n: int) -> int:
total = 0
while n:
n -= 1
total += n * n
return total
assert f(0) == 0 |
benchmark_functions_edited/f6332.py | def f(val, idx):
return (val >> idx) & 1
assert f(1, 0) == 1 |
benchmark_functions_edited/f1949.py | def f(data, duration):
return data * 8 / duration
assert f(1, 1) == 8 |
benchmark_functions_edited/f918.py | def f(value, byte):
return (value >> (8 * byte)) & 0xff
assert f(0x11, 4) == 0 |
benchmark_functions_edited/f11184.py | def f(data_str):
bcc = 0
for d in data_str:
# print d
# d = ord(d)
# bcc = bcc ^ ord(d)
bcc = bcc ^ ord(d)
# print bcc
bcc = bcc & 127
# print bcc
return bcc
assert f(bytes(0)) == 0 |
benchmark_functions_edited/f11648.py | def f(str_weekday):
weekdays = (
'mon',
'tue',
'wed',
'thu',
'fri',
'sat',
'sun'
)
return weekdays.index(str_weekday[:3].lower())
assert f('tuesday') == 1 |
benchmark_functions_edited/f1242.py | def f(a, b, p):
return a + (b - a) * p
assert f(1, 3, 0) == 1 |
benchmark_functions_edited/f8762.py | def f(function, list, initial):
for item in list:
initial = function(initial, item)
return initial
assert f(lambda acc, x: acc * x, [1, 2, 3], 1) == 6 |
benchmark_functions_edited/f12498.py | def f(level, maxval):
return int(level * maxval / 10)
assert f(5, 10) == 5 |
benchmark_functions_edited/f3456.py | def f(a, b):
if a % b:
return (a // b) + 1
return a // b
assert f(5, 3) == 2 |
benchmark_functions_edited/f2388.py | def f(value, min_val, max_val):
return max(min_val, min(value, max_val))
assert f(5, 0, 10) == 5 |
benchmark_functions_edited/f12593.py | def f(ph,pkalist,chargelist):
chargesum = []
for charge,pka in zip(chargelist, pkalist):
#print charge, pka
if charge == 1:
charge = 1/(1+10**(ph-pka))
chargesum.append(charge)
else:
charge = -1/(1+10**-(ph-pka))
chargesum.append(charge)
return sum(chargesum)
assert f(0, [0, 0], [1, -1]) == 0 |
benchmark_functions_edited/f2121.py | def f(i,n,fv,pmt):
pv = fv*(1/(1+i)**n) - pmt*((1-(1/(1+i)**n))/i)
return pv
assert f(0.1, 10, 0, 0) == 0 |
benchmark_functions_edited/f10700.py | def f(nums) -> int:
n = len(nums)
matrix = [0 for i in range(n)]
ans = matrix[0] = nums[0]
for j in range(1, n):
matrix[j] = max(matrix[j - 1] + nums[j], nums[j])
print(matrix)
return max(matrix)
assert f([2, 3, -8, -1, 2, 4, -2, 3]) == 7 |
benchmark_functions_edited/f3063.py | def f(n):
i = 0
j = 1
n = n - 1
while n >= 0:
i, j = j, i + j
n = n - 1
return i
assert f(0) == 0 |
benchmark_functions_edited/f4074.py | def f(params,x):
f = params[0] * (x ** 2) + params[1] * x + params[2]
return f
assert f( [1,2,3], 1) == 6 |
benchmark_functions_edited/f7154.py | def f(value, existing_values):
index = 1
new_value = value
while new_value in existing_values:
new_value = '{}-{}'.format(value, index)
index += 1
return new_value
assert f(4, []) == 4 |
benchmark_functions_edited/f8207.py | def f(no_data_value, dtype):
int_types = ['uint8', 'uint16', 'int16', 'uint32', 'int32']
if dtype in int_types:
return int(no_data_value)
else:
return float(no_data_value)
assert f('1', 'uint16') == 1 |
benchmark_functions_edited/f6298.py | def f(value):
try:
return value() if callable(value) else value
except Exception:
return _error_sentinel
assert f(lambda: 3) == 3 |
benchmark_functions_edited/f6392.py | def f(box):
if box < 4:
box += 1
return box
assert f(4) == 4 |
benchmark_functions_edited/f10735.py | def f(toboggan_map, step_x, step_y):
count = 0
posx = step_x
for line in toboggan_map[1:]:
if toboggan_map.index(line) % step_y == 0:
if line[posx % len(line)] == "#":
count += 1
posx += step_x
return count
assert f(
[
"..##.......",
"#...#...#..",
".#....#..#.",
"..#.#...#.#",
".#...##..#.",
"..#.##.....",
".#.#.#....#",
".#........#",
"#.##...#...",
"#...##....#",
".#..#...#.#",
], 3, 1) == 7 |
benchmark_functions_edited/f9001.py | def f(a, b):
for i, c in enumerate(a):
if i >= len(b):
return i # return if reached end of b
if b[i] != a[i]:
return i # we have come to the first diff
return len(a)
assert f(b"abcdef", b"abcdefg") == 6 |
benchmark_functions_edited/f12436.py | def f(s) -> int:
allowed_chars = "0123456789."
num = s.strip()
try:
temp = int(num)
return temp
except:
res = "".join([i for i in num if i in allowed_chars])
return int(float(res)) if res != "" else 0
assert f("1.0") == 1 |
benchmark_functions_edited/f1018.py | def f(first, second):
return sum([first, second])
assert f(-5, 10) == 5 |
benchmark_functions_edited/f1490.py | def f(a, b, c): # pylint: disable=invalid-name
return a + b + c
assert f(1, 2, 3) == 6 |
benchmark_functions_edited/f2301.py | def f(lst):
return sum(lst) / len(lst)
assert f([1]) == 1 |
benchmark_functions_edited/f763.py | def f(x,N):
if (x <= 0): x += N
if (x > N): x -= N
return x
assert f(13, 10) == 3 |
benchmark_functions_edited/f4688.py | def f(value, unused_context, args):
# @index starts from 1, so used 1-based indexing
return args[(value - 1) % len(args)]
assert f(1, None, [1, 2, 3]) == 1 |
benchmark_functions_edited/f667.py | def f(list):
return sum(list) / len(list)
assert f(range(5)) == 2 |
benchmark_functions_edited/f10077.py | def f(P, x):
try:
return P._coerce_(x)
except AttributeError:
return P(x)
assert f(int, 5) == 5 |
benchmark_functions_edited/f10026.py | def f(x, a, b):
return a+b*x
assert f(0, 0, 0) == 0 |
benchmark_functions_edited/f428.py | def f(value):
return int(value, 2)
assert f("1001") == 9 |
benchmark_functions_edited/f6309.py | def f(extent):
result = 1
for d in range(len(extent)): # list, tuple or 1D numpy array
result *= extent[d]
return result
assert f([1,2,3]) == 6 |
benchmark_functions_edited/f5675.py | def f(a,b):
if a == 0:
if b == 0:
return 'Vo so nghiem'
else:
return 'Vo nghiem'
else:
return -b/a
assert f(1, -1) == 1 |
benchmark_functions_edited/f7388.py | def f(poly, scale):
if type(poly) != list: return poly*scale
return list(f(p, scale) for p in poly)
assert f(1, 1) == 1 |
benchmark_functions_edited/f4340.py | def f(items, col):
return len(list(items))
assert f([None, None, None], 'col') == 3 |
benchmark_functions_edited/f1827.py | def f(string):
try: float(string)
except ValueError: return 0
else: return 1
assert f('1.0') == 1 |
benchmark_functions_edited/f13043.py | def f(phi, e):
s, t, sn, tn, r = 1, 0, 0, 1, 1
while r != 0:
q = phi // e
r = phi - q * e
st, tt = sn * (-q) + s, tn * (-q) + t
s, t = sn, tn
sn, tn = st, tt
phi = e
e = r
return t
assert f(11, 4) == 3 |
benchmark_functions_edited/f6066.py | def f(n, ranks):
for i in ranks:
if ranks.count(i) == n : return i
return None
assert f(1, [1, 2, 3, 4, 5]) == 1 |
benchmark_functions_edited/f8446.py | def f(a, b):
# GCD(a, b) = GCD(b, a mod b).
while b != 0:
# Calculate the remainder.
remainder = a % b
# Calculate GCD(b, remainder).
a = b
b = remainder
# GCD(a, 0) is a.
return a
assert f(3, 2) == 1 |
benchmark_functions_edited/f4830.py | def f(s1, s2):
sz = len(s2)
for i in range(sz):
if s1[i % len(s1)] != s2[i]:
return i
return sz
assert f(u"a", u"a") == 1 |
benchmark_functions_edited/f2046.py | def f(x: list) -> float:
mean_x = sum(x)/len(x)
return mean_x
assert f([2]) == 2 |
benchmark_functions_edited/f3407.py | def f(a, b, c):
diff1 = abs(a - b)
diff2 = abs(b - c)
diff3 = abs(a-c)
return min(diff1, diff2, diff3)
assert f(1, 10, 100) == 9 |
benchmark_functions_edited/f14453.py | def f(stride, padding, effective_padding_output):
return stride * effective_padding_output + padding
assert f(1, 1, 2) == 3 |
benchmark_functions_edited/f12280.py | def f(poly, value):
#return numpy.polyval(poly, value)
acc = 0
for c in poly:
acc = acc * value + c
return acc
assert f((0,0,0,0,0,0,0,0,0), 0) == 0 |
benchmark_functions_edited/f5893.py | def f(*args):
for item in args:
if item is not None:
return item
raise ValueError("No not-None values given.")
assert f(None, 2, None) == 2 |
benchmark_functions_edited/f2169.py | def f(win: int, draw: int, loss:int):
return (win * 3 + draw)
assert f(0,0,3) == 0 |
benchmark_functions_edited/f11690.py | def f(dictionary, key_id):
return dictionary.get(key_id)
assert f(
{'a': 1, 'b': 2},
'b'
) == 2 |
benchmark_functions_edited/f7849.py | def f(first_adapter, second_adapter):
difference = second_adapter - first_adapter
return difference if difference in [1, 2, 3] else None
assert f(0, 1) == 1 |
benchmark_functions_edited/f3720.py | def distLInf (a, b):
return max (abs (a[0] - b[0]), abs (a[1] - b[1]))
assert f( (2,3), (0,0) ) == 3 |
benchmark_functions_edited/f7461.py | def f(time: int) -> int:
return time if (time == 16) else time * 2
assert f(2) == 4 |
benchmark_functions_edited/f5203.py | def f(article: str, num_reducers: int) -> int:
return (sum([ord(s) for s in article]) + len(article)) % num_reducers
assert f(
'apple', 2) == 1 |
benchmark_functions_edited/f10625.py | def f(links: list, node_i: int) -> int:
deg_i = sum(1 if node_i == i else 0 for i, _ in links)
return deg_i
assert f(
[(0, 1), (1, 0), (1, 2), (2, 1)],
4
) == 0 |
benchmark_functions_edited/f4925.py | def f(c):
value = ord(c)
if value <= 0xffff:
return 1
elif value <= 0x10ffff:
return 2
raise ValueError('Invalid code point')
assert f(u'\f') == 1 |
benchmark_functions_edited/f685.py | def f(number):
return (number//2 + 1)
assert f(2) == 2 |
benchmark_functions_edited/f7316.py | def f(text):
max_line_length = 0
for line in text.splitlines():
if len(line) > max_line_length:
max_line_length = len(line)
return max_line_length
assert f(
"hello\nworld\nfoo\nbar\n"
) == 5 |
benchmark_functions_edited/f2913.py | def f(n):
a, b = 0, 1
if n > 1:
for i in range(n):
a, b = b, a + b
return a
return 1
assert f(1) == 1 |
benchmark_functions_edited/f12768.py | def f(f):
from numpy import int32, asanyarray
return asanyarray(f).astype(int32)
assert f(5.4) == 5 |
benchmark_functions_edited/f6966.py | def f(Pkpa):
Ppsig = Pkpa * 0.14503773800722
return Ppsig
assert f(0) == 0 |
benchmark_functions_edited/f22.py | def f(a, b):
return (a > b) - (a < b)
assert f(1, 0) == 1 |
benchmark_functions_edited/f7862.py | def f(data, key):
ret = 0
for c in data:
ret = (ret * key + ord(c)) & 0xffffffff
return ret
assert f(b"", 10) == 0 |
benchmark_functions_edited/f10904.py | def f(matches):
if matches[-1] != -1:
return 0
neg_len = -1
while matches[neg_len] == -1:
neg_len -= 1
return abs(neg_len+1)
assert f( [-1,-1,-1, 0]) == 0 |
benchmark_functions_edited/f6354.py | def f(object, attr, val):
rv = 0
try:
oval = getattr(object, attr)
if oval == val: rv = 1
except: pass
return rv
assert f(object(), 'attr', 1) == 0 |
benchmark_functions_edited/f13370.py | def f(name):
if name.find('terr') != -1:
# terrestrial
return 1
else:
# assume satellite
return 0
assert f("terr.001.nc") == 1 |
benchmark_functions_edited/f11391.py | def f(bytes, to, bsize=1024):
a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 }
r = float(bytes)
for i in range(a[to]):
r = r / bsize
return(r)
assert f(1024, 'k') == 1 |
benchmark_functions_edited/f8225.py | def f(n: int):
pow2 = (n & (n - 1) == 0)
if not pow2:
return "not a power of tow"
return n.bit_length() - 1
assert f(64) == 6 |
benchmark_functions_edited/f12786.py | def f(f, x, dh):
return (f(x + dh) - f(x)) / dh
assert f(lambda x: 2*x, 5, 1) == 2 |
benchmark_functions_edited/f6251.py | def f(x, low, high):
return (x + 1) * (high - low)/2 + low
assert f(1.0, -1, 1) == 1 |
benchmark_functions_edited/f2123.py | def f(value):
if value is None:
return None
else:
return int(value)
assert f(2.5) == 2 |
benchmark_functions_edited/f529.py | def f(pos_acc, neg_acc):
return float(pos_acc + neg_acc)/2
assert f(5, 5) == 5 |
benchmark_functions_edited/f9427.py | def f(x: float) -> float:
if x < 0: return 0 # Uniform radom is never less than 0
elif x < 1: return x # e.g. P(X <= 0.4) = 0.4
else: return 1 # uniform random is always less than 1
assert f(2) == 1 |
benchmark_functions_edited/f13813.py | def f(row : dict):
try:
if (
not row.get('Spam') and
not row.get('Category Promotions') and
not row.get('Trash') and
row['Inbox']
):
return 1
except Exception as e:
print(e)
print(row)
return 0
assert f(
{'Category Promotions': 0, 'Inbox': 1, 'Spam': 0, 'Trash': 0}
) == 1 |
benchmark_functions_edited/f6234.py | def f(line):
i = 0
while (i < len(line) and (line[i] == ' ' or line[i] == '\t')):
i += 1
return i
assert f( " \t\t" ) == 3 |
benchmark_functions_edited/f13366.py | def f(current_step, steps_per_epoch, steps_per_loop):
if steps_per_loop <= 0:
raise ValueError('steps_per_loop should be positive integer.')
if steps_per_loop == 1:
return steps_per_loop
remainder_in_epoch = current_step % steps_per_epoch
if remainder_in_epoch != 0:
return min(steps_per_epoch - remainder_in_epoch, steps_per_loop)
else:
return steps_per_loop
assert f(1, 2, 3) == 1 |
benchmark_functions_edited/f5538.py | def f(n):
try:
return int(n)
except Exception as e:
return False
assert f(1) == 1 |
benchmark_functions_edited/f48.py | def f(x, y):
return 2 * x - 2 * y
assert f(1, 0) == 2 |
benchmark_functions_edited/f11763.py | def f(x, range, drange):
(rx1, rx2) = float(range[0]), float(range[1])
(sx1, sx2) = float(drange[0]), float(drange[1])
return (sx2 - sx1) * (x - rx1) / (rx2 - rx1) + sx1
assert f(0, (0, 10), (0, 10)) == 0 |
benchmark_functions_edited/f9452.py | def f(base, exp, n):
bin_exp = bin(exp)[2:]
output = 1
for i in bin_exp:
output = (output ** 2) % n
if i == "1":
output = (output*base) % n
return output
assert f(2, 8, 3) == 1 |
benchmark_functions_edited/f3560.py | def f(value, tick_number):
return int(value / (24*60*60))
assert f(24*60*60, 1) == 1 |
benchmark_functions_edited/f9582.py | def f(pi_set):
if pi_set is not None:
return len(pi_set.splitlines()) + 1
else:
return 1
assert f('Pi_2\nPi_1\n') == 3 |
benchmark_functions_edited/f4200.py | def f(sum2, n, a, b):
return (0.5 * sum2 + b) / (n / 2.0 + a - 1.0)
assert f(0, 0, 0, 0) == 0 |
benchmark_functions_edited/f8799.py | def f(dict, key, default_value=''):
# Returns False if key doesnt exist, False if value is empty
if bool(dict.get(key)):
return dict.get(key)
else:
return default_value
assert f(
{'key': 1},
'key',
True
) == 1 |
benchmark_functions_edited/f8553.py | def f(q_phoc, w_phoc):
s = 0
qsq = 10**-8
psq = 10**-8
for q, p in zip(q_phoc, w_phoc):
s += q*p
qsq += q**2
psq += p**2
q_norm = qsq**(0.5)
p_norm = psq**(0.5)
dist = 1 - s / (q_norm * p_norm)
return dist
assert f(
[0, 0, 0, 0],
[0, 0, 0, 0]) == 1 |
benchmark_functions_edited/f12401.py | def f(iterable, default=None):
if not iterable:
return default
for item in iterable:
return item
assert f(range(10)) == 0 |
benchmark_functions_edited/f12669.py | def f(val):
if hasattr(val, "lower"):
# string-like object; force base to 0
return int(val, 0)
else:
# not a string; convert as a number (base cannot be specified)
return int(val)
assert f("0O0") == 0 |
benchmark_functions_edited/f309.py | def f(a):
return sum(a)/float(len(a))
assert f( [1, 1, 1, 1, 1, 1] ) == 1 |
benchmark_functions_edited/f9244.py | def f(points):
n = len(points) - 1
a = 0.0
for i in range(n):
a += (points[i] + points[i + 1]) / 2
return a / n
assert f(
[]) == 0 |
benchmark_functions_edited/f11068.py | def f(counts, prev_counts, buffer, threshold=None):
turns = 0
if not threshold:
threshold = buffer / 2
if prev_counts - counts >= threshold:
turns += 1
elif prev_counts - counts <= -1 * threshold:
turns -= 1
return turns
assert f(1, 1, 1) == 0 |
benchmark_functions_edited/f1930.py | def f(data, **kwargs):
return max(data) - min(data)
assert f(range(5)) == 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.