file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f2023.py | def f(iterable, default=None):
return next(iter(iterable), default)
assert f(range(5, 100)) == 5 |
benchmark_functions_edited/f4451.py | def f(input):
return int(input, base=16)
assert f('0x0000') == 0 |
benchmark_functions_edited/f3923.py | def f(e):
return int(e[0])
assert f( ('1', 'C') ) == 1 |
benchmark_functions_edited/f4935.py | def f(z, l):
if z > l:
val = z - l
elif z < -l:
val = z + l
else:
val = 0
return val
assert f(1, 1.5) == 0 |
benchmark_functions_edited/f9335.py | def f(n: int, k: int) -> int:
if k > n:
raise ValueError
result = 1
for i in range(n - k + 1, n + 1):
result *= i
for i in range(2, k + 1):
result /= i
return int(result)
assert f(4, 2) == 6 |
benchmark_functions_edited/f2898.py | def f(beta, x):
a, b, c, d, e = beta
return a * (1 - (b + c * (x - d))/((x - d) ** 2 + e ** 2))
assert f( (1, 0, 0, 0, 0), 1) == 1 |
benchmark_functions_edited/f1556.py | def f(n, r=1):
for i in str(n):
r *= max(int(i), 1)
return r
assert f(1) == 1 |
benchmark_functions_edited/f142.py | def f( h ):
return int(h,16)
assert f( '00' ) == 0 |
benchmark_functions_edited/f14513.py | def F_value (ER:float,EF:float,dfnum:float,dfden:float)->float:
return ((ER-EF)/float(dfnum) / (EF/float(dfden)))
assert f(1,1,2,2) == 0 |
benchmark_functions_edited/f7193.py | def f(player_pos, current_move):
player_pos = (player_pos + current_move) % 10
if player_pos == 0:
return 10
return player_pos
assert f(5, 3) == 8 |
benchmark_functions_edited/f2965.py | def f(a: float, b: float, c: float, x: float) -> float:
return ((a*x*x + b) * x*x) + c
assert f(1, 1, 0, 0) == 0 |
benchmark_functions_edited/f1868.py | def f(num_copy):
return 3 + 0.75 * (num_copy - 1)
assert f(1) == 3 |
benchmark_functions_edited/f11228.py | def f(js, key, default=None, take_none=True):
if key not in js:
return default
if js[key] is None and not take_none:
return default
return js[key]
assert f(dict(), "foo", 1) == 1 |
benchmark_functions_edited/f4007.py | def f(n):
a, b = 0, 1
for i in range(n):
a, b = b, a + b
return a
assert f(1) == 1 |
benchmark_functions_edited/f14556.py | def f(shape, subtpl):
if len(shape) != 2 or len(shape) != len(subtpl):
raise IndexError("Input size and subscripts must have length 2 and "
"be equal in length")
row, col = subtpl
ny, nx = shape
ind = nx*row + col
return ind
assert f((2, 2), (1, 0)) == 2 |
benchmark_functions_edited/f11987.py | def f(pred, iterable, default=None):
# f([a,b,c], x) --> a or b or c or x
# f([a,b], x, f) --> a if f(a) else b if f(b) else x
return next(filter(pred, iterable), default)
assert f(lambda x: x > 5, range(10)) == 6 |
benchmark_functions_edited/f5449.py | def f(lst):
return max([abs(x) for x in lst])
assert f([-5, -5, -5]) == 5 |
benchmark_functions_edited/f12688.py | def f(samples_obj):
allele_count = 0
for sampleid, value in samples_obj.items():
allele_count += value["allele_count"]
return allele_count
assert f(
{
"sample_1": {"allele_count": 1},
"sample_2": {"allele_count": 2},
"sample_3": {"allele_count": 3},
}
) == 6 |
benchmark_functions_edited/f5904.py | def f(x, de, logtau0, a, b, einf):
return ( de / ( 1 + ( 1j * x * 10**logtau0 )**a )**b + einf ) * ( 1j * x * 8.854187817 * 10**(-12) )
assert f(0, 1, 1, 1, 1, 1) == 0 |
benchmark_functions_edited/f9428.py | def f(str_to_add, dns_names):
if str_to_add not in dns_names:
dns_names.append(str_to_add)
return dns_names.index(str_to_add)
assert f(1, []) == 0 |
benchmark_functions_edited/f4910.py | def f(seq_header_len):
if seq_header_len > 255:
return 4
if seq_header_len > 127:
return 3
return 2
assert f(10) == 2 |
benchmark_functions_edited/f396.py | def f(y, alpha=0.02):
return pow(y, alpha)
assert f(1, 0.5) == 1 |
benchmark_functions_edited/f11144.py | def f(series, params, offset):
return params[-1] + sum([params[i] * series[offset-i] for i in range(len(params) - 1)])
assert f(
[1, 2, 3], [1, 0, 0], 1
) == 2 |
benchmark_functions_edited/f2098.py | def f(json_data):
return json_data['@odata.count']
assert f(
{'some_key': 5,
'@odata.count': 1,
'other_key': 99}) == 1 |
benchmark_functions_edited/f12068.py | def f(input_size, conv_size, stride, pad):
if input_size is None:
return None
without_stride = input_size + 2 * pad - conv_size + 1
# equivalent to np.ceil(without_stride / stride)
output_size = (without_stride + stride - 1) // stride
return output_size
assert f(10, 5, 1, 1) == 8 |
benchmark_functions_edited/f10351.py | def f(obj, methodName):
method = getattr(obj, methodName)
if hasattr(obj, '__call_arguments'):
ret = method(*obj.__call_arguments)
del obj.__call_arguments
return ret
return method()
assert f(1, 'bit_length') == 1 |
benchmark_functions_edited/f13155.py | def f(n, k):
if n < 0 or k < 0:
raise Exception("Error: Negative argument in binomial coefficient!")
if n < k:
return 0
if n == k:
return 1
if k == 0:
return 1
if k < n - k:
delta = n - k
iMax = k
else:
delta = k
iMax = n - k
ans = delta + 1
for i in range(2, iMax + 1):
ans = (ans * (delta + i)) / i
return ans
assert f(7, 1) == 7 |
benchmark_functions_edited/f2724.py | def f(conf):
TN, FP, FN, TP = conf
if (TN + FN) == 0:
return 0
return TN / float(TN + FN)
assert f([1, 0, 0, 0]) == 1 |
benchmark_functions_edited/f3091.py | def f(number):
_ = 0
while number:
_, number = _ + number%10, number // 10
return _
assert f(9) == 9 |
benchmark_functions_edited/f7515.py | def f(comment: str) -> int:
return len(comment.split())
assert f("") == 0 |
benchmark_functions_edited/f11787.py | def f(input_shape):
idx = [i for i, s in enumerate(input_shape) if s == -1]
assert len(idx) == 1
return idx[0]
assert f((-1, 20)) == 0 |
benchmark_functions_edited/f262.py | def f(x):
return int(x + 1 - x % 2)
assert f(5) == 5 |
benchmark_functions_edited/f10792.py | def f(array, reverse=True, sort_by_key=False):
if isinstance(array, dict):
if not sort_by_key:
return sorted(array.items(), key=lambda x: x[1], reverse=reverse)
return sorted(array.items(), key=lambda x: str(x[0]).lower(), reverse=reverse)
return array
assert f(1) == 1 |
benchmark_functions_edited/f13990.py | def f(col):
# Convert column index e.g. 'A', 'BZ' etc to
# integer equivalent
idx = 0
i = 0
for c in col[::-1]:
idx = idx + pow(26,i)*(ord(c)-64)
i += 1
return idx-1
assert f('A') == 0 |
benchmark_functions_edited/f1124.py | def f(lst):
return sum([abs(x) for x in lst])
assert f([]) == 0 |
benchmark_functions_edited/f78.py | def f(p,q):
return (p-1)*(q-1)
assert f(2,5) == 4 |
benchmark_functions_edited/f1027.py | def f(O, E):
return (O - E) / E
assert f(*[0.3333333333333333, 0.3333333333333333]) == 0 |
benchmark_functions_edited/f8782.py | def f(a, b):
fp = 0
for item in a:
if item not in b:
fp += 1
return fp
assert f({1, 2, 3}, {1, 2}) == 1 |
benchmark_functions_edited/f7528.py | def f(level: int) -> int:
levels = {4: 1, 5: 3, 6: 5}
return levels[level] if isinstance(level, int) and level in levels else 0
assert f(3) == 0 |
benchmark_functions_edited/f14361.py | def f(string: str, substring: str) -> int:
i_str: int = 0
l_str: int = len(string)
l_sub: int = len(substring)
while i_str <= l_str - l_sub:
index = 0
while index < l_sub and string[index + i_str] == substring[index]:
index += 1
if index >= l_sub:
return i_str
elif index + i_str >= l_str:
return -1
i_str += 1
return -1
assert f(
"test string",
"test ") == 0 |
benchmark_functions_edited/f13334.py | def f(s):
try:
return int(s)
except ValueError:
return s
assert f(1) == 1 |
benchmark_functions_edited/f8382.py | def f(note_str):
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
return(notes.index(note_str))
assert f("D") == 2 |
benchmark_functions_edited/f12221.py | def f(f_t1, f_t2, args):
if args['token_similarity_change'] == 'abs':
fd = abs(f_t2 - f_t1) / max(f_t2, f_t1)
else:
fd = (f_t2 - f_t1) / max(f_t2, f_t1)
return fd
assert f(2, 2, {'token_similarity_change':'rel'}) == 0 |
benchmark_functions_edited/f3256.py | def f(n):
ndx = 0
while ( 1 < n ):
n = ( n >> 1 )
ndx += 1
return ndx
assert f(0b00100001) == 5 |
benchmark_functions_edited/f1011.py | def f(x,n):
return x.upper().count(n.upper())
assert f('AAAA', 'A') == 4 |
benchmark_functions_edited/f6319.py | def f(num: int) -> int:
if num == 0:
return 1
digits: int = 0
while num != 0:
digits += 1
num = int(num / 10)
return digits
assert f(99999) == 5 |
benchmark_functions_edited/f3918.py | def f(steps_per_quarter, qpm):
return steps_per_quarter * qpm / 60.0
assert f(4, 30) == 2 |
benchmark_functions_edited/f8627.py | def f(state):
for i in range(0,len(state)):
if state[i] == "_":
return i
break
else:
None
assert f( "_1_2_3_4_5_6_7_8" ) == 0 |
benchmark_functions_edited/f10596.py | def f(hash: bytes) -> int:
return ((0xFC & hash[0]) << 5) | (hash[-1] & 0x7F)
assert f(bytes([0x01, 0x00, 0x00, 0x00])) == 0 |
benchmark_functions_edited/f2908.py | def f():
print('Hi, I am a simple function')
return 1
assert f(**{}) == 1 |
benchmark_functions_edited/f12098.py | def f(ebit, debt, equity):
return ebit / (debt - equity)
assert f(100, 100, 0) == 1 |
benchmark_functions_edited/f6121.py | def f(limit, lower, upper):
return min(max(lower, limit), upper)
assert f(-4, 0, 2) == 0 |
benchmark_functions_edited/f5717.py | def f(request_queue, request_id):
for request in request_queue:
if request[0] == request_id:
return request_queue.index(request)
assert f(
[('A', '2'), ('B', '4'), ('C', '1'), ('D', '5')], 'A') == 0 |
benchmark_functions_edited/f2481.py | def f(tree):
return 1 + f(tree.left) + f(tree.right) if tree else 0
assert f(None) == 0 |
benchmark_functions_edited/f848.py | def f(lst):
return sum(lst) / len(lst)
assert f([1, 3]) == 2 |
benchmark_functions_edited/f9209.py | def f(predictions, target, confidence):
targets_identified = [
pred for pred in predictions if pred['label'] == target and float(pred['confidence']) >= confidence]
return len(targets_identified)
assert f(
[
{'label': 'person', 'confidence': '0.98'},
{'label': 'car', 'confidence': '0.94'},
{'label': 'cat', 'confidence': '0.87'},
{'label': 'person', 'confidence': '0.98'},
{'label': 'car', 'confidence': '0.94'}
],
'dog',
0.85
) == 0 |
benchmark_functions_edited/f493.py | def f(a, b, adder2_offset=0):
return (a + b) + adder2_offset
assert f(1, 1, 0) == 2 |
benchmark_functions_edited/f9661.py | def f(min_val, max_val, percentage):
value_range = max_val - min_val
return min_val + int(percentage * value_range)
assert f(4, 0, 1) == 0 |
benchmark_functions_edited/f653.py | def f(px):
return ((px & ~7) // 2) + (px & 7)
assert f(0) == 0 |
benchmark_functions_edited/f3066.py | def f(v):
b = 0
while v != 0:
v //= 2
b += 1
return b
assert f(0b1) == 1 |
benchmark_functions_edited/f2027.py | def f(level):
return int((level * 255) / 100)
assert f(0) == 0 |
benchmark_functions_edited/f14216.py | def f(
prev1_start, prev1_haplo, curr1_haplo,
prev2_start, prev2_haplo, curr2_haplo):
earliest_start = None
if prev1_haplo == curr1_haplo:
earliest_start = prev1_start
if prev2_haplo == curr2_haplo:
if earliest_start is None or prev2_start < prev1_start:
earliest_start = prev2_start
return earliest_start
assert f(1, 1, 1, 1, 1, 2) == 1 |
benchmark_functions_edited/f11268.py | def f(data, index):
maxValue = [-99999, 0]
for i in data:
if i[index] > maxValue[0]:
maxValue[0] = i[index]
maxValue[1] = i[0]
return maxValue[1]
assert f([(1, 1), (2, 2), (3, 3)], 0) == 3 |
benchmark_functions_edited/f7328.py | def f(x, coef):
result = 0
for c in coef:
result = result * x + c
return result
assert f(0, [1, 2, 3, 4, 5, 6, 7]) == 7 |
benchmark_functions_edited/f7557.py | def f(hand_value):
if hand_value + 11 > 21:
value = 1
else:
value = 11
return value
assert f(25) == 1 |
benchmark_functions_edited/f10687.py | def f(c, dc, D_fn):
# computes diffusivity at given concentration and one step size away [m^2/s]
D1 = D_fn(c)
D2 = D_fn(c + dc)
# computes dD/dc using forward difference formula [m^2/s / kg/m^3]
dDdc = (D2 - D1) / dc
return dDdc
assert f(0, 0.01, lambda c: 1.0) == 0 |
benchmark_functions_edited/f5187.py | def f(meters: float, units: str) -> float:
if units == 'english':
return meters * 3.2808
else:
return meters
assert f(0, 'english') == 0 |
benchmark_functions_edited/f6835.py | def f(mydict, the_val):
for key, val in mydict.items():
if val == the_val:
return key
return None
assert f( dict.fromkeys( [1, 2], 'one'), 'one') == 1 |
benchmark_functions_edited/f1690.py | def f(*args):
n = len(args)
return (sum([abs(arg)**2 for arg in args]))**(1/2)
assert f(0, 0) == 0 |
benchmark_functions_edited/f8343.py | def f(n, k):
if k > n // 2:
k = n - k
x = 1
y = 1
i = n - k + 1
while i <= n:
x = (x * i) // y
y += 1
i += 1
return x
assert f(5, 4) == 5 |
benchmark_functions_edited/f12996.py | def f(points, i, j, k): # FIXME: add doc
a = points[0][j] - points[0][i]
b = points[1][j] - points[1][i]
c = points[0][k] - points[0][i]
d = points[1][k] - points[1][i]
# Determinant
r = 0.5 * (a * d - b * c)
if r == 0:
return 0
elif r > 0:
return 1
else:
return -1
assert f(
[(0, 0), (1, 1), (2, 2)], 0, 1, 1) == 0 |
benchmark_functions_edited/f2004.py | def f(ecc):
if ecc == 0:
return(2)
else:
return(1)
assert f(1.0) == 1 |
benchmark_functions_edited/f5916.py | def f(kernel_size, dilation):
kernel_size = kernel_size + (kernel_size-1)*(dilation-1)
padding = (kernel_size-1) // 2
return padding
assert f(3, 1) == 1 |
benchmark_functions_edited/f5661.py | def f(n):
if not 0.0 <= n <= 1.0:
raise ValueError('Argument must be between 0.0 and 1.0.')
return n
assert f(1) == 1 |
benchmark_functions_edited/f14104.py | def f(hyper):
if hasattr(hyper, "size"):
return hyper.size
elif isinstance(hyper, (list, tuple)):
return len(hyper)
elif hasattr(hyper, "rvs"):
return 10 # heuristic
else:
return 1
assert f("string") == 1 |
benchmark_functions_edited/f3224.py | def f(n):
if n == 0 or n == 1:
return 1
else:
return f(n-1) + f(n-2)
assert f(5) == 8 |
benchmark_functions_edited/f13303.py | def f(obj, quiet=False):
# Try "2" -> 2
try:
return int(obj)
except (ValueError, TypeError):
pass
# Try "2.5" -> 2
try:
return int(float(obj))
except (ValueError, TypeError):
pass
# Eck, not sure what this is then.
if not quiet:
raise TypeError("Can not translate %s to an integer." % (obj))
return obj
assert f(0.0) == 0 |
benchmark_functions_edited/f4960.py | def f(lwup_sfc, lwup_sfc_clr, lwdn_sfc, lwdn_sfc_clr):
return lwup_sfc - lwup_sfc_clr - lwdn_sfc + lwdn_sfc_clr
assert f(0, 0, 0, 0) == 0 |
benchmark_functions_edited/f5400.py | def f(singles, doubles):
r = float(singles)/doubles
return doubles*(.5*r**2 + r**3 + .24*r**4)
assert f(0, 3) == 0 |
benchmark_functions_edited/f520.py | def f(myList):
return myList[0]**3-1
#return (myList[1]+1)**(1/3)
assert f([1, 2]) == 0 |
benchmark_functions_edited/f7100.py | def f(days: list) -> int:
progress = 0
for index, day in enumerate(days):
if index+1 < len(days):
progress += 1 if day < days[index+1] else 0
return progress
assert f(
[100, 100, 100, 100, 100, 100, 100, 100, 100, 90, 90, 90, 90, 90, 90, 90, 90, 90]) == 0 |
benchmark_functions_edited/f12753.py | def f(adapters):
adapters.append(0)
adapters.sort()
combinations = dict.fromkeys(adapters, 0)
combinations[0] = 1
for adapter in adapters:
for diff in range(1, 4):
if adapter + diff in adapters:
combinations[adapter + diff] += combinations[adapter]
return combinations[adapters[-1]]
assert f(
[16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4]) == 8 |
benchmark_functions_edited/f3642.py | def f(n):
return n[0][0]
assert f([[2, 0], 0]) == 2 |
benchmark_functions_edited/f4585.py | def f(input_list):
if len(input_list) != 0:
return sum(input_list)/len(input_list)
else:
return 0
assert f([1,2,3,4,5]) == 3 |
benchmark_functions_edited/f6105.py | def f(x, y):
if y > x:
x, y = y, x
r = x % y
if r == 0:
return y
else:
result = f(y, r)
return result
assert f(8, 10) == 2 |
benchmark_functions_edited/f2552.py | def f(s1, s2):
return sum(s1[i] == s2[i] for i in range(min(len(s1), len(s2))))
assert f(
"A",
"G",
) == 0 |
benchmark_functions_edited/f11970.py | def f(value, bins):
for index, bin in enumerate (bins):
# assumes bins in increasing order
if value < bin:
return index-1
print (' overflow ! ', value , ' out of range ' , bins)
return bins.size-2
assert f(-1, [-1, 0, 1]) == 0 |
benchmark_functions_edited/f1096.py | def f(x, y):
return 1 - (1-x) * (1-y)
assert f(1, 0) == 1 |
benchmark_functions_edited/f9403.py | def f(limbs):
n = 0
c = 0
shift = 0
mask = (1 << 30) - 1
for i in range(9):
n += ((limbs[i] & mask) + c) << shift
c = limbs[i] >> 30
shift += 30
return n
assert f(bytes([0, 0, 0, 0, 0, 0, 0, 0, 0])) == 0 |
benchmark_functions_edited/f9600.py | def f(p_jugada, p_total):
if p_jugada == p_total:
p_jugada = 0
return p_jugada
assert f(1, 0) == 1 |
benchmark_functions_edited/f7149.py | def f(p,q):
same = 0
for i in p:
if i in q:
same += 1
n = same
vals = range(n)
distance = sum(abs(p[i] - q[i]) for i in vals)
return distance
assert f(
[1, 3, 5],
[1, 3, 5]
) == 0 |
benchmark_functions_edited/f1429.py | def f(acc_index):
return int(acc_index[0:4])
assert f("0000-00000") == 0 |
benchmark_functions_edited/f10236.py | def f(c, freq, ref_freq):
return ((freq - ref_freq[c]) ** 2 / ref_freq[c] if c in ref_freq else
0 if c in ('\n', '\'', '"', ',', '-', '.', '?', '!', '-') else
1)
assert f(1, 0.3, {1: 0.3}) == 0 |
benchmark_functions_edited/f2033.py | def f(l):
# warning, pass-by-ref so WILL modify input arg
return l.pop() if l[-1] >= l[0] else l.pop(0)
assert f([3, 2, 3, 2, 3, 2, 1, 1, 2, 8]) == 8 |
benchmark_functions_edited/f11859.py | def f(u1, u2):
# utility function value generation
diff = u2 - u1
y = 1*(diff > 0.)
#p = probit_link_func(3*diff)
#y = bernoulli.rvs(p)
return y
assert f(200, 100) == 0 |
benchmark_functions_edited/f3889.py | def f(conf_mtx):
[tp, fp], [fn, tn] = conf_mtx
r = tn + fp
return fp / r if r > 0 else 0
assert f(
[[1, 0],
[0, 2]]) == 0 |
benchmark_functions_edited/f6946.py | def f(p):
return 2 * max(p - 0.5, 0)
assert f(1) == 1 |
benchmark_functions_edited/f9656.py | def f(labels, label_to_ix):
end_position = len(labels) - 1
for position, label in enumerate(labels):
if label == label_to_ix['<pad>']:
end_position = position
break
return end_position
assert f(['a', 'b', '<pad>'], {'a':0, 'b':1, '<pad>':2}) == 2 |
benchmark_functions_edited/f7327.py | def f(n, minn, maxn):
return max(min(maxn, n), minn)
assert f(5, 3, 5) == 5 |
benchmark_functions_edited/f11408.py | def f(number):
if not isinstance(number, int):
raise Exception('Enter an integer number to find the factorial')
if number == 1 or number == 2:
return 1
else:
return number * f(number - 1)
assert f(1) == 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.