file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f3189.py | def f(item, cls, default=None):
return default if item is None else cls(item)
assert f(0, int) == 0 |
benchmark_functions_edited/f9034.py | def f(dim, cycle):
if dim%2 != 0:
cycle += 1
return cycle
assert f(3, 0) == 1 |
benchmark_functions_edited/f12196.py | def f(bLst, base=10):
result = 0
for bi in bLst[:]:
result = result*base + int(bi)
return result
assert f( [1] ) == 1 |
benchmark_functions_edited/f4255.py | def f(integer):
string = str(integer)
summe = 0
for ziffer in string:
summe = summe + int(ziffer)
return summe
assert f(24) == 6 |
benchmark_functions_edited/f7476.py | def f(averageEnergySquared, averageEnergy, temperature):
k = 1
return (averageEnergySquared - (averageEnergy ** 2)) / (k * (temperature ** 2))
assert f(1, 1, 1) == 0 |
benchmark_functions_edited/f11116.py | def f(x, out=None):
if out is None or x is out:
return x
out[:] = x
return out
assert f(3) == 3 |
benchmark_functions_edited/f7531.py | def f(a, b):
return int(a > b) - int(a < b)
assert f(5, 1.3) == 1 |
benchmark_functions_edited/f13293.py | def f(value, class_or_type_or_tuple):
s = "%r must be %r, not %s."
if not isinstance(value, class_or_type_or_tuple):
raise TypeError(s % (value, class_or_type_or_tuple, type(value)))
return value
assert f(5, int) == 5 |
benchmark_functions_edited/f8518.py | def f(item):
try:
return sum(item.values())
except Exception:
return "None"
assert f({'a': 0, 'b': 0, 'c': 0, 'd': 0}) == 0 |
benchmark_functions_edited/f10210.py | def f(divs, maxlevel):
for info in divs:
if info['level'] > maxlevel:
maxlevel = info['level']
if info.get('subdivs', None):
maxlevel = f(info['subdivs'], maxlevel)
return maxlevel
assert f([ {'level': 1} ], 0) == 1 |
benchmark_functions_edited/f7369.py | def f(update, close, guess=1, max_updates=100):
k = 0
while not close(guess) and k < max_updates:
guess = update(guess)
k = k + 1
return guess
assert f(lambda x: 2 * x, lambda y: y == 1) == 1 |
benchmark_functions_edited/f4938.py | def f(mu_1, mu_n):
return 1 + (mu_1 / abs(mu_n))
assert f(2, 1) == 3 |
benchmark_functions_edited/f15.py | def f(lam, f, w):
return lam * f * w
assert f(1, 1, 2) == 2 |
benchmark_functions_edited/f12044.py | def f(y, x, dx, f):
k1 = dx * f(y, x)
k2 = dx * f(y + 0.5 * k1, x + 0.5 * dx)
k3 = dx * f(y + 0.5 * k2, x + 0.5 * dx)
k4 = dx * f(y + k3, x + dx)
return y + (k1 + 2 * k2 + 2 * k3 + k4) / 6.
assert f(0, 0, 2, lambda x, y: 0) == 0 |
benchmark_functions_edited/f3178.py | def f(x):
try:
return x.raw
except AttributeError:
return x
assert f(1) == 1 |
benchmark_functions_edited/f10931.py | def f(listA, listB):
dotProd = 0
for num in range(len(listA)):
prod = listA[num] * listB[num]
dotProd = dotProd + prod
return dotProd
assert f( [1, 2], [1, 2] ) == 5 |
benchmark_functions_edited/f9298.py | def f(n, max_num):
if n/10 < 1:
if n % 10 > max_num:
max_num = n % 10
return max_num
else:
if n % 10 > max_num:
max_num = n % 10
return f(n // 10, max_num)
assert f(1111, 0) == 1 |
benchmark_functions_edited/f7127.py | def f(methodcnt): # NOTE - INSTANTIATE WITH SPECIAL CASE
print ("waving")
# react_with_sound(confirmation_final)
return 0
assert f(2) == 0 |
benchmark_functions_edited/f8420.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/f6540.py | def f(fwi):
return 0.0272 * fwi ** 1.77
assert f(0) == 0 |
benchmark_functions_edited/f12891.py | def f(prediction, expectation):
# solve the indetermination but THIS IS STUPID ITS A DATASET ERROR
if len(expectation) == 0:
return 0
return sum([(1 if pmid in expectation else 0) for pmid in prediction])/len(expectation)
assert f(
[(1, 0.9), (2, 0.8), (3, 0.7), (4, 0.6)],
[]
) == 0 |
benchmark_functions_edited/f7658.py | def f(word1, word2, words):
if word1 in words and word2 in words:
return abs(words.index(word1) - words.index(word2))
return -1
assert f("c", "a", ["a", "b", "c", "d", "e"]) == 2 |
benchmark_functions_edited/f2040.py | def f(x, y):
return x + y + 1
assert f(1,1) == 3 |
benchmark_functions_edited/f8332.py | def f(number):
length = 0
shift = 1
while True:
length += 1
number -= (number & 0x7F)
if number == 0: break
number -= shift
number >>= 7
shift += 7
return length
assert f(7) == 1 |
benchmark_functions_edited/f5035.py | def f(item):
count = 0
if item:
for x in item:
if x["level"] == "ERROR":
count = count + 1
return count
assert f([{"level": "INFO", "message": "OK"}]) == 0 |
benchmark_functions_edited/f9362.py | def f(psvList):
return sum(1 for psv in psvList if not psv.is_parked())
assert f([]) == 0 |
benchmark_functions_edited/f2460.py | def f(x, d):
return (x + (d-1)) // d
assert f(4, 1) == 4 |
benchmark_functions_edited/f12890.py | def f(line: str) -> int:
num = 0
maxnum = 1
keychr = ""
if not line: return 0
else:
for chara in line:
if keychr != chara:
keychr = chara
num = 1
else:
num += 1
maxnum = max(num, maxnum)
return maxnum
assert f("abc") == 1 |
benchmark_functions_edited/f2181.py | def f(O1, O2, x1, x2):
return abs(x2/(x2-x1)*(O1-O2)/O2)
assert f(0, 1, 0, 2) == 1 |
benchmark_functions_edited/f8236.py | def f(x):
k = 9
while True:
if k % x == 0:
return(len(str(k)))
break
k = 10*k + 9
assert f(7) == 6 |
benchmark_functions_edited/f12931.py | def f(data):
if len(data) == 0:
return 0
expected = float(len(data)) / 256.
observed = [0] * 256
for b in data:
observed[b] += 1
chi_squared = 0
for o in observed:
chi_squared += (o - expected) ** 2 / expected
return chi_squared
assert f(b"") == 0 |
benchmark_functions_edited/f10744.py | def f(dur, hop_size=3072, win_len=4096) -> float:
return (dur - win_len) / hop_size + 1
assert f(3, 1, 2) == 2 |
benchmark_functions_edited/f8027.py | def f(fp, val, blocksize, start, end):
for i in range(start, end, blocksize):
fp.write(
val[i:min(i + blocksize, end)]
)
return end - start
assert f(None, 'abcdefghi', 2, 12, 12) == 0 |
benchmark_functions_edited/f6995.py | def f(n):
dec = 0
m = len(n) - 1
for char in n:
dec += int(char) * (3 ** m)
m -= 1
return dec
assert f('000') == 0 |
benchmark_functions_edited/f5927.py | def f(is_rev):
if 238 <= is_rev <= 244:
return 1
else:
return 0
assert f(16) == 0 |
benchmark_functions_edited/f6113.py | def f(v):
try:
if v is None or v == '':
return ''
return float(v)
except ValueError:
return v
assert f('1.00000') == 1 |
benchmark_functions_edited/f5204.py | def f(n):
if n<=0:
return 0
elif n==1:
return 1
else:
return n*f(n-1)
assert f(3) == 6 |
benchmark_functions_edited/f4490.py | def f(x, x0, w_px, w):
kx = (x - x0) * w / w_px
return kx - (kx + w / 2) // w
assert f(0, 0, 1, 1) == 0 |
benchmark_functions_edited/f7325.py | def f(reward_list):
accuracy = sum(reward_list)*100/float(len(reward_list))
print("Total Reward: %s, Accuracy: %s %%"%(sum(reward_list),accuracy))
return accuracy
assert f([0]) == 0 |
benchmark_functions_edited/f5367.py | def f(value):
if isinstance(value, str):
return value.encode('utf-8')
else:
return value
assert f(True) == 1 |
benchmark_functions_edited/f7291.py | def count_digits (val):
return sum(1 for c in val if c.isdigit())
assert f("2") == 1 |
benchmark_functions_edited/f124.py | def f(x, a, b):
return a*x + b
assert f(0, 2, 3) == 3 |
benchmark_functions_edited/f2147.py | def f(lst):
return max(range(len(lst)), key=lst.__getitem__)
assert f( [1] ) == 0 |
benchmark_functions_edited/f2022.py | def f(x, lam0, alpha=4.0):
return lam0 * ( 1.0 - x**alpha )
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f10556.py | def f(target, source):
N = len(source)
start = 0
end = N-1
while (end - start) != 1:
mid = start + (end - start)//2
if target <= source[mid]:
end = mid
else:
start = mid
return start
assert f("a", ["a", "b", "c"]) == 0 |
benchmark_functions_edited/f8806.py | def f(a,b):
_len=0
for i in a:
if b.count(i) > a.count(i):
return -1
if b.count(i)== a.count(i):
_len+=1
#print i,b.count(i)
if _len == len(b):
return 1
else:
return 0
assert f(b'abcdei', b'xyz') == 0 |
benchmark_functions_edited/f27.py | def f(n: int):
return len(str(n))
assert f(1000000) == 7 |
benchmark_functions_edited/f5746.py | def f(value):
return type(value)()
assert f(0) == 0 |
benchmark_functions_edited/f2715.py | def f(direction):
return (direction - 1) % 4
assert f(3) == 2 |
benchmark_functions_edited/f5344.py | def f(sentence):
for idx, line in enumerate(sentence):
if line.startswith("# text"):
return idx
return -1
assert f(["# text", "# text", "Not a match", "Another", "Not a match"]) == 0 |
benchmark_functions_edited/f1083.py | def f(es_hit):
return es_hit['vader_score']['compound']
assert f(
{'vader_score': {'compound': 0.0}, 'text': '2'}) == 0 |
benchmark_functions_edited/f11823.py | def f(cache, bits, generator):
if bits not in cache:
# populate with 2 numbers
cache[bits] = [generator(bits) for _ in range(2)]
# rotate, so each call will return a different number
a = cache[bits]
cache[bits] = a[1:] + a[:1]
return cache[bits][0]
assert f(dict(), 2, lambda n: 2**n + 5) == 9 |
benchmark_functions_edited/f8237.py | def f(faces, edges, verticies):
return verticies + edges - faces
assert f(0, 0, 1) == 1 |
benchmark_functions_edited/f5981.py | def f(headers, body):
id = headers.get('id', None)
if id is None:
id = body.get('id', None)
return id
assert f({'id': 1}, None) == 1 |
benchmark_functions_edited/f1776.py | def f(it):
x = 1
for i in it:
x *= i
return x
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f14300.py | def f(n):
if n == 0 or n == 1:
return 1
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
for i in range(2, n+1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]
assert f(1) == 1 |
benchmark_functions_edited/f3109.py | def f(x0,x1,period):
return min((x0 - x1) % period, (x1 - x0) % period)
assert f(2,1,2) == 1 |
benchmark_functions_edited/f796.py | def f(v, alfa=1):
return alfa*v if v<0 else v
assert f(1) == 1 |
benchmark_functions_edited/f9735.py | def f(bcd):
assert(0 <= bcd and bcd <= 255)
ones = bcd & 0b1111
tens = bcd >> 4
return 10*tens + ones
assert f(3) == 3 |
benchmark_functions_edited/f3845.py | def f(array):
import numpy as np
array=np.array(array)
result= np.f(array)
return result
assert f([3, 1, 2, 4, 5]) == 3 |
benchmark_functions_edited/f1560.py | def f(numbers):
return float(sum(numbers)) / float(len(numbers))
assert f([-10, 0, 10]) == 0 |
benchmark_functions_edited/f7704.py | def f(mers: list, consensus: str) -> int:
result = 0
for mer in mers:
for i in range(len(mer)):
if mer[i] != consensus[i]:
result += 1
return result
assert f(
["ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG",
"ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG",
"ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG",
"ACGGGGGGGGGGGGGGGGGGGGGGG", "ACGGGGGGGGGGGGGGGGGGGGGGG"],
"ACGGGGGGGGGGGGGGGGGGGGGGG") == 0 |
benchmark_functions_edited/f5555.py | def f(exception, f, *args, **kwargs):
try:
f(*args, **kwargs)
except exception:
return 1
return 0
assert f(ZeroDivisionError, lambda: 1/0) == 1 |
benchmark_functions_edited/f2437.py | def f(x):
if x >= 0:
y = x + 0.5
else:
y = x - 0.5
return int(y)
assert f(0.4) == 0 |
benchmark_functions_edited/f11454.py | def f(values, p):
return sorted(values)[int(p * len(values))]
assert f([2, 4, 6, 8], 0.25) == 4 |
benchmark_functions_edited/f11880.py | def f(delta):
if delta == (1, 1):
return 2
elif delta == (1, -1):
return 4
elif delta == (-1, -1):
return 6
elif delta == (-1, 1):
return 8
else:
error_template = "Unexpected delta value of: {0}"
raise ValueError(error_template.format(delta))
assert f( (-1, -1) ) == 6 |
benchmark_functions_edited/f12645.py | def f(x,step_size,function_system):
k1 = function_system(x)
k2 = function_system(x + step_size * k1 / 2)
k3 = function_system(x + step_size * k2 / 2)
k4 = function_system(x + step_size * k3)
x_new = x + (step_size / 6) * (k1 + 2 * k2 + 2 * k3 + k4)
return x_new
assert f(0, 1, lambda x: x) == 0 |
benchmark_functions_edited/f7329.py | def f(list_, func):
last_arg = None
for i, x in enumerate(list_):
if func(x):
last_arg = i
return last_arg
assert f([1, 2, 3], lambda x: x % 2 == 1) == 2 |
benchmark_functions_edited/f6619.py | def f(time_of_flight):
convert_to_cm = 58
cm = time_of_flight / convert_to_cm
return cm
assert f(0) == 0 |
benchmark_functions_edited/f12041.py | def f(v):
n = len(v)
sorted_v = sorted(v)
midpoint = n // 2
if n % 2 == 1:
# if odd, return the middle value
return sorted_v[midpoint]
else:
# if even, return the average of the middle values
lo = midpoint - 1
hi = midpoint
return (sorted_v[lo] + sorted_v[hi]) / 2
assert f( [1] ) == 1 |
benchmark_functions_edited/f8115.py | def f(number):
sumNum = 0
while number:
sumNum += number % 10 # Get last digit of the number.
number //= 10 # Remove the last digit of the number.
return sumNum
assert f(1000000) == 1 |
benchmark_functions_edited/f3263.py | def f(model, input):
output = model(input)
return output
assert f(lambda input: input, 4) == 4 |
benchmark_functions_edited/f3096.py | def f(val, src, dst):
return ((val - src[0]) / (src[1]-src[0])) * (dst[1]-dst[0]) + dst[0]
assert f(0, (0, 10), (1, 100)) == 1 |
benchmark_functions_edited/f10756.py | def f(combiner, seq):
result = seq[0]
for item in seq[1:]:
result = combiner(result, item)
return result
assert f(lambda x, y: x * y, [4]) == 4 |
benchmark_functions_edited/f9384.py | def f(curr, goal):
diff_from_goal = 0 # number of differences from goal
for i, c in enumerate(curr):
if i >= len(goal) or c != goal[i]:
diff_from_goal += 1
return diff_from_goal
assert f("a", "a") == 0 |
benchmark_functions_edited/f9232.py | def f(t_dict):
num = 0
for thr in t_dict:
if t_dict[thr].is_alive():
num += 1
return num
assert f(dict()) == 0 |
benchmark_functions_edited/f3833.py | def f(bitlist):
out = 0
for bit in bitlist:
out = (out << 1) | bit
return out
assert f([1, 0, 1]) == 5 |
benchmark_functions_edited/f6602.py | def f(x):
if x == 0:
return 1
else:
return 0
assert f(1) == 0 |
benchmark_functions_edited/f11952.py | def f(ls_object=[], find_str=""):
try:
return ls_object.index(find_str)
except ValueError:
return -1
assert f(
["apple", "banana", "cherry"],
"cherry"
) == 2 |
benchmark_functions_edited/f5314.py | def f(s):
s = s.lower()
counter=0
for x in s:
if(x in ['a','e','i','o','u']):
counter+=1
return counter
assert f(
"This is another unit test"
) == 8 |
benchmark_functions_edited/f10399.py | def f(seq, fn):
best = seq[0]; best_score = fn(best)
for x in seq:
x_score = fn(x)
if x_score < best_score:
best, best_score = x, x_score
return best
assert f([10, 1, 100, 10000], lambda x: x) == 1 |
benchmark_functions_edited/f10007.py | def f(val):
#print("WHAT?",val)
try:
return int(val)
except ValueError:
#print("DDDDDDDDDDD",val)
pass
try:
return float(val)
except ValueError:
return val
assert f(1.1) == 1 |
benchmark_functions_edited/f5767.py | def f(func, x, delta_x):
dividend = func(x + delta_x) - func(x)
deriv = dividend / delta_x
return deriv
assert f(lambda x: 3, 3, 1) == 0 |
benchmark_functions_edited/f7820.py | def f(val, default):
try:
val = int(val)
except (AttributeError, TypeError, ValueError):
val = default
if val < 1:
val = 1
return val
assert f(True, 1) == 1 |
benchmark_functions_edited/f11720.py | def f(total, x, y):
longest = max(len(x), len(y))
if not longest:
return 0
else:
return total/longest
assert f(0, '', '') == 0 |
benchmark_functions_edited/f11956.py | def f(upper_bound, lower_bound, q=3):
return (upper_bound - lower_bound) / q
assert f(0, 0) == 0 |
benchmark_functions_edited/f9849.py | def f(inputs): # DO NOT CHANGE THIS LINE
output = inputs
return output # DO NOT CHANGE THIS LINE
assert f(1) == 1 |
benchmark_functions_edited/f10065.py | def f(A):
n = len(A)
A.sort()
# Find First Max
missing_int = 1
for i in range(n):
if A[i] < 0:
pass
elif A[i] == missing_int:
missing_int = A[i] + 1
return missing_int
assert f([1, 2, 3, 4]) == 5 |
benchmark_functions_edited/f506.py | def np_bitwise_maj (x, y, z):
return (x & y) | (x & z) | (y & z)
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f12962.py | def f(n):
if n < 0:
n = -n
return f(n)
elif 0 < n < 10:
return n
else:
# get the number
number_1 = n - (n // 10) * 10
rest_num = (n - number_1) // 10
max_number = f(rest_num)
if number_1 > max_number:
return number_1
return max_number
assert f(-9453) == 9 |
benchmark_functions_edited/f12131.py | def f(iterable):
try:
return len(iterable)
except TypeError:
return sum(1 for item in iterable)
assert f(iter([])) == 0 |
benchmark_functions_edited/f12191.py | def f(info, val, lb, ub, min_val, max_val, goal, check):
if info == 'unk':
return 0
elif info in ['opt', 'uns']:
return 1
if min_val == max_val:
return ub
s = (ub - lb) * (val - min_val) / (max_val - min_val)
if check:
assert 0 <= round(s, 5) <= ub - lb
if goal == 'min':
return ub - s
else:
return lb + s
assert f('unk', 0, 1, 1, 0, 10,'min', False) == 0 |
benchmark_functions_edited/f4501.py | def f(x,y):
utrue = x**2 - y**2
return utrue
assert f(-0.5,-0.5) == 0 |
benchmark_functions_edited/f10963.py | def f(n):
if type(n) != int:
raise TypeError("Number must be Integer.")
if n > 0 :
return (n&-n)
assert f(42) == 2 |
benchmark_functions_edited/f1502.py | def f(x, n):
return x & ((2 ** n) - 1)
assert f(9, 3) == 1 |
benchmark_functions_edited/f3466.py | def f(value):
if value >= 0:
return 1
return 0
assert f(5) == 1 |
benchmark_functions_edited/f1665.py | def f(n):
if n == 0:
return 0
return n + f(n - 1)
assert f(1) == 1 |
benchmark_functions_edited/f5839.py | def f(popt, value=1):
a, b = popt
assert a > 0, f"a = {value}"
assert value > 0, f"value = {value}"
return (a / value) ** (1 / b)
assert f((1, 1), 1) == 1 |
benchmark_functions_edited/f3219.py | def f(a,b):
if (a % b == 0):
return b
else:
return f(b, a % b)
assert f(8,12) == 4 |
benchmark_functions_edited/f9842.py | def f(d):
max_cnt = -1e90
max_vid = None
for vid in d:
if d[vid]>max_cnt:
max_cnt = d[vid]
max_vid = vid
return max_vid
assert f( {1:100, 2:200, 3:300, 4:400, 5:500} ) == 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.