file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f11803.py
def f(value: int, minimum: int=0, maximum: int=9) -> int: return minimum if value < minimum else maximum if value > maximum else value assert f(42) == 9
benchmark_functions_edited/f2749.py
def f(n): dico = {0:1, 1:1} for i in range(2, n+1): dico[i] = dico[i-1] + dico[i-2] return dico[n] assert f(0) == 1
benchmark_functions_edited/f4230.py
def f(N, k, l, m, dN, di, Omega): K = k**2 + l**2 + m**2 return ((N*(k**2 + l**2)) / (K * Omega)) * (dN/di) assert f(2, 1, 0, 0, 1, 1, 1) == 2
benchmark_functions_edited/f1152.py
def f(data: bytearray) -> int: return int.from_bytes(data, "big") assert f(bytes.fromhex("0004")) == 4
benchmark_functions_edited/f2060.py
def f(n): return 1 << ((n - 1).bit_length() - 1) assert f(12) == 8
benchmark_functions_edited/f5928.py
def f(A, K): A.sort() if A[len(A)-1] - A[0] - 2 * K > 0: return A[len(A)-1] - A[0] - 2 * K else: return 0 assert f([7, 8, 8], 2) == 0
benchmark_functions_edited/f4827.py
def f(inner, cohort_size): if inner % 2: return cohort_size - 1 - inner // 2 else: return inner // 2 assert f(0, 32) == 0
benchmark_functions_edited/f1942.py
def f(n: float) -> float: return -n * (n - 2) assert f(1) == 1
benchmark_functions_edited/f13987.py
def f(a, b): if type(a) is not int or type(b) is not int: raise TypeError('Input must be float type.') if b > a: return f(b, a) if a % b == 0: return b return f(b, a % b) assert f(1, 1) == 1
benchmark_functions_edited/f11248.py
def f(a, b): a = a.split('.') b = b.split('.') # Compare each individual portion of both version strings for va, vb in zip(a, b): ret = int(va) - int(vb) if ret: return ret # Fallback to comparing length last return len(a) - len(b) assert f('0.0.1.10', '0.0.1.9') =...
benchmark_functions_edited/f4831.py
def f(k, params): l = params[0] a = params[1] b = params[2] a4b2=a*a*a*a + b*b aak2=a*a*k*2 return l*(k*k + aak2 + a4b2) / (a4b2 + aak2) assert f(0, [1, 1, 1]) == 1
benchmark_functions_edited/f7027.py
def f(vacant_groups): vacant_groups = dict(sorted(vacant_groups.items(), key=lambda x: x[1])) minimum = list(vacant_groups.keys())[0] return minimum assert f( {1: 10, 2: 1, 3: 2, 4: 2, 5: 3, 6: 1, 7: 1, 8: 3, 9: 2}) == 2
benchmark_functions_edited/f11030.py
def f(seq1, seq2): return sum(1 for ch1, ch2 in zip(seq1, seq2) if ch1 != ch2) assert f('def', 'abc') == 3
benchmark_functions_edited/f7387.py
def f(n, minn, maxn): return max(min(maxn, n), minn) assert f(1, 1, 5) == 1
benchmark_functions_edited/f13263.py
def f(edicao): last_char = str(edicao)[-1] if last_char.isdigit(): return 0 else: return ord(last_char.lower()) - 96 assert f(164) == 0
benchmark_functions_edited/f7996.py
def f(val): rval = 0 for fragment in bytearray(val): rval <<= 8 rval |= fragment return rval assert f([1]) == 1
benchmark_functions_edited/f14366.py
def f(dikt, path): value = dikt for component in path.split("."): if component.isdigit(): value = value[int(component)] else: value = value[component] return value assert f( {'data': {'files': [1, 2, 3]}}, "data.files.2" ) == 3
benchmark_functions_edited/f8993.py
def f(m, n): if m == 0: return n+1 if n == 0: return f(m-1, 1) return f(m-1, f(m, n-1)) assert f(2, 2) == 7
benchmark_functions_edited/f10279.py
def f(expr, precision): return expr // precision * precision assert f(0, 0.1) == 0
benchmark_functions_edited/f13749.py
def f(word_a: str, word_b: str) -> int: if word_a == word_b: return 0 if word_a < word_b: return -1 return 1 assert f( 'foo', 'foo' ) == 0
benchmark_functions_edited/f271.py
def f(c): return 1 / 3 * (c + 1) * (c - 1) assert f(2) == 1
benchmark_functions_edited/f296.py
def f(a, b): return int(a == b) assert f(True, False) == 0
benchmark_functions_edited/f722.py
def f(pack, stub): return pack | (stub << 32) assert f(0, 0) == 0
benchmark_functions_edited/f11345.py
def f(lst): if len(lst) == 0: return None elif len(lst) == 1: return lst[0] elif all([entry is None for entry in lst]): return None return min([entry for entry in lst if entry is not None]) assert f([1, 3, 4, None, None]) == 1
benchmark_functions_edited/f7147.py
def f(value: str): try: res = int(value) except ValueError: try: res = float(value) except ValueError: res = value return res assert f(1) == 1
benchmark_functions_edited/f9798.py
def every (pred, seq): for i in seq: if not pred(i): return 0 return 1 assert f(lambda x: x % 2 == 0, [2, 4, 5, 8]) == 0
benchmark_functions_edited/f7895.py
def f(input_size, kernel_size, stride=1, padding=0, dilation=1, **kwargs): return (input_size-1)*stride - 2*padding + dilation*(kernel_size-1) + 1 assert f(4, 2, 2, 1, 2) == 7
benchmark_functions_edited/f5240.py
def f(colour1, colour2): dist_squared = sum((a - b) ** 2 for a, b in zip(colour1, colour2)) return dist_squared assert f( (255, 255, 255), (255, 255, 255) ) == 0
benchmark_functions_edited/f9483.py
def f(attrs, key): path = key.split('.') dict_ = attrs for part in path: if part.isdigit(): part = int(part) # Let it raise the appropriate exception dict_ = dict_[part] return dict_ assert f( {'a': {'b': 1, 'c': {'d': 2}}}, 'a.c.d' ) == 2
benchmark_functions_edited/f11733.py
def f(a:float, b:float) -> int: if a == b: return 1 else: return 0 assert f(1.0000001, 1) == 0
benchmark_functions_edited/f4151.py
def f(v): norm = 0 for n in v: norm += n**2 return norm**0.5 assert f( (0, 0) ) == 0
benchmark_functions_edited/f10108.py
def f(sample, xvals, pdfs): x1, x2 = xvals pdf1, pdf2 = pdfs grad = (pdf2 - pdf1) / (x2 - x1) dist = sample - x1 return grad * dist + pdf1 assert f(0.5, [0, 1], [0, 0]) == 0
benchmark_functions_edited/f2778.py
def f(a, b): diffs = ([x for x in a if x not in b] + [x for x in b if x not in a]) return len(diffs) assert f('abc', 'abcd') == 1
benchmark_functions_edited/f4944.py
def f(rnd: int) -> int: if rnd <= 20: return 2 if rnd <= 40: return 4 if rnd <= 60: return 6 return 8 assert f(4) == 2
benchmark_functions_edited/f179.py
def f(x, slope, offset): return slope * x + offset assert f(0, 1, 0) == 0
benchmark_functions_edited/f6277.py
def f(n, k): return int(((n - 2) * k ** 2 - (n - 4) * k) / (2)) assert f(1, 1) == 1
benchmark_functions_edited/f3237.py
def f(src) -> int: try: return int(src) except Exception: return 0 assert f({}) == 0
benchmark_functions_edited/f7630.py
def f(ft2): m2 = ft2 * (12 * 25.4 / 1000) ** 2 return m2 assert f(0) == 0
benchmark_functions_edited/f8113.py
def f(prediction): max_prob = prediction[0] if max_prob > prediction[1]: return 0 else: return 1 assert f( [0.7, 0.3]) == 0
benchmark_functions_edited/f4026.py
def f(char): if type(char) in [str, type(u"")]: return ord(char) else: return char assert f(1) == 1
benchmark_functions_edited/f11395.py
def f(length): # Every 24 bits (3 bytes) becomes 32 bits (4 bytes, 6 bits encoded per byte) # End is padded with '=' to make the result a multiple of 4 units, trailing = divmod(length, 3) if trailing: units += 1 return 4 * units assert f(1) == 4
benchmark_functions_edited/f3019.py
def f(listy): return (sum(listy)) assert f([-1, 2]) == 1
benchmark_functions_edited/f7173.py
def f(runs): return runs[0] if isinstance(runs, list) else\ runs if isinstance(runs, int) else\ int(runs.split(',',1)[0].split('-',1)[0]) assert f('5,15') == 5
benchmark_functions_edited/f238.py
def f(string): return int(string, 16) assert f(hex(0)) == 0
benchmark_functions_edited/f12964.py
def f(term_parameter): if (term_parameter == 'A') or (term_parameter == 'a'): return 0 elif (term_parameter == 'B') or (term_parameter == 'b'): return 1 elif (term_parameter == 'C') or (term_parameter == 'c'): return 2 elif (term_parameter == 'D') or (term_parameter == 'd'): return 3 ret = int(term_paramet...
benchmark_functions_edited/f11830.py
def f(value): try: return value[0] except (TypeError, IndexError): return value assert f([1, 2, 3]) == 1
benchmark_functions_edited/f9646.py
def f(barometric_pressure, sea_level_pressure): # https://www.weather.gov/media/epz/wxcalc/pressureAltitude.pdf return 44307.69396 * (1 - pow((barometric_pressure / sea_level_pressure), 0.190284)) assert f(900, 900) == 0
benchmark_functions_edited/f1701.py
def f(l): if " " in str(l): return 1 else: return 0 assert f(6) == 0
benchmark_functions_edited/f11858.py
def f(points): area = 0.5 * abs(points[0][0] * points[-1][1] - points[0][1] * points[-1][0]) for i in range(len(points) - 1): area += 0.5 * abs(points[i][0] * points[i + 1][1] - points[i][1] * points[i + 1][0]) return area assert f( [(0,0), (2,0), (2,2), (0,2), (0,0)] ) == 4
benchmark_functions_edited/f13540.py
def f(arr1: list, arr2: list) -> int: count = 0 for i in range(len(arr2)): if arr2[i] == arr1[i]: count += 4 elif arr2[i] != arr1[i] and not len(arr2[i]) == 0: count -= 1 return count if count > 0 else 0 assert f( ["b", "c", "b", "a"], ["", "a", "a", "c"]) == 0
benchmark_functions_edited/f8853.py
def f(s): last_line = "" count = 0 for line in s.split("\n"): if len(line) > 0 and (len(last_line) == 0 or last_line == "\n"): count += 1 last_line = line return count assert f( "This is the first paragraph.\n\n \tThis is the second paragraph.\t\n") == 2
benchmark_functions_edited/f11649.py
def f(display_width: int, line: str) -> int: return display_width // 2 - len(line) // 2 assert f(20, "Hello") == 8
benchmark_functions_edited/f6414.py
def f(list_, value): try: return list_.index(value) except ValueError: list_.append(value) return len(list_) - 1 assert f(list([]), 5) == 0
benchmark_functions_edited/f3655.py
def f(listing): if 'meta' in listing and 'query_total' in listing['meta']: return listing['meta']['query_total'] assert f({'meta': {'query_total': 0}}) == 0
benchmark_functions_edited/f8594.py
def f(number_str, a, b): try: n = float(number_str) if a <= n <= b: return n else: return None except ValueError: return None assert f("0", 0, 20) == 0
benchmark_functions_edited/f11795.py
def f(nums): return max(set(nums), key=nums.count) assert f([1, 2, 3, 2, 3]) == 2
benchmark_functions_edited/f5401.py
def f(value): return int(float(value)) assert f(3.14) == 3
benchmark_functions_edited/f8605.py
def f(L): for i in L: if i % 2 == 0: return i raise ValueError('L does not contain an even number.') assert f( [2, 4, 6, 8, 9]) == 2
benchmark_functions_edited/f3534.py
def lsum (inlist): s = 0 for item in inlist: s = s + item return s assert f( [0,0] ) == 0
benchmark_functions_edited/f3615.py
def f(excel_column: str) -> int: return ord(excel_column.upper()) - 64 assert f('C') == 3
benchmark_functions_edited/f6817.py
def f(n): start_odd = n * (n - 1) + 1 row = [] for i in range(1, n + 1): row.append(start_odd + (i - 1) * 2) return sum(row) assert f(2) == 8
benchmark_functions_edited/f7906.py
def f(a, b): return abs(a[0] - b[0]) + abs(a[1] - b[1]) assert f((0, 0), (0, 0)) == 0
benchmark_functions_edited/f7270.py
def f(data): # business logic here # compare with history data in redis # get equipment status and send to heka #print ("data: %s" % (data) ) return data assert f(3) == 3
benchmark_functions_edited/f7148.py
def f(axes): if hasattr(axes, "get_zlim"): n = 3 else: n = 2 return n assert f(None) == 2
benchmark_functions_edited/f12462.py
def f(region, country_parameters): cost = ( region['network_cost'] + region['spectrum_cost'] + region['tax'] + region['profit_margin'] ) revenue = region['total_revenue'] if revenue > 0 and cost > 0: bcr = revenue / cost else: bcr = 0 return bcr...
benchmark_functions_edited/f102.py
def f(x): return x**3 - 2*x + 2 assert f(0) == 2
benchmark_functions_edited/f8231.py
def f(n): sum_squares = sum([x*x for x in range(1, n+1)]) square_sum = sum([x for x in range(1, n+1)])**2 return square_sum - sum_squares assert f(0) == 0
benchmark_functions_edited/f161.py
def f(x, A, B): return A * x + B assert f(1, 1, 0) == 1
benchmark_functions_edited/f10527.py
def f(node, tree_id, pos=1, level=0): node['tree_id'] = tree_id node['level'] = level node['left'] = pos for child in node.get('children', []): pos = f(child, tree_id, pos=pos + 1, level=level + 1) pos = pos + 1 node['right'] = pos return pos assert f( {'children': [ {'c...
benchmark_functions_edited/f3371.py
def f(window, *args, **kwargs): return float(sum(w[1] for w in window)) / len(window) assert f(list(enumerate(range(5)))) == 2
benchmark_functions_edited/f10592.py
def f(organization, no_teams, teams_and_members): team_names = teams_and_members.keys() for name in team_names: organization.create_team(name, permission="push") return no_teams assert f(None, 0, {}) == 0
benchmark_functions_edited/f789.py
def f(img): return len(img[0]) assert f( [ [1, 0, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1], [1, 0, 0, 1], ] ) == 4
benchmark_functions_edited/f7875.py
def f(argumentValues): if 1 in argumentValues: outcome = 1 else: outcome = 0 return outcome assert f( [0,1] ) == 1
benchmark_functions_edited/f1851.py
def f(x: int) -> int: assert isinstance(x, int) return max(min(x, 255), 0) assert f(-10) == 0
benchmark_functions_edited/f11377.py
def f(percentage, max_val): if 1 <= percentage <= max_val: out = percentage elif 0 <= percentage < 1: out = percentage * max_val else: raise ValueError( "percentage={} outside of [0,{}].".format(percentage, max_val)) return int(out) assert f(0, 1) == 0
benchmark_functions_edited/f5277.py
def f(v_k1, x_k, m_k1, m_k): return v_k1 + (x_k - m_k1) * (x_k - m_k) assert f(0, 0, 0, 0) == 0
benchmark_functions_edited/f11187.py
def f(vlv: bytes) -> int: output = 0 mask = 127 # 01111111 for count, byte in enumerate(vlv[::-1]): b = mask & byte # remove first bit c = b << (count*7) # move to correct position in 'bit string' output |= c # add to output return output assert f(b'\x00') == 0
benchmark_functions_edited/f11301.py
def f(a, b, ab): return ab / (a + b - ab) assert f(2, 0, 0) == 0
benchmark_functions_edited/f1666.py
def f(map): return len([x for x in map.values() if x]) assert f(dict()) == 0
benchmark_functions_edited/f6934.py
def f(event): if event[0][0] == 'relatedLinkClicked' and 'Related content' in event[0][1]: return event[1] return 0 assert f( [('relatedLinkClicked', 'Related content'), 1] ) == 1
benchmark_functions_edited/f1622.py
def f(x): return (x - 127.5) / 127.5 assert f(127.5) == 0
benchmark_functions_edited/f2039.py
def f(data, rec, arg): if rec is None: return 1 return 0 assert f({}, {}, {}) == 0
benchmark_functions_edited/f10182.py
def f(color): red = color[0] green = color[1] blue = color[2] alpha = 0 if len(color) == 4: alpha = color[3] return ((((red)) << 24) | # noqa: W504 (((green)) << 16) | # noqa: W504 (((blue)) << 8) | # noqa: W504 ((alpha))) # noqa: W504 assert f((0, 0, 0)) == 0
benchmark_functions_edited/f11526.py
def f(x, y): # choose the greater number if x > y: greater = x else: greater = y while True: if (greater % x == 0) and (greater % y == 0): lcm = greater break greater += 1 return lcm assert f(1, 2) == 2
benchmark_functions_edited/f4662.py
def f(nets): wire_count = 0 for net in nets: wire_count += net.wire_count() return wire_count assert f([]) == 0
benchmark_functions_edited/f6628.py
def f(symbol): if not symbol: return 0 for s in symbol: if not s.isalnum() and s != '_': return 0 return 1 assert f("abc_123_123") == 1
benchmark_functions_edited/f7200.py
def f(registers, opcodes): test_result = int(opcodes[1] == registers[opcodes[2]]) return test_result assert f( { 'a': 1, 'b': 1, 'c': 0 }, [ 'eqir', 1, 'a', 'b' ] ) == 1
benchmark_functions_edited/f5414.py
def f(iterable, pred, default=None): return next(filter(pred, iterable), default) assert f(range(10), lambda x: x == 3, 3) == 3
benchmark_functions_edited/f13174.py
def f(x, y, grid): neighbors = 0 c_y = [-1, -1, -1, 1, 1, 1, 0, 0] c_x = [-1, 1, 0, -1, 1, 0, -1, 1] for n in range(0, 8): if grid[(c_y[n]+y) % 8][(c_x[n]+x) % 8] > 0: neighbors += 1 return neighbors assert f(2, 2, [ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],...
benchmark_functions_edited/f6724.py
def f(n): if n < 2: return 1 res = 0 for i in range(n): res += f(i) * f(n - i - 1) return res assert f(2) == 2
benchmark_functions_edited/f7170.py
def f(index, size, doraise=True): if index < 0: index = size + index if doraise and not (0 <= index < size): raise IndexError('out-of-bound') return min(index, size) assert f(-1, 4) == 3
benchmark_functions_edited/f424.py
def f(cond, b): return cond and b() assert f(True, lambda: 0) == 0
benchmark_functions_edited/f5322.py
def f(a, d, n): sum_ = (n/2) * (2 * a + (n-1) * d) return sum_ assert f(1, 1, 2) == 3
benchmark_functions_edited/f13009.py
def f(dek_year: int) -> int: week_day = ( (1 + 5 * ((dek_year) % 4) + 4 * ((dek_year) % 100) + 6 * ((dek_year) % 400)) % 7 ) + 1 return week_day assert f(2029) == 3
benchmark_functions_edited/f11918.py
def f(arr: list) -> int: res = arr[0] # Initialization counter = 0 # Counter for i in range(len(arr)): if counter == 0: res = arr[i] counter = 1 elif res == arr[i]: counter += 1 else: counter -= 1 return res assert f(list([3, 4...
benchmark_functions_edited/f4973.py
def f(*args): return sum(args) & 0xFFFFFFFF assert f(0, 0, 0) == 0
benchmark_functions_edited/f13333.py
def f(rows): rank = 0 while rows: pivot_row = rows.pop() if pivot_row: rank += 1 lsb = pivot_row & -pivot_row for index, row in enumerate(rows): if row & lsb: rows[index] = row ^ pivot_row return rank assert f( # Singl...
benchmark_functions_edited/f8198.py
def f(state, t, dt, rhs): k1 = rhs(t, state) k2 = rhs(t+dt/2, state + dt/2*k1) k3 = rhs(t+dt/2, state + dt/2*k2) k4 = rhs(t+dt, state + dt*k3) return state + dt/6*(k1 + 2*k2 + 2*k3 + k4) assert f(0, 0, 2, lambda t, x: x**2) == 0
benchmark_functions_edited/f13215.py
def f(value): if isinstance(value, list): if any(v < 0 for v in value): raise ValueError("The Values in the list must not be negative") else: return value else: if value < 0: raise ValueError("The Value must not be negative.") else: ...
benchmark_functions_edited/f7789.py
def f(_checkpoint_name): return int(_checkpoint_name.split("epoch=")[-1].split("_")[0].replace(".ckpt", "")) assert f( "epoch=4_v0.ckpt" ) == 4