file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f7443.py | def f(ch1, ch2, m, c):
af = m * ch2 + c
signal = ch1 - af
return signal
assert f(10, 5, 1, 1) == 4 |
benchmark_functions_edited/f5936.py | def f(limit):
sequence = [0, 1]
[sequence.append(sequence[i] + sequence[i - 1]) for i in range(1, limit)]
return sequence[-1]
assert f(6) == 8 |
benchmark_functions_edited/f13207.py | def f(s):
if not isinstance(s, slice): return len(s)
if s.start is None or s.stop is None:
return 0
if s.step is None:
return s.stop - s.start
else:
return len(range(s.start, s.stop, s.step))
assert f(slice(1, 10, 5)) == 2 |
benchmark_functions_edited/f9099.py | def f(num1: int, num2: int) -> int:
result = 1
while num2 > 0:
if num2 & 1:
result = result * num1
num1 = num1 ** 2
num2 >>= 1
return result
assert f(0, 3) == 0 |
benchmark_functions_edited/f8154.py | def f(tp,fp):
return tp / (tp+fp+1e-10)
assert f(0,1) == 0 |
benchmark_functions_edited/f12273.py | def f(dataList):
sum=0
for item in dataList:
sum=sum+float(item)
if len(dataList)>0:
mean=sum/float(len(dataList))
else:
mean=0
return mean
assert f( [1, 2, 3, 4, 5] ) == 3 |
benchmark_functions_edited/f7107.py | def f(*args):
res = sum(i if abs(i) != 1 else 0 for i in args)
return res if res != 0 else 1
assert f(0, 0, 0) == 1 |
benchmark_functions_edited/f5384.py | def f(n):
n -= 1
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
n += 1
return n
assert f(3) == 4 |
benchmark_functions_edited/f291.py | def f(x, y):
return (y - x) // abs(y - x)
assert f(1, 2) == 1 |
benchmark_functions_edited/f4144.py | def f(item, class_mapping):
for k in class_mapping:
if k in item:
return class_mapping[k]
assert f(
"class2",
{
"class1": 0,
"class2": 1,
"class3": 2
}
) == 1 |
benchmark_functions_edited/f6343.py | def f(number):
if number < 0:
raise ValueError('Factorial is defined only for non-negative numbers')
if number == 0:
return 1
return number * f(number - 1)
assert f(3) == 6 |
benchmark_functions_edited/f5268.py | def f(n):
if n == 0:
return 1
else:
return n * f(n-1)
if x <= 0:
return -x
else:
return x
assert f(1) == 1 |
benchmark_functions_edited/f5857.py | def f(x1, x2, y1, y2):
return (((x2 - x1) ** 2) + ((y2 - y1) ** 2)) ** 0.5
assert f(0, 0, 0, 1) == 1 |
benchmark_functions_edited/f8242.py | def f(possible_string):
if type(possible_string) is str:
return 1
else:
raise TypeError(f'string not passed - got type {type(possible_string)})')
assert f('this is a string') == 1 |
benchmark_functions_edited/f9937.py | def f(objName, objList):
for i in range(0, len(objList)):
if objList[i][0] == objName:
return objList[i][1]
assert f( 'torus', [['sphere', 0], ['torus', 2], ['plane', 1]] ) == 2 |
benchmark_functions_edited/f3259.py | def f(c1, c2):
if c1[-1] == c2[-1]:
return 2
else:
return -3
assert f('C', 'C') == 2 |
benchmark_functions_edited/f933.py | def f(Vdc,Vdc_ref,Ki_DC):
dxDC = Ki_DC*(Vdc_ref - Vdc)
return dxDC
assert f(0,0,0) == 0 |
benchmark_functions_edited/f5229.py | def f(freeboard, rho_sw, rho_i):
berg_H = freeboard * (rho_sw/(rho_sw-rho_i))
return berg_H
assert f(0, 1000, 917) == 0 |
benchmark_functions_edited/f13099.py | def f(sigma,N,typ = 1):
k=int(0)
for i in range(0,N):
k=k+(sigma[i]+typ)/(1+typ)*2**(N-i-1) # typ=1 --> [-1,1] typ=0 --> [0,1]
return int(k)
assert f(**{'sigma': [1,0,0], 'N': 3, 'typ': 0}) == 4 |
benchmark_functions_edited/f7392.py | def f(parameter):
value = {'RFC_IMPORT':1,
'RFC_CHANGING':2,
'RFC_TABLES':3,
'RFC_EXPORT':4}
return value[parameter['direction']]
assert f(
{
'direction': 'RFC_EXPORT'
}
) == 4 |
benchmark_functions_edited/f12560.py | def f(num1 : int,num2 : int) -> int:
divisor = num1 if num1 > num2 else num2
dividor = num1 if num1 != divisor else num2
remainder = divisor%dividor
times_in = divisor//dividor
while remainder != 0:
divisor = dividor
dividor = remainder
remainder = divisor%dividor
return dividor
assert f(15,10) == 5 |
benchmark_functions_edited/f6820.py | def f(x, in_min, in_max, out_min, out_max):
ret_val = (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
return ret_val
assert f(50, 0, 100, 0, 10) == 5 |
benchmark_functions_edited/f1662.py | def f(*X):
s = 0
for i in X:
s += i**i
return (s)
assert f(1, 2) == 5 |
benchmark_functions_edited/f248.py | def f(word: str):
print(f'Hello {word}!')
return 0
assert f('world') == 0 |
benchmark_functions_edited/f2483.py | def f(*args):
for arg in args:
if arg is not None:
return arg
assert f(None, None, None, None, 0, 0) == 0 |
benchmark_functions_edited/f2623.py | def f(fahrenheit):
celsius = (fahrenheit - 32.) * (5. / 9.)
return celsius
assert f(32) == 0 |
benchmark_functions_edited/f10480.py | def f(months_to_legal_maturity: int, outstanding_balance: float
) -> float:
return outstanding_balance if months_to_legal_maturity == 1 else 0
assert f(2, 1000) == 0 |
benchmark_functions_edited/f9714.py | def f(n_workers, len_iterable, factor=4):
chunksize, extra = divmod(len_iterable, n_workers * factor)
if extra:
chunksize += 1
return chunksize
assert f(4, 1) == 1 |
benchmark_functions_edited/f8880.py | def f(arr, target):
low = 0
high = len(arr)-1
while low <= high:
mid = (low+high)//2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
assert f( [1, 2, 3], 3 ) == 2 |
benchmark_functions_edited/f9475.py | def f(x, a):
print(x, a)
if x == a:
return 0
elif x < a:
print('x', x)
return x
else:
return f(x-a, a)
assert f(15, 15) == 0 |
benchmark_functions_edited/f9241.py | def f(direction, instruction_list):
if instruction_list[1] == 0:
direction -= 1
elif instruction_list[1] == 1:
direction += 1
else:
print("And I oop....robot_do_it (2)")
direction %= 4
return direction
assert f(0, [0, 1]) == 1 |
benchmark_functions_edited/f5477.py | def f(n):
if n > 100:
n = 100
elif n < -100:
n = -100
return n
assert f(1) == 1 |
benchmark_functions_edited/f6496.py | def f(sentence_pair):
return len(sentence_pair[1])
assert f(('', 'the')) == 3 |
benchmark_functions_edited/f7542.py | def f(rel_attr, target_rel):
# XXX: TESTME
rels = rel_attr.strip().split()
for rel in rels:
rel = rel.lower()
if rel == target_rel:
return 1
return 0
assert f(u'FOO BAR', u'bar') == 1 |
benchmark_functions_edited/f14010.py | def f(alt_pos, trans_queue, changes):
offset = 0
for struct_var in changes:
if struct_var[2] > alt_pos and struct_var[0] != "TRANS":
break
elif struct_var[0] == "DEL":
offset += struct_var[3]
for trans in trans_queue:
if trans[2] > alt_pos:
return offset
offset += len(trans[1])
return offset
assert f(0, [], [["DEL", 123, 123, 123]]) == 0 |
benchmark_functions_edited/f9968.py | def f(slope, x0, x):
return slope * x + x0
assert f(0, 0, -1) == 0 |
benchmark_functions_edited/f10843.py | def f(a, fromIdx):
n = len(a)
for i in range(fromIdx+1,n):
if a[i][fromIdx] != 0:
return i
return -1
assert f(
[[0, 0, 0, 0, 0],
[0, 0, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 0]], 1) == 2 |
benchmark_functions_edited/f3124.py | def f(x):
return int(x + 0.5)
assert f(0.000000000001) == 0 |
benchmark_functions_edited/f9113.py | def f(symbol):
h = 0
g = 0
for c in symbol:
h = (h << 4) + ord(c)
g = h & 0xf0000000
h ^= (g >> 24)
h &= ~g
return h & 0xffffffff
assert f(b'') == 0 |
benchmark_functions_edited/f11630.py | def f(float_str, default=0):
try:
return float(float_str)
except ValueError:
return default
assert f('abc') == 0 |
benchmark_functions_edited/f6920.py | def f(signup_days, book_score):
return (book_score / signup_days)
assert f(2, 10) == 5 |
benchmark_functions_edited/f10477.py | def f(clause, assignment):
satisfied_lits = [var in assignment and polarity == assignment[var] for (polarity, var) in clause]
return sum(satisfied_lits)
assert f({(True, 1), (True, 2), (False, 3)}, {}) == 0 |
benchmark_functions_edited/f13950.py | def f(base, angle):
# rotate the angle towards 0 by base
offset = angle - base
if offset <= -180:
# bring it back into the (-180, 180] range
return 360 + offset
if offset > 180:
return offset - 360
return offset
assert f(0, 0) == 0 |
benchmark_functions_edited/f6432.py | def f(a, b):
print("=" * 20)
print("a: ", a, "/ b: ", b)
try:
return a/b
except (ZeroDivisionError, TypeError):
print("Something went wrong!")
raise
assert f(8, 4) == 2 |
benchmark_functions_edited/f3215.py | def f(km):
if km is not None:
return km/1.609
else:
return None
assert f(0) == 0 |
benchmark_functions_edited/f9079.py | def f(x):
return x.bit_length() - 1
assert f(0b11111111) == 7 |
benchmark_functions_edited/f6164.py | def f(curr_x, x_init, x_end, y_init, y_end):
m = (y_end - y_init)/(x_end - x_init)
n = y_end - x_end * m
return m * curr_x + n
assert f(0, 0, 2, 1, 3) == 1 |
benchmark_functions_edited/f6297.py | def f(lrate, batch_size, arch):
f1 = (
(lrate - 0.2) ** 2
+ (batch_size - 4) ** 2
+ (0 if arch == "conv" else 10)
)
return f1
assert f(0.2, 4, "conv") == 0 |
benchmark_functions_edited/f6373.py | def f(n):
if n == 0:
return 1
num_digits = 0
while n > 0:
num_digits += 1
n /= 10
return num_digits
assert f(0) == 1 |
benchmark_functions_edited/f12445.py | def f(seq):
g = seq.count('G')
c = seq.count('C')
d = float(g + c)
if d == 0:
d = 1
return float(g - c)/1
assert f('ACGTGCGC') == 0 |
benchmark_functions_edited/f8636.py | def f(lines) -> int:
i = len(lines) - 1
count = 0
for line in lines[::-1]:
if "-" * 10 in line:
count += 1
if count == 2:
break
i -= 1
return max(i, 0)
assert f(
["# comment", "not a comment"]
) == 0 |
benchmark_functions_edited/f12868.py | def f(row, rarefy=0, count=False):
if count:
return sum(row > 0)
row_sum, R = sum(row), 0
for val in row:
prob_success = val / row_sum
prob_fail = 1 - prob_success
prob_detect = 1 - (prob_fail ** rarefy)
if val and rarefy <= 0:
R += 1
else:
R += prob_detect
return int(R + 0.5)
assert f(list()) == 0 |
benchmark_functions_edited/f9642.py | def f(ad_bits):
tab = [0, None, 5, 17, 82, 375, 1263, 5262, 17579, 72909, 305276]
return tab[ad_bits]
assert f(2) == 5 |
benchmark_functions_edited/f13889.py | def f(mapping, x):
mapping = sorted(mapping)
if len(mapping) == 1:
xa, ya = mapping[0]
if xa == x:
return ya
return x
for (xa, ya), (xb, yb) in zip(mapping[:-1], mapping[1:]):
if xa <= x <= xb:
return ya + float(x - xa) / (xb - xa) * (yb - ya)
return x
assert f((), 0) == 0 |
benchmark_functions_edited/f4801.py | def f(items, pivot):
return min(items, key=lambda x: abs(x - pivot))
assert f([2,4,5,7,9,10], 2.9) == 2 |
benchmark_functions_edited/f13276.py | def f(source, alpha):
dest = 0
# Handle the easy cases first:
if alpha == 0:
return dest
if alpha == 255:
return source
alpha_pct = alpha / 255.0
new_rgb = int(source * alpha_pct + dest * (1 - alpha_pct))
return new_rgb
assert f(0, 255) == 0 |
benchmark_functions_edited/f11663.py | def f(wind_speed):
if wind_speed < 0:
raise ValueError('wind speed cannot be negative')
if 0 <= wind_speed <= 12:
wind = 1
elif 13 <= wind_speed <= 25:
wind = 2
else:
wind = 0
return wind
assert f(13) == 2 |
benchmark_functions_edited/f4165.py | def f(list_values):
max_score = max(list_values)
return max_score
assert f([1, 2, 3, 2, 5, 1, 6, 9, 0, -1]) == 9 |
benchmark_functions_edited/f10398.py | def f(x):
if (x < 0):
return 0
else:
if (x > 0):
return 1
assert f(1.0) == 1 |
benchmark_functions_edited/f5416.py | def f(k):
return 2**k + (4**k - 2**k)//2 if k % 2 == 0 else 4**k // 2
assert f(1) == 2 |
benchmark_functions_edited/f3155.py | def f(ts):
try:
return ts // 1000000
except TypeError:
return 0
assert f(0) == 0 |
benchmark_functions_edited/f11601.py | def f(inst_ptr, program, direction):
count = direction
while count != 0:
inst_ptr += direction
char = program[inst_ptr]
if char == '[':
count += 1
elif char == ']':
count -= 1
else:
pass
return inst_ptr
assert f(1, "[[]]", -1) == 0 |
benchmark_functions_edited/f5530.py | def f(df, key, default=None):
try:
return df.pop(key)
except KeyError:
return default
assert f(dict(), 'a', 2) == 2 |
benchmark_functions_edited/f3589.py | def f(m, n):
if n > m:
m, n = n, m
r = m % n # get the remainder
if r == 0:
return n
return f(n, r)
assert f(3, 2) == 1 |
benchmark_functions_edited/f1077.py | def f(inp):
return (inp + 1) / 2
assert f(-1) == 0 |
benchmark_functions_edited/f2340.py | def f(interval):
return 2 ** (interval/12)
assert f(0) == 1 |
benchmark_functions_edited/f13762.py | def f(distance, length):
return -1 if distance < 0 else 1.0 - distance / length
assert f(5, 5) == 0 |
benchmark_functions_edited/f13732.py | def f(number: int) -> int:
sum_factorial = 0
from math import factorial
for i in range(1, number + 1):
sum_factorial += factorial(i)
return sum_factorial
assert f(1) == 1 |
benchmark_functions_edited/f3887.py | def f(sequence):
if isinstance(sequence, str):
sequence = int(sequence[2])
return sequence
assert f(0) == 0 |
benchmark_functions_edited/f1312.py | def f(x, y):
while y != 0:
t = x % y
x, y = y, t
return x
assert f(2,1) == 1 |
benchmark_functions_edited/f6085.py | def f(coll):
if hasattr(coll, "__len__"):
return len(coll)
n = 0
for _ in coll:
n += 1
return n
assert f(enumerate(range(5))) == 5 |
benchmark_functions_edited/f35.py | def f(args):
return args[0] + args[1] - 2.0
assert f( (1, 2) ) == 1 |
benchmark_functions_edited/f14418.py | def f(vform_choice, repeats, nqubits):
switcher = {
"two_local": lambda: nqubits * (repeats + 1),
}
nweights = switcher.get(vform_choice, lambda: None)()
if nweights is None:
raise TypeError("Specified variational form is not implemented!")
return nweights
assert f(
"two_local",
1,
2,
) == 4 |
benchmark_functions_edited/f11694.py | def f(log2_ratio, ref_copies):
ncopies = ref_copies * 2 ** log2_ratio
return ncopies
assert f(0, 2) == 2 |
benchmark_functions_edited/f13704.py | def f(n: int, r: int) -> int:
# If either n or r is 0, nPr = 1
if n == 0 or r == 0:
return 1
# Initializing varibales
nFac = 1
nrFac = 1
# A single for loop to compute both required values
for i in range(1, n+1):
nFac *= i
if i == (n-r):
nrFac = nFac
return nFac//nrFac
assert f(3, 4) == 6 |
benchmark_functions_edited/f3361.py | def f(value, alignment):
return ((value + alignment - 1) // alignment) * alignment
assert f(3, 4) == 4 |
benchmark_functions_edited/f14468.py | def f(drusize: int) -> int:
drszwi = drusize
if 0 <= drszwi <= 2:
return 0
elif drszwi == 3:
return 1
elif 4 <= drszwi <= 5:
return 2
elif drszwi == 8 or drszwi == 88:
return 88
else:
raise KeyError('drarwi: %s' % drszwi)
assert f(5) == 2 |
benchmark_functions_edited/f12520.py | def f(val):
if val is None or isinstance(val, int):
result = val
elif isinstance(val, str):
try:
result = int(val)
except (ValueError, TypeError):
result = False
else:
result = False
return result
assert f(1) == 1 |
benchmark_functions_edited/f2763.py | def f(shape):
s = 1
for dim in shape[1:]:
s *= dim
return s
assert f((1,)) == 1 |
benchmark_functions_edited/f2771.py | def f(l):
sum=0.0
for i in l:
sum=sum+i
return sum/float(len(l))
assert f([-1, 1]) == 0 |
benchmark_functions_edited/f9771.py | def f(A, n, B, m):
if n == -1 or m == -1:
return 0
elif A[n] == B[m]:
return f(A, n-1, B, m-1)+1 # decrease and conqure
else:
l1, l2 = f(A, n-1, B, m), f(A, n, B, m-1)
if l1 < l2:
return l2
return l1
assert f(b"ABCDE", -1, b"ABCE", -1) == 0 |
benchmark_functions_edited/f8639.py | def f(brix):
return (brix / (258.6 - ((brix / 258.2) * 227.1))) + 1
assert f(0) == 1 |
benchmark_functions_edited/f13898.py | def f(length: int):
if length <= 10:
xp = 0.1
elif 10 < length <= 200:
xp = ((length / 200) * 2.5) + 0.5
elif 200 < length <= 400:
xp = 2.5
elif 400 < length <= 600:
xp = 2
elif 600 < length <= 800:
xp = 1.5
elif 800 < length <= 1000:
xp = 1
else:
xp = 0
return xp
assert f(1300) == 0 |
benchmark_functions_edited/f13532.py | def f(area, max_weight, plot_metric = None):
plot_metric = plot_metric if plot_metric is not None else "precision"
min_thresh = max_weight/6
_text_size = {area > 0 and area < min_thresh: 8,
area >= min_thresh and area < 2*min_thresh: 10,
area >= 2*min_thresh: 14}.get(True, 0)
return _text_size
assert f(0.01, 10.0) == 8 |
benchmark_functions_edited/f6335.py | def f(n, k, p, s):
return (n - k + 2 * p)//s + 1
assert f(5, 3, 1, 2) == 3 |
benchmark_functions_edited/f11321.py | def f(context):
try:
return context['endless']
except KeyError:
raise Exception('Cannot find endless data in context.')
assert f({'endless':1}) == 1 |
benchmark_functions_edited/f4448.py | def f(a):
def x1(b):
def x4(c):
return b
return x4
x2 = x1(a)
x3 = x2(1)
return x3
assert f(5) == 5 |
benchmark_functions_edited/f8170.py | def f(flux, lambda_microns):
#flux = u.Quantity(flux, u.erg*u.s**(-1)*u.cm**(-2)*(u.um))
#lambda_microns = u.Quantity(lambda_microns*(u.um))
dflux = flux*(lambda_microns**2)*1e26/3e14
return dflux
assert f(0, 1) == 0 |
benchmark_functions_edited/f3675.py | def f(position):
return sum([abs(x) for x in position])
assert f((1, 1)) == 2 |
benchmark_functions_edited/f6545.py | def f(results):
max_temp = -100000
for forecast in results:
max_temp = max(forecast['temp'], max_temp)
return max_temp
assert f([{'temp': 1}]) == 1 |
benchmark_functions_edited/f10180.py | def f(var, parameters):
if hasattr(parameters, "viewer_descr") and var in parameters.viewer_descr:
return parameters.viewer_descr[var]
return var
assert f(0, 1) == 0 |
benchmark_functions_edited/f12764.py | def f(edgelist):
node_dict = {}
node_count = 0
for edge in edgelist:
p, q = edge[ :2]
if p not in node_dict:
node_dict[p] = True
node_count += 1
if q not in node_dict:
node_dict[q] = True
node_count += 1
return node_count
assert f(
[
[1, 2, 4],
[1, 3, 3],
[1, 4, 1]
]
) == 4 |
benchmark_functions_edited/f13830.py | def f(dec_num):
bitstring = ""
try:
bitstring = dec_num[2:]
except:
bitstring = bin(int(dec_num))[2:] # cut off 0b
# print bin(int(dec_num)), bitstring
return bitstring.count("1")
assert f(10) == 2 |
benchmark_functions_edited/f2248.py | def f(work):
return sum([arr.size for arr in work.values()])
assert f(dict()) == 0 |
benchmark_functions_edited/f12856.py | def f(lab):
n = lab["nlines"]
m = lab["ncolumns"]
murs_max = n*(m-1) + m*(n-1)
non_murs = []
for k in lab.keys():
if type(k)==str:
continue
for connect in lab[k]:
if [connect,k] in non_murs:
continue
non_murs.append([k,connect])
return murs_max - len(non_murs)
assert f({ "nlines": 0, "ncolumns": 0, "walls": [] }) == 0 |
benchmark_functions_edited/f9374.py | def f(dbent1, dbent2):
tab1 = dbent1[1][0]
tab2 = dbent2[1][0]
if len(tab1) < len(tab2):
return -1
elif len(tab1) > len(tab2):
return 1
else:
return 0
assert f( ('1',[['1','1']]), ('1',[['1','1']]) ) == 0 |
benchmark_functions_edited/f9467.py | def f(n):
if n <= 2:
return 0
primes = [True] * (n)
primes[0] = primes[1] = False
for i in range(2, n):
if primes[i]:
for j in range(i*i, n, i):
primes[j] = False
return sum(primes)
assert f(10) == 4 |
benchmark_functions_edited/f1236.py | def f(n, b):
return ((n << b) | (n >> (32 - b))) & 0xffffffff
assert f(1, 1) == 2 |
benchmark_functions_edited/f3194.py | def f(iterable):
try:
return next(iter(iterable))
except StopIteration:
return None
assert f(iter([7, 11, 13])) == 7 |
benchmark_functions_edited/f9115.py | def f(m):
return (
m[0][0] * m[1][1] * m[2][2]
- m[0][0] * m[1][2] * m[2][1]
+ m[0][1] * m[1][2] * m[2][0]
- m[0][1] * m[1][0] * m[2][2]
+ m[0][2] * m[1][0] * m[2][1]
- m[0][2] * m[1][1] * m[2][0]
)
assert f(
[[1, 0, 0], [0, 0, 0], [0, 0, 1]]
) == 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.