file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f10552.py
|
def f(fromlist):
newest_timestamp = 0
for obj in fromlist:
if obj.newest_sample > newest_timestamp:
newest_timestamp = obj.newest_sample
return newest_timestamp
assert f( [] ) == 0
|
benchmark_functions_edited/f5154.py
|
def f(n):
total, k = 0, 1
while k <= n:
total, k = total + pow(k, 3), k + 1
return total
assert f(1) == 1
|
benchmark_functions_edited/f13006.py
|
def f(data, index):
if len(data) > index and data[index:index+1] == b"\x0a":
return 1
if len(data) > index+1 and data[index:index+2] == b"\x0d\x0a":
return 2
if len(data) > index and data[index:index+1] == b"\x0d":
return 1
return 0
assert f(b"\x0d\x0d\x0a", 5) == 0
|
benchmark_functions_edited/f11598.py
|
def f(string, sub_string):
#chnage this to one line
return sum([1 for i in range(0,len(string)) if string[i:i+len(sub_string)]==sub_string])
#return count
assert f(
'ABC',
'C'
) == 1
|
benchmark_functions_edited/f5889.py
|
def f(string):
spaces = 0
for c in string:
if c == " ":
spaces += 1
else:
break
return spaces
assert f( "a00001" ) == 0
|
benchmark_functions_edited/f4321.py
|
def f(data, keys=None):
l = 0
if keys == None:
keys = data.keys()
for i in keys:
l += len(data[i])
return l
assert f({"a": [1, 2, 3], "b": [4, 5, 6]}, ["b", "a"]) == 6
|
benchmark_functions_edited/f8554.py
|
def f(numbers: list):
total_sum = 0
divisor = 0
for number in numbers:
total_sum += number
divisor += 1
return total_sum / divisor
assert f([1, 2, 3]) == 2
|
benchmark_functions_edited/f7725.py
|
def f(x,N,sign_ptr,args):
out = 0
s = args[0] # N-1
#
out ^= (x&1)
x >>= 1
while(x):
out <<= 1
out ^= (x&1)
x >>= 1
s -= 1
#
out <<= s
return out
assert f(0, 1, 0, (1,)) == 0
|
benchmark_functions_edited/f4885.py
|
def f(collection):
# autoincrement id
if len(collection) == 0:
return 1
else:
return collection[-1]['id']+1
assert f([{'id': 1}]) == 2
|
benchmark_functions_edited/f13993.py
|
def f(results):
if not isinstance(results, list):
raise TypeError(
f'Expected type is list, but the argument type is {type(results)}'
)
exc = list(filter(
lambda result: isinstance(result, Exception), results)
)
return len(list(exc))
assert f([0]) == 0
|
benchmark_functions_edited/f6239.py
|
def f(X, Y, angle):
import numpy as np
theta = np.radians(angle % 360)
Z = np.abs((np.cos(theta) * X - np.sin(theta) * Y))
return Z
assert f(2, 0, 0) == 2
|
benchmark_functions_edited/f1463.py
|
def f(n):
if n <= 1:
return 1.0
else:
return n*f(n-1)
assert f(3) == 6
|
benchmark_functions_edited/f2556.py
|
def f(dictionary):
return list(dictionary.values())[0]
assert f({'a': 1, 'b': 2, 'c': 3, 'd': 4}) == 1
|
benchmark_functions_edited/f5625.py
|
def f(vertex, mergeDict):
while vertex in mergeDict:
vertex = mergeDict[vertex]
return vertex
assert f(5, {5: 2, 2: 1}) == 1
|
benchmark_functions_edited/f7459.py
|
def f(paths):
# This feature assumes that test files contain word "test
test_files_count = len([path for path in paths if "test" in path.lower()])
return test_files_count
assert f(["hello.py", "test_hello.py", "hello.ipynb"]) == 1
|
benchmark_functions_edited/f163.py
|
def f(inch: float) -> float:
return (inch * 2.54) * 10
assert f(0) == 0
|
benchmark_functions_edited/f1911.py
|
def f(f, x, h=0.001):
return (f(x+h) - f(x-h))/(2*h)
assert f(lambda x:x**2, 0, 0.001) == 0
|
benchmark_functions_edited/f13461.py
|
def f(n: int) -> int:
largest = 1
for d in range(2, n+1):
if n % d == 0:
largest = max(largest, d)
while n % d == 0:
n //= d
if d * d > n:
# n doesnt have at two non-trivial divisors here
break
# n may be 1 or prime by this point
largest = max(largest, n)
return largest
assert f(6) == 3
|
benchmark_functions_edited/f7654.py
|
def f(diffeq, y0, t, h): # uses docstring dydt = diffeq(y0, t) # get {dy/dt} at t
return y0 + h*dydt # Euler method on a vector @\lbl{line:vecop}@
assert f(lambda t,y: y**2, 1, 0, 0.25) == 1
|
benchmark_functions_edited/f3285.py
|
def f(X, Y):
radicand = sum([(x - y)**2 for x, y in zip(X, Y)])
return radicand**0.5
assert f([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]) == 0
|
benchmark_functions_edited/f535.py
|
def f(i: float, k: int) -> int:
return int(k * (i // k))
assert f(7, 2) == 6
|
benchmark_functions_edited/f5903.py
|
def f(n):
a = 1
b = 1
intermediate = 0
for x in range(n):
intermediate = a
a = a + b
b = intermediate
return a
assert f(0) == 1
|
benchmark_functions_edited/f11613.py
|
def f(n: int, base: int = 10) -> int:
digit_sum = 0
while n != 0:
n, digit = divmod(n, base)
digit_sum += digit
return digit_sum
assert f(0, 2) == 0
|
benchmark_functions_edited/f6948.py
|
def f(x, y, z):
result = x
if y > result:
result = y
if z > result:
result = z
return result
assert f(3, 1, 2) == 3
|
benchmark_functions_edited/f6738.py
|
def f(posn1, posn2):
distX = (posn1[0] - posn2[0]) ** 2
distY = (posn1[1] - posn2[1]) ** 2
return (distX + distY) ** 0.5
assert f( (1,0), (0,0) ) == 1
|
benchmark_functions_edited/f10061.py
|
def f(initVal, exp):
val = initVal
if val > 0:
val = val ** exp
if val < 0:
val *= -1
val = val ** exp
val *= -1
return val
assert f(0, -1) == 0
|
benchmark_functions_edited/f13007.py
|
def f(prec, rec, beta=1):
if prec + rec == 0:
return 0
else:
return (1 + beta ** 2) * prec * rec / (beta ** 2 * prec + rec)
assert f(0, 0, 2) == 0
|
benchmark_functions_edited/f7029.py
|
def f(valuation, base):
factor = 1
integer = 0
for i in range(len(valuation)):
integer += factor * valuation[i]
factor *= base
return integer
assert f( [0, 0, 0, 0, 0, 0, 0, 0], 3) == 0
|
benchmark_functions_edited/f6858.py
|
def f(l, pixelwidth):
try:
return l / pixelwidth
except (TypeError, ZeroDivisionError):
return l
assert f(0, 1000) == 0
|
benchmark_functions_edited/f10585.py
|
def f(example, num_partitions, eval_fraction, all_ids):
del num_partitions
example_id = example[0]
eval_range = int(len(all_ids) * eval_fraction)
for i in range(eval_range):
if all_ids[i] == example_id:
return 0
return 1
assert f(
(9, "a", "b", "c"), 1, 0.25, range(100)) == 0
|
benchmark_functions_edited/f14428.py
|
def f(value, arg):
value = int(value)
boundary = int(arg)
if value > boundary:
return boundary
else:
return value
assert f(5, 2) == 2
|
benchmark_functions_edited/f13127.py
|
def f(CI_lower, CI_upper, value):
if value < CI_lower:
return -1
elif value > CI_upper:
return 1
else:
return 0
assert f(3, 5, 5) == 0
|
benchmark_functions_edited/f9168.py
|
def f(x,y,p1,p2):
tmp = p1*x + p2*y
output = tmp
return output
assert f(1, 2, 0, 1) == 2
|
benchmark_functions_edited/f6485.py
|
def f(array):
# Sets only have distinct values
# and creating a set from a list has a good time complexity, as it uses hash tables
return len(set(array))
assert f([1, 2, 3, 4, 5, 1]) == 5
|
benchmark_functions_edited/f9759.py
|
def f(vals):
n = len(vals)
sorted_vals = sorted(vals)
if n % 2 == 0:
return (sorted_vals[n // 2] + sorted_vals[n // 2 - 1]) / 2
else:
return sorted_vals[n // 2]
assert f(list(range(11))) == 5
|
benchmark_functions_edited/f8098.py
|
def f(number):
return number * number * number
assert f(1) == 1
|
benchmark_functions_edited/f12219.py
|
def f(s, min_val, max_val):
return max(min(s, max_val), min_val)
assert f(-1.5, 0, 1) == 0
|
benchmark_functions_edited/f2971.py
|
def f(x):
return x[0](*(x[1:]))
assert f(
(lambda x: x, 4)
) == 4
|
benchmark_functions_edited/f4700.py
|
def f(block, n, blocksize=4) -> int:
return block >> (blocksize-n) & 0b1
assert f(0b1111, 3) == 1
|
benchmark_functions_edited/f2479.py
|
def f(hms):
h, m, s = map(float, hms.split(":"))
return h * 60. ** 2 + m * 60. + s
assert f("00:00:00") == 0
|
benchmark_functions_edited/f11361.py
|
def f(n, factors_d, i):
if n == 0:
return 0
if i < 0:
return n
return f(n, factors_d, i-1) - f(n // factors_d[i], factors_d, i-1)
assert f(0, [1, 1, 1], 2) == 0
|
benchmark_functions_edited/f10553.py
|
def f(ranks):
return sum([1/v for v in ranks])/len(ranks)
assert f([1 for _ in range(1000)]) == 1
|
benchmark_functions_edited/f14197.py
|
def f(content, offset, byte, length=1):
for i in range(length-1):
if content[offset + i:offset + i+1] != byte:
raise ValueError(("Expected byte '0x%s' at offset " +
"0x%x but received byte '0x%s'.") % (byte.hex(), offset+i,
content[offset + i:offset + i+1].hex()))
return offset + length
assert f(b'\x00\x00\x00\x00', 0, b'\x00') == 1
|
benchmark_functions_edited/f10589.py
|
def f(item):
if isinstance(item, str):
return len(item)
elif isinstance(item, list):
return sum(f(elem) for elem in item)
elif isinstance(item, dict):
return f(list(item.values()))
else:
return len(str(item))
assert f(["1", 1]) == 2
|
benchmark_functions_edited/f4188.py
|
def f(c):
if len(c) == 1 and c.isdigit():
return int(c)
return 0
assert f("\n") == 0
|
benchmark_functions_edited/f12315.py
|
def f(event, event_attribute):
if event_attribute in event:
return event[event_attribute]
return None
assert f({'attr1': 3, 'attr2': 3, 'attr3': 5}, 'attr3') == 5
|
benchmark_functions_edited/f5061.py
|
def f(num):
rev = 0
while num > 0:
rev = (rev * 10) + (num % 10)
num //= 10
return rev
assert f(1000) == 1
|
benchmark_functions_edited/f10128.py
|
def f(padding, kernel):
if padding == "valid":
return 0
elif padding == "same":
return kernel // 2
elif padding == "full":
return kernel - 1
raise ValueError("accepted paddings are 'valid', 'same' or 'full', found " +
padding)
assert f("full", 2) == 1
|
benchmark_functions_edited/f996.py
|
def f(x, minn, maxx):
return max(minn, min(maxx, x))
assert f(2, 2, 3) == 2
|
benchmark_functions_edited/f6252.py
|
def f(x):
if isinstance(x, tuple):
if len(x) == 1:
return x[0]
return x
assert f((1,)) == 1
|
benchmark_functions_edited/f7795.py
|
def f(risk):
_index = int(risk)
return _index
assert f(0) == 0
|
benchmark_functions_edited/f378.py
|
def f(x):
return x % 2 == 0
assert f(3) == 0
|
benchmark_functions_edited/f13367.py
|
def f(obj, default=0):
return int(obj) if obj else default
assert f(u"1") == 1
|
benchmark_functions_edited/f12705.py
|
def f(total_axis: int, axis: int):
if axis < 0:
return total_axis + axis
else:
return axis
assert f(5, -5) == 0
|
benchmark_functions_edited/f13798.py
|
def f(num_matches, num1, num2):
denom = num1 + num2 - num_matches
if denom == 0:
return 0
return num_matches / denom
assert f(1, 1, 1) == 1
|
benchmark_functions_edited/f25.py
|
def f(x):
return x # comment
assert f(1) == 1
|
benchmark_functions_edited/f10641.py
|
def f(fwhm):
shift = fwhm
n = 0
while shift < 1.:
n += 1
shift = fwhm * 10 ** n
return n + 1
assert f(2.5) == 1
|
benchmark_functions_edited/f14180.py
|
def f(values):
generator = [0x7d52fba40bd886, 0x5e8dbf1a03950c, 0x1c3a3c74072a18, 0x385d72fa0e5139, 0x7093e5a608865b] # new generators, 7 bytes
chk = 1
for value in values:
top = chk >> 55 # 25->55
chk = ((chk & 0x7fffffffffffff) << 5) ^ value # 0x1ffffff->0x7fffffffffffff
for i in range(5):
chk ^= generator[i] if ((top >> i) & 1) else 0
return chk
assert f(b'') == 1
|
benchmark_functions_edited/f11512.py
|
def f(ls):
if not len(ls):
return 0
write_idx = 0
for idx, elt in enumerate(ls):
if idx > write_idx and elt != ls[write_idx]:
write_idx += 1
ls[write_idx] = elt
return write_idx + 1
assert f(sorted([1, 1, 1, 1])) == 1
|
benchmark_functions_edited/f14096.py
|
def f(n, l):
d = [0] * n
# at position x, store length of maximal increasing subsequence ending in x
for i, x in enumerate(l):
try:
d[x] = 1 + max(d[j] for j in range(x))
except ValueError: # max does not accept empty sequence
d[0] = 1
return max(d)
assert f(3, [0, 2, 1]) == 2
|
benchmark_functions_edited/f6091.py
|
def f(title):
score = 0
if 'python' in title:
score += 2
if title in {'Senior', 'Sr.', 'senior', 'sr.'}:
score -= 2
return score
assert f('Engineer') == 0
|
benchmark_functions_edited/f3139.py
|
def f(line, start=0):
shortline = line.rstrip()
return len(shortline)
assert f('1234\t ') == 4
|
benchmark_functions_edited/f4866.py
|
def f(n: int, k: int, p: int) -> int:
if k == 0:
return 1
tmp = f(n, k // 2, p) ** 2
return tmp % p if k % 2 == 0 else tmp * n % p
assert f(2, 1, 5) == 2
|
benchmark_functions_edited/f8286.py
|
def f(val, bits):
if (val & (1 << (bits - 1))) != 0: # if sign bit is set
val = val - (1 << bits) # compute negative value
return val # return positive value as is
assert f(0b00000001, 16) == 1
|
benchmark_functions_edited/f5760.py
|
def f(job_id):
try:
object_id = int(job_id.split("_")[-1])
return object_id
except ValueError:
return None
assert f("12345_1") == 1
|
benchmark_functions_edited/f5519.py
|
def f(y0, y1, x0, x1 ):
deltaX = float(x1) - float(x0)
deltaY = float(y1) - float(y0)
return deltaY/deltaX
assert f(5, 5, 1, 0) == 0
|
benchmark_functions_edited/f8729.py
|
def f(x):
if x == 'White':
return 1
elif x == 'Black':
return 2
elif x == 'Native American':
return 3
elif x == 'Asian':
return 4
else:
return 0
assert f('Asian') == 4
|
benchmark_functions_edited/f14111.py
|
def f(default, init_value, expected_type=None):
if init_value is None:
return default
if expected_type is not None and not isinstance(init_value, expected_type):
raise TypeError(f"Argument was of type {type(init_value)}, not {expected_type}")
return init_value
assert f("a", 1) == 1
|
benchmark_functions_edited/f5867.py
|
def f(predictions, labels, binary=False):
if binary:
return predictions
else:
return (predictions - labels) + 1
assert f(10, 10) == 1
|
benchmark_functions_edited/f10911.py
|
def f(n, largest_digit):
if n == 0: # base case
return largest_digit
else:
if n < 0: # convert negative n into positive if any
n = n * -1
if n % 10 > largest_digit:
largest_digit = n % 10
return f(int(n/10), largest_digit)
assert f(0, 0) == 0
|
benchmark_functions_edited/f6135.py
|
def f(mylist, item):
try:
idx = mylist.index(item)
except ValueError:
idx = -1
return idx
assert f([1, 2, 3, 4, 5], 4) == 3
|
benchmark_functions_edited/f8918.py
|
def f(ni, nj, agents, commcost):
n = len(agents)
if n == 1:
return 0
npairs = n * (n-1)
return 1. * sum(commcost(ni, nj, a1, a2) for a1 in agents for a2 in agents
if a1 != a2) / npairs
assert f(0, 1, [0], lambda a, b: 1) == 0
|
benchmark_functions_edited/f12959.py
|
def f(idx, n):
return idx * n - idx * (idx - 1) // 2
assert f(2, 2) == 3
|
benchmark_functions_edited/f3955.py
|
def f(lst):
avg = sum(lst) / len(lst)
avg_float_decimal = float("{0:.3f}".format(avg))
return avg_float_decimal
assert f([1, 2, 3]) == 2
|
benchmark_functions_edited/f13212.py
|
def f(rpm):
hz = rpm / 60
return (hz)
assert f(0) == 0
|
benchmark_functions_edited/f5250.py
|
def f(num):
try:
return float(num)
except:
return 0
assert f(0) == 0
|
benchmark_functions_edited/f5042.py
|
def f(data):
n = len(data)
if n < 1:
raise ValueError('mean requires at least one data point')
return sum(data)/float(n)
assert f([7]) == 7
|
benchmark_functions_edited/f2625.py
|
def f(obj, name, default=None):
return getattr(obj.__class__, name, default)
assert f(None, 'a', 0) == 0
|
benchmark_functions_edited/f5651.py
|
def f(m : float, v : float) -> float:
return (m * (v*v)) / 2
assert f(9.8, 0) == 0
|
benchmark_functions_edited/f13202.py
|
def f(wave, tau_v=1, alpha=1.0, **kwargs):
return tau_v * (wave / 5500)**(-alpha)
assert f(5500) == 1
|
benchmark_functions_edited/f12332.py
|
def f(pop, rate):
return rate * (7.86 * pop - 23.31 * pop ** 2 + 28.75 * pop ** 3 - 13.3 * pop ** 4)
assert f(0, 0.0000010) == 0
|
benchmark_functions_edited/f4149.py
|
def f(value, min_value, max_value):
return min(max_value, max(min_value, value))
assert f(-1, 0, 100) == 0
|
benchmark_functions_edited/f7965.py
|
def f(items, i):
for j, item in enumerate(items):
if j == i:
return item
assert f(range(1), 0) == 0
|
benchmark_functions_edited/f13962.py
|
def f(peak_ind, freq, prepeak):
offset = int(peak_ind - prepeak * freq)
return offset
assert f(5, 0.1, 2.5) == 4
|
benchmark_functions_edited/f1742.py
|
def f(_list):
return max(len(item) for item in _list if type(item) != int)
assert f(["", "", ""]) == 0
|
benchmark_functions_edited/f11473.py
|
def f(diff_egn, r, t, h):
k1 = h * diff_egn(r, t)
k2 = h * diff_egn(r + k1 / 2, t + h / 2)
k3 = h * diff_egn(r + k2 / 2, t + h / 2)
k4 = h * diff_egn(r + k3, t + h)
return r + k1 / 6 + k2 / 3 + k3 / 3 + k4 / 6
assert f(lambda x, y: x, 0, 0, 0) == 0
|
benchmark_functions_edited/f6844.py
|
def f(data, is_array, is_scalar):
if not is_array:
return data[0]
if is_scalar:
return [data[0]]
return data
assert f([1], False, True) == 1
|
benchmark_functions_edited/f1642.py
|
def f(a,b):
a = abs(a)
b = abs(b)
while a:
a, b = (b % a), a
return b
assert f(-15, -40) == 5
|
benchmark_functions_edited/f3185.py
|
def f(l, val):
try:
return l.index(val)
except ValueError:
return False
assert f(
[4, 5, 3, 1],
1
) == 3
|
benchmark_functions_edited/f724.py
|
def f(Vdc,Ppv,S,C):
dVdc = (Ppv - S.real)/(Vdc*C)
return dVdc
assert f(1,1,0,1) == 1
|
benchmark_functions_edited/f11764.py
|
def f(transcript: str) -> int:
counter = 0
for i in transcript:
if i != " ":
counter += 1
return counter
assert f("???") == 3
|
benchmark_functions_edited/f3204.py
|
def f(filename="", text=""):
with open(filename, mode='w', encoding='UTF8') as f:
chars = f.write(text)
return chars
assert f(
"foo.txt",
"some text"
) == 9
|
benchmark_functions_edited/f4164.py
|
def f( s, target ):
result = s.f( target )
if result == -1: result = len( s )
return result
assert f('string', 'g' ) == 5
|
benchmark_functions_edited/f8587.py
|
def f(entry):
if entry['funct'] == "Mitglieder" and (entry["firstName"].isdigit() or entry["lastName"].isdigit()):
return 1
return 0
assert f(
{
"firstName": "4",
"lastName": "Mitglieder",
"funct": "Mitglieder",
"year": "1990",
}
) == 1
|
benchmark_functions_edited/f4580.py
|
def f(request, param, default=None):
try:
return int(request.params[param])
except:
return default
assert f(None, '0', 3) == 3
|
benchmark_functions_edited/f3022.py
|
def f(lst, elem):
try:
return len(lst) - lst[::-1].index(elem) - 1
except:
return 0
assert f([1, 2, 3, 1, 2, 3], 3) == 5
|
benchmark_functions_edited/f7775.py
|
def f(x, thresh, fallback):
return x if (x and x > thresh) else fallback
assert f(None, 3, 2) == 2
|
benchmark_functions_edited/f7415.py
|
def f(msg_id,msg):
checksum = ((msg_id) & 0xFF) + ((msg_id >> 8) & 0xFF)
for i in range(0,len(msg),1):
checksum = (checksum + ord(msg[i])) & 0xFF
return checksum
assert f(0, "") == 0
|
benchmark_functions_edited/f7000.py
|
def f(dim_n, dim_p):
return dim_n * (dim_p - 1)
assert f(3, 2) == 3
|
benchmark_functions_edited/f4111.py
|
def f( x1, y1, x2, y2 ):
dist = ( ( float(x2) - float(x1) ) ** 2 + ( float(y2) - float(y1) ) **2 ) ** 0.5
return dist
assert f( 1, 1, 1, 1 ) == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.