file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f9313.py
def f(s, ret=0): if not isinstance(s, str): return int(s) elif s: if s[0] in "+-": ts = s[1:] else: ts = s if ts and all([_ in "0123456789" for _ in ts]): return int(s) return ret assert f(1.9) == 1
benchmark_functions_edited/f497.py
def f(m1,m2): return (m1*m2)**(3./5.)/(m1+m2)**(1./5.) assert f(0, 20) == 0
benchmark_functions_edited/f4276.py
def f(t): current_min = t[0] for v in t: if current_min > v: current_min = v return current_min assert f( [1, 2, 3] ) == 1
benchmark_functions_edited/f5429.py
def f(unit): unitSpacing = 19.050000 wxConversionFactor = 1000000 return unit*unitSpacing assert f(0) == 0
benchmark_functions_edited/f6258.py
def f(minutes): return (minutes // 60) % 60 assert f(3600) == 0
benchmark_functions_edited/f14308.py
def f(input_dim, kernel_size, stride, padding, transpose=False): if transpose: return (input_dim - 1) * stride + kernel_size - 2*padding return (2*padding + input_dim - kernel_size) // stride + 1 assert f(10, 3, 2, 0) == 4
benchmark_functions_edited/f13989.py
def f(f, x, h): x = float(x) h = float(h) D = (f(x) - f(x - h)) / h return D assert f(lambda x: 2 * x**2, 1, 2) == 0
benchmark_functions_edited/f748.py
def f(val: int, bitNo: int) -> int: return (val >> bitNo) & 1 assert f(0b00001101, 0) == 1
benchmark_functions_edited/f8645.py
def f(criterion, frRow, exRow): t = criterion['transform'] q = criterion['QLabel'] return abs(t[frRow[q]] - t[exRow[q]]) / max(t.values()) assert f( {'transform': {'one': 1, 'two': 2}, 'QLabel': 'one'}, {'one': 'one', 'two': 'two'}, {'one': 'one', 'two': 'two'} ) == 0
benchmark_functions_edited/f13094.py
def f(specstr, sep=','): num_seps = 0 brace_depth = 0 for s in specstr: if s == sep and brace_depth == 0: num_seps += 1 elif s == '(': brace_depth += 1 elif s == ')': brace_depth -= 1 return num_seps assert f('foo(bar,baz)') == 0
benchmark_functions_edited/f8363.py
def f(index): return 2 * index + 1 assert f(4) == 9
benchmark_functions_edited/f14390.py
def f(a, m): if a < 0 or m <= a: a = a % m # From Ferguson and Schneier, roughly: c, d = a, m uc, vc, ud, vd = 1, 0, 0, 1 while c != 0: q, c, d = divmod(d, c) + (c,) uc, vc, ud, vd = ud - q * uc, vd - q * vc, uc, vc # At this point, d is the GCD, and ud*a+vd*m = d. # If d == 1, this means that ud is a inverse. assert d == 1 if ud > 0: return ud else: return ud + m assert f(1, 4) == 1
benchmark_functions_edited/f616.py
def f(register): return max(register.values()) assert f( {'a': -1, 'b': 2} ) == 2
benchmark_functions_edited/f7134.py
def f(a: int, b: int) -> int: if b == 0: return a return f(b, a % b) assert f(1, 1) == 1
benchmark_functions_edited/f12290.py
def f(lines, lineix): while lineix < len(lines): if lines[lineix].strip().startswith('/*'): # Only return this marker if the comment goes beyond this line if lines[lineix].strip().find('*/', 2) < 0: return lineix lineix += 1 return len(lines) assert f( ['a = /* 1 */ 2;', '/* 2 */'], 2) == 2
benchmark_functions_edited/f809.py
def f(name, offset): # print("{}".format(name)) return offset + 1 assert f( 'ADD', 0 ) == 1
benchmark_functions_edited/f8491.py
def f(p, q): return ((p[0] - q[0])**2 + (p[1] - q[1])**2 + (p[2] - q[2])**2)**0.5 assert f( (1, 1, 1), (1, 1, 1) ) == 0
benchmark_functions_edited/f10571.py
def f(terms1, terms2, sem_sim): sims = [] for t1 in terms1: for t2 in terms2: sim = sem_sim(t1, t2) if sim is not None: sims.append(sim) if not sims: return return round(sum(sims) / len(sims), 3) assert f({1, 2, 3}, {1, 2, 3}, lambda t1, t2: 0) == 0
benchmark_functions_edited/f4783.py
def f(k, h): assert h >= 0 return ((k**(h+1)) - 1) // (k - 1) assert f(4, 0) == 1
benchmark_functions_edited/f4670.py
def f(val): c = 1 while val * 2 > c: val = val ^ c c = c << 1 return val assert f(0b11111111111111111111111111111111111) == 0
benchmark_functions_edited/f469.py
def f(x, y): # traceback.print_stack() return x + y assert f(1, 0) == 1
benchmark_functions_edited/f4138.py
def f(values): values_sum = 0 for value in values: values_sum += value return values_sum / len(values) assert f([2, 3, 4]) == 3
benchmark_functions_edited/f1980.py
def f(length): return -(length % -4) assert f(0) == 0
benchmark_functions_edited/f6493.py
def f(seq): if len(seq) == 1: return 0 if seq[-1] == 0: return f(seq[:-1]) if seq[-1] == 1: return f(seq[:-1]) + 2 assert f(tuple([0, 0, 1, 0])) == 2
benchmark_functions_edited/f2508.py
def f(value): if value < 0: return -1 if value > 0: return 1 return 0 assert f(10) == 1
benchmark_functions_edited/f11559.py
def f(s): h = 0 for f in s: h = (h << 4) + ord(f.lower()) g = h & 0xf0000000 if g != 0: h |= g >> 24 h |= g return h & 0x7fffffff assert f(b"") == 0
benchmark_functions_edited/f3135.py
def f(tree): if isinstance(tree, list): return tree[0] else: return tree assert f([1, [2, [3, [], []], [4, [], []]], [5, [6, [], []], []]]) == 1
benchmark_functions_edited/f8058.py
def f(n): return n * (n + 1) / 2 assert f(3) == 6
benchmark_functions_edited/f7541.py
def f(a, b): intsize = len(set.intersection(a, b)) unionsize = len(set.union(a, b)) if unionsize == 0: return 1 else: return float(intsize) / float(unionsize) assert f(set(['a', 'b', 'c']), set([])) == 0
benchmark_functions_edited/f3166.py
def f(width): if isinstance(width, str): width = float(width) return width assert f(4 and 5) == 5
benchmark_functions_edited/f6566.py
def f(text): text = text.split() return len(text) assert f("Hello world") == 2
benchmark_functions_edited/f11596.py
def f(file): f=open(file) f.seek(0,2) size=f.tell() try: f.seek(-128,2) except: f.close() return 0 buf=f.read(3) f.close() if buf=="TAG": size=size-128 if size<0: return 0 else: return size assert f("/dev/null") == 0
benchmark_functions_edited/f1947.py
def f(x, y): return (x > y) - (x < y) assert f((1, 2), (1, 2)) == 0
benchmark_functions_edited/f6893.py
def f(b): assert isinstance(b, bytes) return int.from_bytes(b, 'big') assert f(bytes.fromhex('00000000000000')) == 0
benchmark_functions_edited/f6816.py
def f(num1, num2): for i in range(min(num1, num2), 0, -1): if (num1 % i == 0) and (num2 % i == 0): return i assert f(2, 3) == 1
benchmark_functions_edited/f1935.py
def f(value): return int(value) if value else 0 assert f("-0") == 0
benchmark_functions_edited/f9336.py
def f(l): for e in l: if len(e) > 0: return True return False assert f([]) == 0
benchmark_functions_edited/f2566.py
def f(mat): return len(mat[0]) assert f([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) == 3
benchmark_functions_edited/f10233.py
def f(params, scale=1): total_norm = 0.0 for p in params: if p.grad is not None: param_norm = (p.grad.detach().data / scale).norm(2) total_norm += param_norm.item() ** 2 total_norm = total_norm**0.5 return total_norm assert f([], 100) == 0
benchmark_functions_edited/f10787.py
def f(nested_dicts, path): value = nested_dicts for key in path.split("/"): if type(value) is dict: value = value[key] elif type(value) is list: value = value[int(key)] return value assert f( { "foo": [ {"bar": 1}, {"baz": 2}, {"bar": 3}, {"baz": 4}, {"bar": 5}, {"baz": 6}, ] }, "foo/2/bar" ) == 3
benchmark_functions_edited/f8159.py
def f(string): try: if string.isdigit(): result = int(string) else: result = round(float(string), 3) return result except (ValueError, AttributeError): return string assert f(2) == 2
benchmark_functions_edited/f6764.py
def f(x): n=str(x) if x >= 0: result=int(n[::-1]) return 0 if result > pow(2,31)-1 else result else: result=int("-"+n[1:][::-1]) return 0 if result < -pow(2,31) else result assert f(1563847413) == 0
benchmark_functions_edited/f11776.py
def f(x): if not x: return None if 0 in x: return 0 product = 1 for element in x: product *= element return product assert f([0,1,0]) == 0
benchmark_functions_edited/f3649.py
def f(l, base): return sum([d * (base**i) for i, d in enumerate(l)]) assert f([1, 1, 1], 2) == 7
benchmark_functions_edited/f9972.py
def f(arch): if arch == 'armeabi': return 6 elif arch == 'armeabi-v7a': return 7 elif arch in ['arm64-v8a', 'x86', 'x86_64']: return None else: raise Exception('Unknown arch: ' + arch) assert f('armeabi-v7a') == 7
benchmark_functions_edited/f157.py
def f(x): return( 2*x ) assert f(2) == 4
benchmark_functions_edited/f9170.py
def f(val): if val == 'True': formtd_val = True elif val == 'False': formtd_val = False elif val.isdigit(): formtd_val = int(val) else: formtd_val = val return formtd_val assert f('3') == 3
benchmark_functions_edited/f5005.py
def f(hand): return sum(hand.values()) assert f({}) == 0
benchmark_functions_edited/f11472.py
def f(string1, string2): # Pure Python implementation: no numpy tri_grams = set(zip(string1, string1[1:], string1[2:])) tri_grams = tri_grams.intersection(zip(string2, string2[1:], string2[2:])) return len(tri_grams) assert f(b"foo bar", b"foo") == 1
benchmark_functions_edited/f6067.py
def f(i, n): return n-i-1 assert f(0, 2) == 1
benchmark_functions_edited/f1684.py
def f(tam_win, tam_scr): dato_scr = (tam_scr-tam_win) / 2 return dato_scr assert f(5, 5) == 0
benchmark_functions_edited/f5067.py
def f(coll): # It is really frustrating that Python doesn't have this built in try: return coll[0] except TypeError: return next(iter(coll)) assert f((1, 2, 3)) == 1
benchmark_functions_edited/f12252.py
def f(yield_required): farm_hours = yield_required*1.2 labour_cost = farm_hours * 7 # wage return labour_cost assert f(0) == 0
benchmark_functions_edited/f5403.py
def f(x): if x < 0: return 0 return 1 assert f(-1000) == 0
benchmark_functions_edited/f9779.py
def f(nwater, ng): return (nwater * (nwater + ng) ** 2) / (1 + ng) ** 2 assert f(0, 0) == 0
benchmark_functions_edited/f2855.py
def f(data): try: return data.magnitude except AttributeError: return data assert f(3) == 3
benchmark_functions_edited/f8537.py
def f(x): def fib(n): if n < 0: raise Exception('No fibonacci number below 0') if n == 0 or n == 1: return 1 return fib(n-1) + fib(n-2) return fib(x) assert f(0) == 1
benchmark_functions_edited/f7535.py
def f(p, g, m = 255): if (p + g < m + 1) and (p + g > 0): return int(p + g) elif p + g <= 0: return 0 else: return m assert f(255, -255) == 0
benchmark_functions_edited/f5085.py
def f(project_object): try: if project_object['coa']: return 1 else: return 0 except: pass return 0 assert f(dict()) == 0
benchmark_functions_edited/f5773.py
def f(facts): return max( [ int(facts.get("ansible_processor_count", 0)), int(facts.get("ansible_processor_vcpus", 0)), ] ) assert f(dict()) == 0
benchmark_functions_edited/f4306.py
def f(input): if input <= 0: return input else: output = f(input - 1) return output assert f(2) == 0
benchmark_functions_edited/f11437.py
def f(t): # use on python scalars/pytorch scalars if isinstance(t, (float, int)): return t if hasattr(t, 'float'): t = t.float() # half not supported on CPU if hasattr(t, 'item'): return t.item() else: assert len(t) == 0 return t[0] assert f(2) == 2
benchmark_functions_edited/f9300.py
def f(pattern, line): size = len(line) for i in range(0, size): if pattern in line[i]: return i + 1 raise ValueError('\'' + pattern + '\' is not found in log files') assert f(r'benchmarking', [r'Benchmarking', r'benchmarking']) == 2
benchmark_functions_edited/f2690.py
def f(num): return len(str(num)) assert f(9999) == 4
benchmark_functions_edited/f11263.py
def f(total, coins): if total == 0: return 0 count = total for coin in coins: if total - coin >= 0: _count = f(total - coin, coins) if _count + 1 < count: count = _count + 1 return count assert f(70, [1, 10, 20, 50]) == 2
benchmark_functions_edited/f668.py
def f(g, a, p): return pow(g, a, p) assert f(2, 3, 5) == 3
benchmark_functions_edited/f13017.py
def f(i,j,k): if i == j + k: return -1 elif j == i + k or k == i + j: return 1 else: msg = "Possible Error: Indices ({},{},{})".format(i,j,k) print(msg) return 0 assert f(1,3,8) == 0
benchmark_functions_edited/f6632.py
def f(obj, ops, op): res = obj for o in reversed(ops): res = o.apply(res, op) return res assert f(1, [], 1) == 1
benchmark_functions_edited/f5776.py
def f(haystack: list, needle: str): for thing in haystack: if repr(thing) == needle: return thing raise IndexError(f'Not found: {needle}!') assert f( [1, 2, 3], '3', ) == 3
benchmark_functions_edited/f6559.py
def f(word): try: return int(word) except ValueError: try: return int(word.replace(',', '')) except ValueError: return 0 assert f('three') == 0
benchmark_functions_edited/f13153.py
def f(n): if n < 0: # if the integer in negative, we need to turn it to positive first. n = -n if n == 0: # if n == 0, means that the function had finished comparing the numbers. return n else: digit = n % 10 return max(f(n // 10), digit) assert f(281) == 8
benchmark_functions_edited/f3987.py
def f(values): for v in values: if v is None: continue return v return None assert f([None, 1, None, 2, None, 3]) == 1
benchmark_functions_edited/f4724.py
def f(postcrement: float) -> int: return (7, 6, 5, 4, 8, 0, 1, 2, 3)[int(postcrement) + 4] assert f(2.25) == 1
benchmark_functions_edited/f7381.py
def f(origin, p1_end, p2_end): ux, uy = (p1_end[0] - origin[0], p1_end[1] - origin[1]) vx, vy = (p2_end[0] - origin[0], p2_end[1] - origin[1]) return ux * vx + uy * vy assert f( (0, 0), (0, 0), (0, 0) ) == 0
benchmark_functions_edited/f11640.py
def f(total, x, y): longest = max(len(x), len(y)) if not longest: return 0 else: return total / longest assert f(100, [], []) == 0
benchmark_functions_edited/f11857.py
def f(auth_id=None, auth_token=None): if auth_id is not None and auth_token is not None: global AUTH_ID global AUTH_TOKEN AUTH_ID = auth_id AUTH_TOKEN = auth_token return 0 print("Function takes two arguments, auth_id and auth_token as strings") return None assert f('id', 'token') == 0
benchmark_functions_edited/f13319.py
def f(plist,x,x2=None): val = 0 if x2: for i in range(len(plist)): val += plist[i]*(pow(x2,i)-pow(x,i)) else: for i in range(len(plist)): val += plist[i]*pow(x,i) return val assert f( [1], 1 ) == 1
benchmark_functions_edited/f4109.py
def f(value): return int(round(65536 * value)) assert f(0.0) == 0
benchmark_functions_edited/f9500.py
def f(Dictionary, IndexPath): if IndexPath == []: return Dictionary else: return f(Dictionary[IndexPath[0]], IndexPath[1:]) assert f( {"a": 1, "b": {"c": 2, "d": 3}}, ["b", "d"] ) == 3
benchmark_functions_edited/f9223.py
def f(s): h = 0 for c in s: o = ord(c) if isinstance(c, str) else c h = (31 * h + o) & 0xFFFFFFFF return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000 assert f('') == 0
benchmark_functions_edited/f9152.py
def f(actuals: list, candidates: list, k: int) -> float: if len(candidates) > k: candidates = candidates[:k] return len(set(actuals).intersection(candidates)) / len(actuals) assert f( ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'], 4 ) == 1
benchmark_functions_edited/f14376.py
def f(typing_speed): assert isinstance( typing_speed, (int, float) ), f"typing_speed is neither int nor float, it is {type(typing_speed)}" cps = typing_speed * 5 / 60 return cps assert f(0) == 0
benchmark_functions_edited/f1003.py
def f(line: str) -> int: return len(eval(line)) assert f(r'"\\\""') == 2
benchmark_functions_edited/f12112.py
def f(stop, common, solution): count = sum(x == y for x, y in zip(common[:stop], solution[:stop])) return count assert f(1, [1,2,3,4], [1,1,1,2]) == 1
benchmark_functions_edited/f4257.py
def f(dct, names): if len(names) == 0: return dct return f(dct[names[0]], names[1:]) assert f({"a": 5}, ["a"]) == 5
benchmark_functions_edited/f6375.py
def f(file_path, line, linebreak="\n"): try: with open(file_path, "a") as file: file.write(line + linebreak) return 1 except: return 0 assert f( "test_data.csv", "a,b,c" ) == 1
benchmark_functions_edited/f12599.py
def f(poly): area = 0.0 p = poly[:] # close the polygon if p[0] != p[-1]: p.append(p[0]) for (x1, y1), (x2, y2) in zip(p, p[1:]): area += x1*y2 - y1*x2 area /= 2.0 return area assert f( [(0, 0), (2, 0), (2, 2), (0, 2), (0, 0)] ) == 4
benchmark_functions_edited/f7529.py
def f(predicate, seq): for x in seq: px = predicate(x) if px: return px assert f(callable, [min, 3]) == 1
benchmark_functions_edited/f12160.py
def f(a, b, c): return ((b[0] - a[0])*(c[1] - a[1]))-((c[0] - a[0])*(b[1] - a[1])) assert f([0,0],[1,1],[1,1]) == 0
benchmark_functions_edited/f11482.py
def f(rotor_setting, ring_num): if ring_num == 0: # special condition for first rotor? return 0 # Needs to be something different if rotor_setting == ring_num: return 1 else: return 0 assert f(1, 6) == 0
benchmark_functions_edited/f1866.py
def f(a, b): a, b = max(a, b), min(a, b) while b != 0: a, b = b, a % b return a assert f(17, 13) == 1
benchmark_functions_edited/f6563.py
def f(x,y,z,rin,rout): return ((z+rin+rout)**2+y**2+x**2+rout**2-rin**2)**2 - \ 4*rout**2*((z+rin+rout)**2+y**2) assert f(0, 0, 0, 1, 1) == 0
benchmark_functions_edited/f10047.py
def f(num): result = num * num # It is a good practice to always allocate calculated value to a local variable instead of chaining to return or another function return result assert f(3) == 9
benchmark_functions_edited/f13206.py
def f(keys, max_value): res = 0 for i, key in enumerate(reversed(keys)): res += key * (max_value ** i) return res # return int(np.sum(keys * (max_value ** np.linspace(0, len(keys)-1, len(keys))))) assert f([], 10) == 0
benchmark_functions_edited/f12103.py
def f(TPR, TNR): return TPR+TNR-1 assert f(0.5, 0.5) == 0
benchmark_functions_edited/f11463.py
def f(obj, iterable): index = 0 for element in iterable: if element is obj: return index index += 1 raise ValueError('object not found in the iterable') assert f(3, [1,2,3]) == 2
benchmark_functions_edited/f2919.py
def f(user): global _currentUser _currentUser = user return _currentUser assert f(3) == 3
benchmark_functions_edited/f14491.py
def f(ii): jj = 1 while ((ii & 1) > 0): ii >>= 1 jj += 1 #print(ii, "{0:b}".format(ii), jj, (ii&1)>0) return jj-1 assert f(127) == 7
benchmark_functions_edited/f12148.py
def f(a, b): count_dict = {} for n in a: if n in count_dict.keys(): count_dict[n] +=1 else: count_dict[n] = 1 for n in b: if n in count_dict.keys(): count_dict[n] -=1 else: count_dict[n] = -1 return sum(map(abs, count_dict.values())) assert f(list("codewars"), list("code")) == 4
benchmark_functions_edited/f3253.py
def f(H, D, gamma, c): return gamma * H * D + 2 * H * c assert f(0, 0, 1, 1) == 0