file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f9733.py
|
def f(value: str) -> int:
if isinstance(value, int):
return value
if isinstance(value, str):
if value.isdecimal():
return int(value)
return 0
assert f("13.37") == 0
|
benchmark_functions_edited/f7898.py
|
def f(k, lm):
n = len(lm)
assert k >= 1, k
assert k <= n, (k, n)
start = k - 1
assert start >= 0, start
r = lm[start]
for i in range(start, n):
r |= lm[i]
return r
assert f(1, [1, 0]) == 1
|
benchmark_functions_edited/f7152.py
|
def f(adjList):
size = len(adjList)
averageGrade = 0
for i in range(size):
averageGrade += len(adjList[i])
averageGrade /= size
return averageGrade
assert f(
[[]]
) == 0
|
benchmark_functions_edited/f7003.py
|
def f(charVar):
p = 1
sum = 0
downTo = len(charVar)-1
while downTo >= 0:
sum += p * int(charVar[downTo])
p *= 2
downTo -= 1
return sum
assert f(list("101")) == 5
|
benchmark_functions_edited/f3558.py
|
def f(i):
return sum(1 for e in i)
assert f([1, 2, 3]) == 3
|
benchmark_functions_edited/f4923.py
|
def f(n, lower, upper):
return max(lower, min(n, upper))
assert f(5, 2, 10) == 5
|
benchmark_functions_edited/f8184.py
|
def f(f, a, b, n):
sum = 0.0
h = (b - a) / float(n)
for counter in range(int(n)):
sum += (1 / 2.0) * h * (f(a + counter * h) + f (a + (counter + 1) * (h)))
return sum
assert f(lambda x: 1, 1, 2, 1) == 1
|
benchmark_functions_edited/f7311.py
|
def f(a):
eps = 0.0000001
old = 1
new = 1
while True:
old,new = new, (new + a/new) / 2.0
print([old, new])
if abs(new - old) < eps:
break
return new
assert f(9) == 3
|
benchmark_functions_edited/f4889.py
|
def f(var):
output = -1
try:
output = len(var)
except:
pass
return output
assert f("a") == 1
|
benchmark_functions_edited/f250.py
|
def f(x, AdB):
return x*10**(AdB/10)
assert f(4, 0) == 4
|
benchmark_functions_edited/f13593.py
|
def f(label1, label2):
try:
return pow(label1 - label2, 2)
# return pow(list(label1)[0]-list(label2)[0],2)
except:
print("non-numeric labels not supported with interval distance")
assert f(0, 0) == 0
|
benchmark_functions_edited/f8893.py
|
def f(x, sub=-1):
try:
return int(x)
except:
return sub
assert f(3) == 3
|
benchmark_functions_edited/f5332.py
|
def f(dict_: dict, dict_name: str):
if dict_name == "all":
return dict_
else:
return dict_[dict_name]
assert f(
{"a": 1, "b": 2},
"a",
) == 1
|
benchmark_functions_edited/f4139.py
|
def f(a, b):
(x1, y1) = a
(x2, y2) = b
return abs(x1 - x2) + abs(y1 - y2)
assert f(
(1, 1),
(1, 1),
) == 0
|
benchmark_functions_edited/f14289.py
|
def f( interpolation ) :
if( ( interpolation < 0 ) or ( interpolation > 5 ) or ( interpolation == 1 ) ) : raise Exception( "Invalid ENDL interpolation value = %d" % interpolation )
return( ( 0, None, 0, 1, 2, 3 )[interpolation] )
assert f( 4 ) == 2
|
benchmark_functions_edited/f743.py
|
def f(a:int,b:int)->int:
#x:int
#x:int
return a-b
assert f(True, True) == 0
|
benchmark_functions_edited/f4650.py
|
def f(val, digits):
try:
return round(float(val), digits)
except (ValueError, TypeError):
return float(0)
assert f("0.1", 0) == 0
|
benchmark_functions_edited/f14247.py
|
def f(files_string):
new_files_string = str(files_string)
if new_files_string == "nan":
return 0
return new_files_string.count(",") + 1
assert f(
"2010_Tracts_DP02_cleaned.csv,2010_Tracts_DP03_cleaned.csv,2010_Tracts_DP04_cleaned.csv"
) == 3
|
benchmark_functions_edited/f5552.py
|
def f(predictions, weight=None):
return sum([prediction["prediction"] * prediction[weight] for
prediction in predictions])
assert f([]) == 0
|
benchmark_functions_edited/f6568.py
|
def f(tpr, fpr, positive_prior):
return (positive_prior * tpr) / ((positive_prior * tpr) + ((1 - positive_prior) * fpr))
assert f(0.5, 0.5, 1) == 1
|
benchmark_functions_edited/f8646.py
|
def f(distance_image,distance_object,height_image):
neg_di = (-1) * distance_image
numerator = height_image * distance_object
return numerator / neg_di
assert f(1, 0, 2) == 0
|
benchmark_functions_edited/f2474.py
|
def f(n: float) -> int:
if n >= 0:
return 1
return 0
assert f(1.0) == 1
|
benchmark_functions_edited/f2210.py
|
def f(gamma,sigmax):
r = -1/sigmax
return 1/(1+gamma*r)
assert f(0, 1) == 1
|
benchmark_functions_edited/f9107.py
|
def f(q,mp):
return mp['p']*q
assert f(0, {'p': 0.05}) == 0
|
benchmark_functions_edited/f9307.py
|
def f(password, lower, upper, letter):
if password[lower] == letter and password[upper] != letter:
return 1
elif password[lower] != letter and password[upper] == letter:
return 1
else:
return 0
assert f(
"cdefg",
1,
3,
"c",
) == 0
|
benchmark_functions_edited/f7655.py
|
def f(x, shift):
b, q = 1 << shift, x >> shift
return q + (2 * (x & b - 1) + (q & 1) > b)
assert f(2, 20) == 0
|
benchmark_functions_edited/f14250.py
|
def f(n):
def recur_f(n, c):
print(n)
if n == 1:
return c
if n % 2 == 0:
n = n // 2
else:
n = n * 3 + 1
c += 1
return recur_f(n, c)
return recur_f(n,1)
assert f(1) == 1
|
benchmark_functions_edited/f4680.py
|
def f(root):
if root is None:
return 0
return max(f(root.left), f(root.right)) + 1
assert f(None) == 0
|
benchmark_functions_edited/f10841.py
|
def f(entry, key, none_value=0):
v = entry.get(key)
if not v:
return none_value
return v
assert f({'foo': 0}, 'foo') == 0
|
benchmark_functions_edited/f6885.py
|
def f(nums):
for i in range(len(nums)):
while i != nums[i]:
if nums[nums[i]] == nums[i]: return nums[i]
nums[nums[i]], nums[i] = nums[i], nums[nums[i]]
return -1
assert f([3, 1, 2, 3, 4, 2]) == 3
|
benchmark_functions_edited/f5758.py
|
def f(parameter_list, code_list, i):
if parameter_list[0] == 0:
i = parameter_list[1]
return i
assert f([1, 3], [0, 3], 0) == 0
|
benchmark_functions_edited/f194.py
|
def f(a,b):
return int(a) ^ int(b)
assert f(1,0) == 1
|
benchmark_functions_edited/f12285.py
|
def f(value):
try:
if isinstance(value, int):
return value
else:
result = len(value)
return result
except TypeError:
return None
assert f({}) == 0
|
benchmark_functions_edited/f10154.py
|
def f(M, n):
if (n >= 0) and (n <= (M/2)):
return (2*n)/M
elif (n >= ((M/2)+1)) and (n <= (M/2)):
return 2 - ((2*n)/M)
else:
return 0
assert f(1, 1.2) == 0
|
benchmark_functions_edited/f4917.py
|
def f(x, y):
while x > 0 and y > 0:
if x >= y:
x = x - y
else:
y = y - x
return x+y
assert f(100, 5) == 5
|
benchmark_functions_edited/f7344.py
|
def f(string, base_str):
value = 0
base = len(base_str)
for b in string:
value *= base
value += base_str.find(b)
return value
assert f(b'A', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ') == 0
|
benchmark_functions_edited/f3446.py
|
def f(distance):
margin = distance * 2 / 5
return margin
assert f(10) == 4
|
benchmark_functions_edited/f6637.py
|
def f(a,b):
count_list = [0]*26
for n in a:
count_list[ord(n)-ord('a')] += 1
for n in b:
count_list[ord(n)-ord('a')] -= 1
return sum(map(abs,count_list))
assert f(
"",
"abcde"
) == 5
|
benchmark_functions_edited/f12017.py
|
def f(a, b, mix):
if mix < 0:
return a
elif mix > 1:
return b
else:
return (1 - mix) * a + mix * b
assert f(2, 4, 0.5) == 3
|
benchmark_functions_edited/f1707.py
|
def f(sets):
return sum(ord(letter) - ord('A') + 1 for letter in sets)
assert f("ABC") == 6
|
benchmark_functions_edited/f2781.py
|
def f(a1, b1, c1, a2, b2, c2):
return abs(a1 - a2) + abs(b1 - b2) + abs(c1 - c2)
assert f(1, 1, 1, 1, 1, 1) == 0
|
benchmark_functions_edited/f2018.py
|
def f(arr):
o = 0
for a in arr:
o = (o << 8) + a
return o
assert f(bytearray([0])) == 0
|
benchmark_functions_edited/f3582.py
|
def f(bitlist: list) -> int:
result = 0
for bit in bitlist:
result = (result << 1) | bit
return result
assert f(list([0,1,0])) == 2
|
benchmark_functions_edited/f12067.py
|
def f(val: int, n: int):
return val >> n if val >= 0 else (val + 0x100000000) >> n
assert f(5, 2) == 1
|
benchmark_functions_edited/f7323.py
|
def f(m_med, m_f):
return 1 + 2 * m_f**2 / m_med**2
assert f(1, 1) == 3
|
benchmark_functions_edited/f13432.py
|
def f(performance_comparisons):
min_performance_change = 0
for _, percent_diff, _, _ in performance_comparisons:
if percent_diff < min_performance_change:
min_performance_change = percent_diff
return min_performance_change
assert f(
[('a', 1.0, 1.0, 2.0),
('b', 2.0, 2.0, 1.0),
('c', 3.0, 3.0, 3.0),
('d', 4.0, 4.0, 5.0)]) == 0
|
benchmark_functions_edited/f8568.py
|
def f(a, b):
if isinstance(a, (int, float)) and isinstance(b, (int, float)):
return int(a) + int(b)
else:
raise TypeError("{:} must be an integer"
.format('b' if isinstance(a, (int, float)) else 'a'))
assert f(1, 1.0) == 2
|
benchmark_functions_edited/f4185.py
|
def f(s, N):
bs = bin(s)[2:].zfill(N)
return int(bs[-1] + bs[:-1], base=2)
assert f(0, 1) == 0
|
benchmark_functions_edited/f2694.py
|
def isHTML (fileS):
if fileS.endswith("htm") or fileS.endswith("html") :
return 1
return 0
assert f("foo.bar") == 0
|
benchmark_functions_edited/f7454.py
|
def f(velocity: int) -> int:
final_position = (velocity * (velocity + 1)) // 2 # Gauss summation strikes again
return final_position
assert f(3) == 6
|
benchmark_functions_edited/f11238.py
|
def f(subarr_len, arr):
# check all subarrs in the sorted arr
arr = sorted(arr, reverse=True)
return min(arr[i] - arr[i + subarr_len - 1]
for i in range(len(arr) - subarr_len + 1))
assert f(3, [4, 5, 2, 10, 1, 7]) == 3
|
benchmark_functions_edited/f13662.py
|
def f(name, container, docmap):
if docmap is None or not docmap.has_key(container): return 0
container_doc = docmap.get(container)
if container.is_routine():
for param in container_doc.parameter_list():
if param.name() == name: return 1
return 0
assert f('foo', None, None) == 0
|
benchmark_functions_edited/f14486.py
|
def f(Tf, t):
return 10 * (1.0 * t / Tf) ** 3 - 15 * (1.0 * t / Tf) ** 4 \
+ 6 * (1.0 * t / Tf) ** 5
assert f(4, 0) == 0
|
benchmark_functions_edited/f10856.py
|
def f(input_x: int) -> int:
x = input_x
for i in range(x.bit_length()):
if x & (1 << i) > 0:
return x.bit_length() - i
return 0
assert f(0b11111111) == 8
|
benchmark_functions_edited/f11814.py
|
def f(env_names, graphs):
max_children = 0
for name in env_names:
most_frequent = max(graphs[name], key=graphs[name].count)
max_children = max(max_children, graphs[name].count(most_frequent))
return max_children
assert f(
['ant', 'antmaze'],
{
'ant': ['ant', 'antmaze', 'walker2d'],
'antmaze': ['ant', 'antmaze', 'walker2d']
}
) == 1
|
benchmark_functions_edited/f5864.py
|
def f(mass: int) -> int:
required_fuel = mass // 3 - 2
return required_fuel
assert f(12) == 2
|
benchmark_functions_edited/f829.py
|
def f(X):
return X["a"] + X["b"]
assert f({"a": 1, "b": 2}) == 3
|
benchmark_functions_edited/f11848.py
|
def f(state):
invCount = 0
size = len(state)
for i in range(0, size-1):
for j in range(i+1, size):
if (int(state[j]) and int(state[i]) and state[i] > state[j]):
invCount += 1
# return (invCount%2 == 0)
return 1
assert f(list('318540276')) == 1
|
benchmark_functions_edited/f5190.py
|
def f(data):
if data != None:
return data
else:
return ""
assert f(3) == 3
|
benchmark_functions_edited/f5671.py
|
def f(x):
x = str(x) + str(x)[0]
return sum([int(x[i]) for i in range(len(x)-1) if x[i] == x[i+1]])
assert f(1234) == 0
|
benchmark_functions_edited/f3470.py
|
def f(length: float, breadth: float, height: float) -> float:
volume: float = length * breadth * height
return volume
assert f(2, 1, 3) == 6
|
benchmark_functions_edited/f10879.py
|
def f(w,z,point,verbose=False):
if point>z[0]:
for i in range(1,len(z)):
if point<=z[i]:
weight=(z[i]-point)/(z[i]-z[i-1])
if verbose:print(weight,point,z[i-1])
return w[i]*(1-weight)+w[i-1]*weight
else:
return w[0]
assert f([3,4,5],[3,4,5],5) == 5
|
benchmark_functions_edited/f5958.py
|
def f(m_vals, B_z):
return m_vals * B_z * (1/2)
assert f(0, 0) == 0
|
benchmark_functions_edited/f13307.py
|
def f(arr, first, last):
mid = first + (last - first) >> 1
if (arr[first] - arr[mid]) * (arr[last] - arr[first]) >= 0:
return first
elif (arr[mid] - arr[first]) * (arr[last] - arr[mid]) >= 0:
return mid
else:
return last
assert f([0, 1, 2, 3, 4], 0, 2) == 1
|
benchmark_functions_edited/f9186.py
|
def f(x, rho, x_obs):
return (x + x_obs / rho) / (1. + 1. / rho)
assert f(1, 1, 1) == 1
|
benchmark_functions_edited/f6143.py
|
def f(d, key, func, *args, **kwargs):
try:
return d[key]
except KeyError:
return func(*args, **kwargs)
assert f(
{'a': 1, 'b': 2}, 'b',
lambda: 3) == 2
|
benchmark_functions_edited/f1047.py
|
def f(x, y):
return x if x > y else y
assert f(1, -2) == 1
|
benchmark_functions_edited/f3229.py
|
def f(a: int, b: int) -> int:
while b != 0:
(a, b) = (b, a % b)
return a
assert f(3, 2) == 1
|
benchmark_functions_edited/f11907.py
|
def f(value, breaks):
for i in range(1, len(breaks)):
if value < breaks[i]:
return i
return len(breaks) - 1
assert f(11, [1, 3, 10]) == 2
|
benchmark_functions_edited/f9880.py
|
def f(fn):
assert callable(fn), 'function_arg_count needed a callable function, not {0}'.format(repr(fn))
if hasattr(fn, '__code__') and hasattr(fn.__code__, 'co_argcount'):
return fn.__code__.co_argcount
else:
return 1
assert f(print) == 1
|
benchmark_functions_edited/f8707.py
|
def f(s):
if s.rfind('\n') == -1:
return len(s)
return len(s) - s.rfind('\n') - len('\n')
assert f(u'hi there\n\n') == 0
|
benchmark_functions_edited/f14080.py
|
def f(s1, s2):
# Transform into a fixed-size binary string first
s1bin = ' '.join('{0:08b}'.format(ord(x), 'b') for x in s1)
s2bin = ' '.join('{0:08b}'.format(ord(x), 'b') for x in s2)
if len(s1bin) != len(s2bin):
raise ValueError("Undefined for sequences of unequal length")
return sum(el1 != el2 for el1, el2 in zip(s1bin, s2bin))
assert f(b'', b'') == 0
|
benchmark_functions_edited/f8769.py
|
def f(val):
try:
return val._sgn_()
except AttributeError:
if val == 0:
return 0
if val > 0:
return 1
else:
return -1
assert f(-0) == 0
|
benchmark_functions_edited/f13439.py
|
def f(l_, l):
if l_ == l:
return 0 #1 if pos < self.m else 0
elif abs(l_) > abs(l) and l * l_ >= 0:
return 0
elif abs(l_) < abs(l) and l * l_ >= 0:
return abs(l - l_)
else:
return abs(l - l_) - abs(l_)
assert f(1, 2) == 1
|
benchmark_functions_edited/f9726.py
|
def f(number):
return sum(int(x) for x in str(abs(number)))
assert f(-100000) == 1
|
benchmark_functions_edited/f2782.py
|
def f(u, u_prev):
return (u - u_prev) ** 2
assert f(10, 10) == 0
|
benchmark_functions_edited/f5969.py
|
def f(is_in_support):
if is_in_support == 254.0:
return 1
elif is_in_support == 152.0:
return 0
assert f(254) == 1
|
benchmark_functions_edited/f336.py
|
def f(ix):
return ix + (ix & ~7)
assert f(0) == 0
|
benchmark_functions_edited/f660.py
|
def f(a, b, *args, **kwargs):
return round(a * b, 2)
assert f(1, 2) == 2
|
benchmark_functions_edited/f5360.py
|
def f(adc_value, bits=12, vRef=1.8):
return adc_value*(vRef/2**bits)
assert f(0, 2) == 0
|
benchmark_functions_edited/f5895.py
|
def f(str1, str2):
diffs = 0
for ch1, ch2 in zip(str1, str2):
if ch1 != ch2:
diffs += 1
return diffs
assert f(list('abc'), list('def')) == 3
|
benchmark_functions_edited/f13547.py
|
def f(byteArray):
number = 0
round = 0
for byte in byteArray:
round += 1
if round > 1:
number <<= 7
number |= byte & 127 # only use the lower 7 bits
return number
assert f(bytearray([0b00000000])) == 0
|
benchmark_functions_edited/f6356.py
|
def f(numbers, size):
return (size * (size + 1)) // 2 - sum(numbers)
assert f(
[2, 3, 1, 8, 2], 6) == 5
|
benchmark_functions_edited/f1884.py
|
def f(shape):
size=1
for d in shape: size*=d
return size
assert f( (1,) ) == 1
|
benchmark_functions_edited/f9356.py
|
def f(numbers):
if not numbers:
return None
min_number = numbers[0]
for number in numbers:
min_number = number if number < min_number else min_number
return min_number
assert f(range(1, 5)) == 1
|
benchmark_functions_edited/f8400.py
|
def f(a,b):
if b == 0 :
return a
else:
return f(b,a%b)
##@param num1,num2 a tuple of the form (fac,fac_inv)
#@return a tuple of the form (fac,fac_inv)
assert f(1, 11) == 1
|
benchmark_functions_edited/f3474.py
|
def f(square: float, side3: float):
height = 2 * square / side3
return height
assert f(48, 12) == 8
|
benchmark_functions_edited/f4248.py
|
def f(a, b):
return -(-a // b)
assert f(4, 1) == 4
|
benchmark_functions_edited/f13195.py
|
def f(used_markers):
new_marker = 1
while new_marker in used_markers:
new_marker += 1
return new_marker
assert f({0, 1, 2, 3}) == 4
|
benchmark_functions_edited/f310.py
|
def f(c, n, d):
dec_c = pow(c, d, n)
return dec_c
assert f(1, 4, 2) == 1
|
benchmark_functions_edited/f8844.py
|
def f(fname):
try:
f = open(fname, "rb")
f.close()
return 0
except IOError:
print("ERROR: Could not read file", fname)
return 1
sys.exit()
f.close()
assert f("foo") == 1
|
benchmark_functions_edited/f9045.py
|
def f(string: str) -> int:
cost = 0
if not string:
return 0
characters = set()
for char in string:
if char not in characters:
cost += 1
characters.add(char)
return cost
assert f(
"ABABABAB"
) == 2
|
benchmark_functions_edited/f12616.py
|
def f(level, maxval):
return int(level * maxval / 10)
assert f(100, 0) == 0
|
benchmark_functions_edited/f9525.py
|
def f(map):
map_keys = [len(map[key].keys()) for key in map.keys()]
if len(map_keys) == 0:
return 0
return sum(map_keys) / float(len(map_keys))
assert f({}) == 0
|
benchmark_functions_edited/f7494.py
|
def f(name): # pylint: disable=unused-argument
print("Goodbye, {name}".format(**locals()))
return 0
assert f("World") == 0
|
benchmark_functions_edited/f11219.py
|
def f(x, y, a, b, sigma=0.25):
number = 0
for i in range(len(x)):
y_estimate = a * x[i] + b
if abs(y_estimate - y[i]) < sigma:
number += 1
return number
assert f(
[1.0, 2.0, 3.0, 4.0], [3.0, 2.0, 3.0, 4.0], -1.0, 2.0) == 0
|
benchmark_functions_edited/f10643.py
|
def f(dec1, dec2):
return 3600 * (dec1 - dec2)
assert f(100, 100) == 0
|
benchmark_functions_edited/f4858.py
|
def f(m, n):
return sum(map(int, bin(m ^ n)[2:]))
assert f(11, 10) == 1
|
benchmark_functions_edited/f1307.py
|
def f(a, b):
return (a - 1) // b + 1
assert f(10, 2) == 5
|
benchmark_functions_edited/f14075.py
|
def f(indices_size, value_size):
if value_size < 1:
raise ValueError("The value assigned to tensor cannot be empty.")
if value_size > 1:
if value_size != indices_size:
raise ValueError(
"The value given to tensor does not match the index size. \
value size:{}, indics size:{}".format(value_size, indices_size))
return value_size
assert f(4, 1) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.