file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f4562.py
|
def f(args_tuple):
function, args = args_tuple
try:
return function(*args)
except KeyboardInterrupt:
pass
assert f(
((lambda a, b, *, c=4: a + b + c), (1, 2,))) == 7
|
benchmark_functions_edited/f13405.py
|
def f(list_in, value):
if list_in[0] > value:
return None
for ind, crrt_element in enumerate(list_in):
if crrt_element > value:
return ind
return None
assert f( [1, 4, 6, 9, 12], 9) == 4
|
benchmark_functions_edited/f4997.py
|
def f(
q1: float, q2: float, c1: float = 2, c2: float = 1, *args: float
) -> float:
return c1 * q1 + c2 * q2
assert f(1, 1) == 3
|
benchmark_functions_edited/f7071.py
|
def f(value):
try:
return int((value[1] * 100) / value[2])
except Exception:
return 0
assert f(('hi', 'hi', 'hi')) == 0
|
benchmark_functions_edited/f3206.py
|
def f(source, added):
if source is None:
source = added
else:
source &= added
return source
assert f(None, 1) == 1
|
benchmark_functions_edited/f14252.py
|
def f(event_id_1, event_id_2):
if event_id_1 == 1 and event_id_2 == 1:
return 0 # Completely similar
if event_id_1 == 2 and event_id_2 == 2:
return 0.5 # Somewhat similar
elif event_id_1 == 1 and event_id_2 == 2:
return 0.5 # Somewhat similar
elif event_id_1 == 2 and event_id_1 == 1:
return 0.5 # Somewhat similar
else:
return 1
assert f(1, 3) == 1
|
benchmark_functions_edited/f4366.py
|
def f(word):
if word[0] == '\x1b':
return len(word) - 11 # 7 for color, 4 for no-color
return len(word)
assert f('foooo') == 5
|
benchmark_functions_edited/f2591.py
|
def f(numbers):
return sum(numbers) / float(len(numbers))
assert f(range(5)) == 2
|
benchmark_functions_edited/f7668.py
|
def f(s):
return int("".join(i for i in s), 2)
assert f("001") == 1
|
benchmark_functions_edited/f5041.py
|
def f(row_indices, col_indices, num_cols):
return (row_indices * num_cols) + col_indices
assert f(0, 3, 4) == 3
|
benchmark_functions_edited/f13779.py
|
def f(lst: list) -> int:
if len(lst) < 2:
return 0
minv = lst[0]
diff = lst[1] - minv
for i in range(2, len(lst)):
if lst[i-1] < minv:
minv = lst[i-1]
curr_diff = lst[i] - minv
if curr_diff > diff:
diff = curr_diff
return diff
assert f(
[100]) == 0
|
benchmark_functions_edited/f10087.py
|
def f(reliable_image, denoised_image, fusion_weight, confidence_map=None, **kwargs):
estimated_noise = reliable_image - denoised_image
fused_image = reliable_image - fusion_weight * estimated_noise
return fused_image
assert f(2, 2, 0.5) == 2
|
benchmark_functions_edited/f13649.py
|
def f(n, cache):
if n == 1:
return 1
if n in cache:
return cache[n]
if n % 2 == 0:
cache[n] = f(n // 2, cache) + 1
else:
cache[n] = f(3 * n + 1, cache) + 1
return cache[n]
assert f(40, {}) == 9
|
benchmark_functions_edited/f9338.py
|
def f(x_axis,cdf,percent,reverse=False):
n = len(cdf)
if(not reverse):
cut = percent/100.
else:
cut = 1. - percent/100.
i = 0
while((cdf[i]<=cut)and(i<n)):
i += 1
if(i>0):
return x_axis[i-1]
else:
return x_axis[i]
assert f(range(10), range(10), 0) == 0
|
benchmark_functions_edited/f14015.py
|
def f(X, y):
eps = 1e-08
prediction, box_class_count, *_ = X
concept_direction = y
box_class_count = box_class_count + eps # prevent division by zero
return -1 * (concept_direction * prediction / box_class_count)
assert f(
(0, 0, 0), 1
) == 0
|
benchmark_functions_edited/f13444.py
|
def f(elem, bins):
for idx, bounds in enumerate(bins, start=1):
if bounds[0] < elem <= bounds[1]:
return idx
else:
return -1
assert f(0.1, [(0.0, 1.0)]) == 1
|
benchmark_functions_edited/f13288.py
|
def f(test, left, right):
n = len(test)
while left >= 0 and right < n and test[left] is test[right]:
left -= 1
right += 1
return right - left - 1
assert f("aa", 0, 0) == 1
|
benchmark_functions_edited/f3034.py
|
def f(n):
a = str(n)
dsum = 0
for char in a:
dsum += int(char)
return(dsum)
assert f(0) == 0
|
benchmark_functions_edited/f6635.py
|
def f(lowc = 'u'):
if(lowc == 'u'):
return 0
if(lowc == 'r'):
return 1
if(lowc == 'd'):
return 2
if(lowc == 'l'):
return 3
assert f(u'l') == 3
|
benchmark_functions_edited/f9578.py
|
def f(n_categories):
val = min(600, round(1.6 * n_categories**0.56))
return int(val)
assert f(2) == 2
|
benchmark_functions_edited/f3547.py
|
def f(s1, s2):
assert len(s1) == len(s2)
return sum(c1 != c2 for c1, c2 in zip(s1, s2))
assert f('1111', '0000') == 4
|
benchmark_functions_edited/f2811.py
|
def f(pixels, dpi):
return((pixels / float(dpi)) * 25.4)
assert f(0, 144) == 0
|
benchmark_functions_edited/f6980.py
|
def f(a):
try:
res = float(a)
return res
except:
msg = 'Cannot convert value to a float.\nValue: %s' % a.__repr__()
raise TypeError(msg)
assert f(0) == 0
|
benchmark_functions_edited/f11594.py
|
def f(a,b):
i = 1
if float(a/b) - int(a/b) != 0.0:
while True:
if b*i < a:
i +=1
else:
return a - b * (i-1)
break
elif b > a:
return a
else:
return 0
assert f(9,1) == 0
|
benchmark_functions_edited/f292.py
|
def f(xs):
return max(set(xs), key=xs.count)
assert f([1,2,3]) == 1
|
benchmark_functions_edited/f9083.py
|
def f(
string_label, label_classes, default=-1, **unused_kwargs):
if string_label in label_classes:
return label_classes.index(string_label)
else:
return default
assert f(
"foo", ["foo", "bar"]) == 0
|
benchmark_functions_edited/f14484.py
|
def f(nums):
if nums == None:
return 0
if len(nums) == 0:
return 0
max_array = [0 for num in range(len(nums))]
max_array[0] = nums[0]
for num in range(1, len(nums)):
max_array[num] = max(max_array[num-1]+nums[num], nums[num])
return max(max_array)
assert f([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
|
benchmark_functions_edited/f5475.py
|
def f(x, y):
area = 0.0
for i in range(-1, len(x)-1):
area += x[i] * (y[i+1] - y[i-1])
return abs(area) / 2.0
assert f(
[-1, -1, 0, -1, 0, 1, -1, 1, -1, -1],
[0, 1, 1, 0, -1, -1, -1, 0, 1, 1]) == 1
|
benchmark_functions_edited/f8767.py
|
def f(thread_list, recorded):
return recorded + sum(getattr(thread, 'pending_data', 0) for thread in thread_list)
assert f([None, None, None], 0) == 0
|
benchmark_functions_edited/f9681.py
|
def f(data, path):
value = data
try:
for key in path:
value = value[key]
return value
except (KeyError, IndexError):
return ''
assert f(
{"a": {"b": {"c": 3}}},
["a", "b", "c"]
) == 3
|
benchmark_functions_edited/f12758.py
|
def f(iterable, default=False, pred=None):
# first_true([a,b,c], x) --> a or b or c or x
# first_true([a,b], x, f) --> a if f(a) else b if f(b) else x
return next(filter(pred, iterable), default)
assert f([0, 1, 2, 3, 4], 5, lambda x: x > 5) == 5
|
benchmark_functions_edited/f13814.py
|
def f(ifm_dim, k, stride, total_pad=0, dilation=1):
if ifm_dim == 1:
# indicates dummy dimension, keep as-is
out_dim = 1
else:
out_dim = int(((ifm_dim + total_pad - dilation * (k - 1) - 1) / stride) + 1)
return out_dim
assert f(1, 2, 2) == 1
|
benchmark_functions_edited/f4658.py
|
def f(data):
n = len(data)
if n < 1:
raise ValueError('mean requires at least one data point')
return sum(data) / n
assert f([1, 2, 3, 4, 5]) == 3
|
benchmark_functions_edited/f4861.py
|
def f(ndim, ind, strides):
ret = 0
for i in range(ndim):
ret += strides[i] * ind[i]
return ret
assert f(1, [0], [1]) == 0
|
benchmark_functions_edited/f5665.py
|
def f(x):
assert type(x) == type(()), 'Expected tuple.' # safety check
assert len(x) == 1, 'Expected tuple singleton.' # safety check
return x[0]
assert f(tuple((1,))) == 1
|
benchmark_functions_edited/f4991.py
|
def f(a,b,x):
return a*x**(b)
assert f(3,0,3) == 3
|
benchmark_functions_edited/f4381.py
|
def f(n):
# base case
if n < 2:
return 1
else:
return n * f(n-1)
assert f(1) == 1
|
benchmark_functions_edited/f3685.py
|
def f(n):
count = 0
while n:
n &= n - 1
count += 1
return count
assert f(0b00000000000000000000000000001000) == 1
|
benchmark_functions_edited/f8524.py
|
def f(msg: dict) -> int:
records = 0
if msg is not None:
records = len(msg[0])
if records != 1:
raise ValueError("Not expected single record")
return records
assert f([["test"], ["test2"], ["test3"]]) == 1
|
benchmark_functions_edited/f7729.py
|
def f(n, arr):
# Stop case
if n < 0:
return 0
if n == 0:
return 1
ways = 0
for i in range(0, len(arr)):
ways += f(n - arr[i], arr)
return ways
assert f(0, []) == 1
|
benchmark_functions_edited/f832.py
|
def f(deg):
return deg * (3.14159/180)
assert f(0) == 0
|
benchmark_functions_edited/f41.py
|
def f(k, x):
return k[0] * x + k[1]
assert f( (1, 2), 3) == 5
|
benchmark_functions_edited/f14043.py
|
def f(dataset_size: int, num_processes: int) -> int:
chunksize = dataset_size // num_processes
return chunksize if chunksize > 0 else 1
assert f(9, 3) == 3
|
benchmark_functions_edited/f7848.py
|
def f(current, target):
result = (abs(target[0] - current[0]) + abs(target[1] - current[1]))
# print(result)
return result
assert f((0, 0), (0, 0)) == 0
|
benchmark_functions_edited/f8847.py
|
def f(side1, side2, side3):
list = [side1, side2, side3]
list.sort()
return list[-1]
assert f(1, 2, 4) == 4
|
benchmark_functions_edited/f5065.py
|
def f(current_fur, previous_fur):
ang = abs(previous_fur - current_fur)
return ang
assert f(-1, 1) == 2
|
benchmark_functions_edited/f3998.py
|
def f(x, vmin, vmax):
if x < vmin:
return vmin
elif x > vmax:
return vmax
else:
return x
assert f(10, 0, 9) == 9
|
benchmark_functions_edited/f8611.py
|
def count_lowers (val):
return sum(1 for c in val if c.islower())
assert f("!@#$%^&*()") == 0
|
benchmark_functions_edited/f7901.py
|
def f(x):
bits = []
bits.extend(x)
bits.reverse() # MSB
multi = 1
value = 0
for b in bits:
value += b * multi
multi *= 2
return value
assert f([1,0,1]) == 5
|
benchmark_functions_edited/f11868.py
|
def f(
n_machine_time_steps, bytes_per_timestep):
if n_machine_time_steps is None:
raise Exception(
"Cannot record this parameter without a fixed run time")
return ((n_machine_time_steps * bytes_per_timestep) +
(n_machine_time_steps * 4))
assert f(1, 4) == 8
|
benchmark_functions_edited/f3879.py
|
def f(x, vec):
for i in range(len(vec)):
if vec[i] > x:
return i
return -1
assert f(1, [1, 1, 2]) == 2
|
benchmark_functions_edited/f9829.py
|
def f(x, y):
return (x > y) - (x < y)
assert f([1, 2, 3], [1, 2, 3]) == 0
|
benchmark_functions_edited/f8321.py
|
def f(a, b):
while b != 0:
(a, b) = (b, a % b)
return a
assert f(27, 18) == 9
|
benchmark_functions_edited/f9129.py
|
def f(some_list, current_index):
try:
return some_list[int(current_index) - 1] # access the previous element
except:
return ''
assert f(range(10), 2) == 1
|
benchmark_functions_edited/f4222.py
|
def f(current, rampdown_length):
if current >= rampdown_length:
return 1.0 - current / rampdown_length
else:
return 1.0
assert f(1, 1) == 0
|
benchmark_functions_edited/f1512.py
|
def f(y, f, t, h):
k1 = f(t, y)
k2 = f(t + 0.5*h, y + 0.5*h*k1)
return y + h*k2
assert f(1, lambda x, y: 1, 0, 1) == 2
|
benchmark_functions_edited/f4169.py
|
def f(data:list, item):
for k, v in enumerate(data):
if v == item:
return(k)
return(-1)
assert f(list("abc"), "c") == 2
|
benchmark_functions_edited/f7869.py
|
def f(x):
x_string = str(x)
sum = 0
if x == 6666:#if it is a no-data pixel
return 255
for i in range(1,6):
if str(i) in x_string:
sum += 2**i
return sum
assert f(0) == 0
|
benchmark_functions_edited/f9907.py
|
def f(a, b):
c = (b - a) % 360
if c > 180:
c -= 360
return c
assert f(0, 0) == 0
|
benchmark_functions_edited/f1998.py
|
def f(n,BDIM):
mult=int((n+BDIM-1)/BDIM)
return mult*BDIM
assert f(1, 2) == 2
|
benchmark_functions_edited/f3822.py
|
def f(int):
count = 0
for bit in range(0, 32):
count = count + ((int >> bit) & 1)
return count
assert f(26) == 3
|
benchmark_functions_edited/f3515.py
|
def f(x, a, b):
return a - b * x
assert f(1, 3, 0) == 3
|
benchmark_functions_edited/f13788.py
|
def f(n, k):
count = 0
digits = 1
while n and digits <= k:
count += n & 1
n >>= 1
digits += 1
return count
assert f(0, 0) == 0
|
benchmark_functions_edited/f5487.py
|
def f(data, split_count):
if hasattr(data, "__len__"):
return min(len(data), split_count)
return split_count
assert f([9], 3) == 1
|
benchmark_functions_edited/f11156.py
|
def f(value, gamma):
if value > 1.:
return 1.
if value < 0:
return 0.
else:
return value**(1./gamma)
assert f(0, 0.5) == 0
|
benchmark_functions_edited/f4655.py
|
def f(value, lower, upper):
return lower if value < lower else upper if value > upper else value
assert f(1, 1, 100) == 1
|
benchmark_functions_edited/f1433.py
|
def f(x):
return max(x) - min(x)
assert f([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) == 9
|
benchmark_functions_edited/f10438.py
|
def f(groupdict):
if groupdict['hours'] is None:
groupdict['hours'] = 0
return (int(groupdict['hours']) * 3600 +
int(groupdict['minutes']) * 60 +
int(groupdict['seconds'])) * 1000
assert f(
{
'hours': '00',
'minutes': '00',
'seconds': '00'
}
) == 0
|
benchmark_functions_edited/f8574.py
|
def f(x):
return -1 if x < 0 else 0 if x == 0 else 1
assert f(2) == 1
|
benchmark_functions_edited/f14128.py
|
def f(layers: int) -> int:
# base case: spiral with 1 layer has a diagonal sum of 1
if layers < 2:
return 1
side = layers * 2 - 1
side_squared = side * side
# compute the sum of the diagonal entries of the current layer and recurse
return side_squared * 4 - (side - 1) * 6 + f(layers - 1)
assert f(1) == 1
|
benchmark_functions_edited/f2525.py
|
def f(deg):
n_rotations = deg // 360
deg -= 360 * n_rotations
return deg
assert f(-360) == 0
|
benchmark_functions_edited/f14069.py
|
def f(values):
# how many measurements increased
increased = 0
# first value
previous = values[0]
# rest of the values
for current in values[1:]:
if current > previous:
increased += 1
previous = current
return increased
assert f(list(map(int, "199 200 208 210 200 207 240 269 260 263".split()))) == 7
|
benchmark_functions_edited/f5289.py
|
def f(a: int, b: int) -> int:
return a if a == b else sum([i for i in range(min(a, b), max(a, b)+1)])
assert f(-10, 10) == 0
|
benchmark_functions_edited/f1241.py
|
def f(a):
# type: (tuple) -> float
return (a[0] ** 2) + (a[1] ** 2)
assert f( (0, 0) ) == 0
|
benchmark_functions_edited/f8950.py
|
def f(dev):
return (dev & 0xff) | ((dev >> 12) & ~0xff)
assert f(2) == 2
|
benchmark_functions_edited/f4303.py
|
def f(x0, y0, gx, gy, x, y):
#return INVPI * gx/((x-x0)**2+gx**2) * gy/((y-y0)**2+gy**2)
return (gx*gy)**2 / ((x-x0)**2 + gx**2) / ((y-y0)**2 + gy**2)
assert f(1, 1, 1, 1, 1, 1) == 1
|
benchmark_functions_edited/f12704.py
|
def f(num_1, num_2):
max = num_1 if num_1 > num_2 else num_2
lcm = max
while (True):
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
break
lcm += max
return lcm
assert f(2, 2) == 2
|
benchmark_functions_edited/f12836.py
|
def f(iterable):
item = None
iterator = iter(iterable)
try:
item = next(iterator)
except StopIteration:
raise ValueError('Iterable is empty, must contain one item')
try:
next(iterator)
except StopIteration:
return item
else:
raise ValueError('object contains >1 items, must contain exactly one.')
assert f(range(1)) == 0
|
benchmark_functions_edited/f12038.py
|
def f(ascending_list, datum):
old_delta = abs(ascending_list[0] - datum)
for index, element in enumerate(ascending_list[1:]):
delta = abs(element - datum)
if delta > old_delta:
return index
old_delta = delta
return len(ascending_list) - 1
assert f(range(0, 5), 5) == 4
|
benchmark_functions_edited/f9449.py
|
def f(i):
# return 2*i
# return 2**i
return 1
assert f(2) == 1
|
benchmark_functions_edited/f10627.py
|
def f(a, b):
if type(a) is not list:
raise ValueError(f"Incorrect parameter type: {type(a)}")
elif type(b) is not list:
raise ValueError(f"Incorrect parameter type: {type(b)}")
else:
return sum([a[i] * b[i] for i in range(len(b))])
assert f([], []) == 0
|
benchmark_functions_edited/f11607.py
|
def f(slopesBetweenJumps):
countSides = 0
currSlope2 = 10000
runningTotal = 0
for x in slopesBetweenJumps:
if(x == currSlope2):
runningTotal += 1
else:
currSlope2 = x
runningTotal = 0
if(runningTotal == 3):
countSides += 1
return countSides
assert f([0, 1, 2, 3, 4, 5]) == 0
|
benchmark_functions_edited/f10425.py
|
def f(idx, dim):
if idx < dim:
return idx
else:
return idx - dim
assert f(0, 4) == 0
|
benchmark_functions_edited/f12325.py
|
def f(n):
if not isinstance(n, int):
raise TypeError("Input parameter must be an integer")
if n <= 0:
return 1
else:
return n * f(n-2)
assert f(1) == 1
|
benchmark_functions_edited/f2375.py
|
def f(pep8_output):
return len(pep8_output.splitlines())
assert f('a\nb\n') == 2
|
benchmark_functions_edited/f11191.py
|
def f(max, min, N):
precision = 10
while precision > 0:
mid = (max+min)//2
if mid*min > N:
max = mid
else:
min = mid
precision -= 1
return max
assert f(1, 1, 10000) == 1
|
benchmark_functions_edited/f14538.py
|
def f(offsets):
# Put the offsets in a list
value_list = offsets.split('\n')
# Starting at [0] follow the offsets, adding one to each when used
list_position = 0
steps = 0
while list_position < len(value_list):
offset = int(value_list[list_position])
value_list[list_position] = int(value_list[list_position]) + 1
steps += 1
list_position += offset
return steps
assert f(
'0\n3\n0\n1\n-3') == 5
|
benchmark_functions_edited/f8781.py
|
def f(arr):
swap, i = 0, 0
while i < len(arr):
if arr[i] == (i + 1):
i += 1
continue
arr[arr[i] - 1], arr[i] = arr[i], arr[arr[i] - 1]
swap += 1
return swap
assert f(
[4, 3, 1, 2]) == 3
|
benchmark_functions_edited/f13926.py
|
def f(data):
return sum(i for i in data)
assert f([1, 2, 3]) == 6
|
benchmark_functions_edited/f10818.py
|
def f(hand):
handLength = 0
# Iterate through letters in current hand
for letter in hand:
# Increment handLength
handLength += hand[letter]
return handLength
assert f({}) == 0
|
benchmark_functions_edited/f12159.py
|
def f(data):
valMax = data[0]
xOfMax = 0
for i in range(len(data)):
if data[i] > valMax:
valMax = data[i]
xOfMax = i
return xOfMax
assert f([1,2,3,4,5]) == 4
|
benchmark_functions_edited/f4136.py
|
def f(probability: float, length: int) -> float:
return probability ** -(1 / length)
assert f(1 / 3, 1) == 3
|
benchmark_functions_edited/f10523.py
|
def f(base, exponent):
if base == 0:
return 0
if exponent == 0:
return 1
exp = abs(exponent)
power = 1
for i in range(exp):
power *= base
if exponent < 0:
return 1.0 / power
return power
assert f(-1, 0) == 1
|
benchmark_functions_edited/f8331.py
|
def f(r, p, ri, ro, E, nu, dT, alpha):
A = ri**2 * ro**2 * -p / (ro**2 - ri**2)
C = p * ri**2 / (ro**2 - ri**2)
u = (-A*nu - A + C*r**2*(1 - 2*nu))/(E*r)
return u
assert f(1, 0, 0, 1, 1, 0.3, 0, 0) == 0
|
benchmark_functions_edited/f5542.py
|
def f(a, b, s):
(a1, a2), (b1, b2) = a, b
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
assert f(
(1, 10),
(2, 3),
1
) == 2
|
benchmark_functions_edited/f5966.py
|
def f(total, items):
for i in range(len(items)):
s = sum(items[:i])
if s > total:
return i
return 0
assert f(4, [1, 2, 3]) == 0
|
benchmark_functions_edited/f14093.py
|
def f(tweet_in_conversation, tweet_map):
root_id = tweet_in_conversation
# go until we reply outside of the corpus, or the current tweet isn't a reply
while root_id in tweet_map and 'in_reply_to_status_id_str' in tweet_map[root_id] and tweet_map[root_id]['in_reply_to_status_id_str']:
root_id = tweet_map[root_id]['in_reply_to_status_id_str']
return root_id
assert f(1, {}) == 1
|
benchmark_functions_edited/f13219.py
|
def f(start, stop):
numfactors = (stop - start) >> 1
if not numfactors:
return 1
elif numfactors == 1:
return start
else:
mid = (start + numfactors) | 1
return f(start, mid) * f(mid, stop)
assert f(1, 3) == 1
|
benchmark_functions_edited/f4901.py
|
def f(l, m=0):
if not -l <= m <= l:
raise ValueError('m must lie between -l and l')
return l*(l + 1) + m
assert f(1, 1) == 3
|
benchmark_functions_edited/f3837.py
|
def f(v: int, bits: int) -> int:
count = 0
while count < bits and (v % 2) == 0:
count += 1
v //= 2
return count
assert f(0b1110, 4) == 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.