file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f8065.py
def f(s: str) -> int: count = 0 m = {'(': 1, ')': -1} for token in s: count += m[token] if count < 0: return 0 return 0 if count else 1 assert f( '())' ) == 0
benchmark_functions_edited/f279.py
def f(a, b): return f(b, a % b) if b else a assert f(4, 12) == 4
benchmark_functions_edited/f5198.py
def f(choice): try: resp = choice[0] except IndexError: resp = '' pass return resp assert f((1,)) == 1
benchmark_functions_edited/f7884.py
def f(data): if len(data)==0: return 0 return sum(data) / float(len(data)) assert f([]) == 0
benchmark_functions_edited/f1286.py
def f(i, j): assert i in (0,1) assert j in (0,1) return i*j assert f(1,1) == 1
benchmark_functions_edited/f8206.py
def f(hand): hand_len = 0 for frequency in hand.values(): hand_len += frequency return hand_len assert f({}) == 0
benchmark_functions_edited/f13909.py
def f(x_dict, y_dict): x = x_dict['X_2'] y = y_dict['X_2'] dist = 0 for idx_time in range(9): sim_hist = x[idx_time] data_hist = y[idx_time] for idx_el in range(len(data_hist)): a = data_hist[idx_el] b = sim_hist[idx_el] dist += abs(a - b) return dist assert f( {'X_2': [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24], [25, 26, 27]]}, {'X_2': [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21], [22, 23, 24], [25, 26, 27]]}) == 0
benchmark_functions_edited/f139.py
def f(x): return (x + 1)**(1.0/3.0) assert f(0) == 1
benchmark_functions_edited/f2544.py
def f(record): return record['end_idx'] - record['start_idx'] assert f( {'start_idx': 0, 'end_idx': 5} ) == 5
benchmark_functions_edited/f4581.py
def f(s): return s[len(s.rstrip()):].count('\n') assert f("\n\n\n\n") == 4
benchmark_functions_edited/f9628.py
def f(dir_list): int_list = [] for directory in dir_list: try: int_list.append(int(directory)) except ValueError: pass if not int_list: return None return max(int_list) assert f(list('12')) == 2
benchmark_functions_edited/f10224.py
def f(raw_file): lines = raw_file.split("\n") start = None end = None for idx, line in enumerate(lines): if "---" in line and start is None: start = idx elif "---" in line and start is not None: return idx assert f( ) == 3
benchmark_functions_edited/f3800.py
def f(sigma_small, sigma_large): return int((sigma_large / sigma_small)**2.) assert f(1, 2) == 4
benchmark_functions_edited/f14103.py
def f(a, b): def num_set_bits(n): count = 0 while n != 0: last_bit = n & 1 if last_bit == 1: count += 1 n = n >> 1 return count return num_set_bits(a ^ b) assert f(31, 14) == 2
benchmark_functions_edited/f11523.py
def f(x, n): return (x + n - 1) // n assert f(9, 3) == 3
benchmark_functions_edited/f10400.py
def f(m, n): if n == 0: result = m else: result = f(n, m % n) return result assert f(12, 6) == 6
benchmark_functions_edited/f5547.py
def f(point_a, point_b): return (point_a[0] - point_b[0]) ** 2 + (point_a[1] - point_b[1]) ** 2 assert f( (2, 0), (0, 2) ) == 8
benchmark_functions_edited/f13542.py
def f(event, possibilities): if len(possibilities) == 0: return 0 matches = 0 for possibility in possibilities: if event == possibility: matches += 1 return matches / len(possibilities) assert f(1, []) == 0
benchmark_functions_edited/f322.py
def f(x): return (5 * x) + x**2 - (0.5 * x**3) assert f(0) == 0
benchmark_functions_edited/f11949.py
def f(nums): if not nums: return 0 max_ = 0 end = nums[0] for num in nums: max_ = max(num, max_ + num) end = max(end, max_) return end assert f(None) == 0
benchmark_functions_edited/f3416.py
def f(rec): info = rec["product"]["attributes"] return float(info.get("memory").split()[0].replace(",", "")) assert f( {"product": {"attributes": {"memory": "2 GB Memory"}}} ) == 2
benchmark_functions_edited/f3497.py
def f(i): return (1 if i > 0 else -1 if i < 0 else 0) assert f(10) == 1
benchmark_functions_edited/f8770.py
def f(seq): if hasattr(seq, '__len__'): return len(seq) return sum(1 for i in seq) assert f(iter(s for s in "hello")) == 5
benchmark_functions_edited/f12429.py
def f(laid_card, turns_to_wait=0): value = laid_card[1] if value == '4': turns_to_wait += 1 return turns_to_wait assert f(('6', '7')) == 0
benchmark_functions_edited/f11508.py
def f(motor_output, coach_dead_zone): if motor_output == 0: return 0 elif motor_output > 0: return (motor_output**3 + motor_output)/2 else: return (motor_output**3 - motor_output)/2 assert f(0, 0.1) == 0
benchmark_functions_edited/f11899.py
def f(deferredImages, timeTracker): return len(deferredImages)*timeTracker['timePerSample'] assert f(['test1', 'test2', 'test3'], {'timePerSample':0}) == 0
benchmark_functions_edited/f2080.py
def f(w, x, order=2): result = 2 * w[0] return result assert f( [1, 1], 1, ) == 2
benchmark_functions_edited/f7356.py
def f(width): # assert width <= 0.01 assert width >= 0 return 0.01 - width assert f(0.01) == 0
benchmark_functions_edited/f3789.py
def f(nums): expected_sum = len(nums)*(len(nums)+1)//2 actual_sum = sum(nums) return expected_sum - actual_sum assert f([0]) == 1
benchmark_functions_edited/f12789.py
def f(e03150, e03300, IRADC_credit_c, IRADC_credit_rt, iradctc): # calculate refundable credit amount tot_retirement_contributions = e03150 + e03300 if IRADC_credit_rt > 0.: iradctc = min(tot_retirement_contributions * IRADC_credit_rt, IRADC_credit_c) else: iradctc = 0. return (iradctc) assert f(0, 0, 0, 0, 2000) == 0
benchmark_functions_edited/f7005.py
def f(x): x = (x & 0x555555) + ((x & 0xaaaaaa) >> 1) x = (x & 0x333333) + ((x & 0xcccccc) >> 2) x = (x + (x >> 4)) & 0xf0f0f return (x + (x >> 8) + (x >> 16)) & 0x1f assert f(0b00000000000000000000000000000000) == 0
benchmark_functions_edited/f1958.py
def f(v0, v1): return v0[0] * v1[1] - v0[1] * v1[0] assert f( (-1, 0), (1, 0) ) == 0
benchmark_functions_edited/f9252.py
def f(x, phi): for _phi in phi: if _phi[1] == x: return _phi[0] raise Exception('Could not find inverse transformation') assert f(0, [(0, 0), (1, 1), (2, 3)]) == 0
benchmark_functions_edited/f1174.py
def f(b): return 0 if b==0 else (1 if b&1==1 else 0) + f(b>>1) assert f(6) == 2
benchmark_functions_edited/f14039.py
def f(substring, string): count = 0 start = 0 while start < len(string): start = string.find(substring, start) if start == -1: break else: count += 1 start += len(substring) return count assert f( "foo", "bar", ) == 0
benchmark_functions_edited/f8285.py
def f(blocklst,object): ls=[] for el in blocklst: ls.append(el[0].upper()) return ls.index(object.upper()) assert f( [("TITLE", "TITLE"), ("HARMONICITY", "HARMONICITY"), ("RISK MEASURE", "RISK MEASURE"), ("SOLUTION ALGORITHM", "SOLUTION ALGORITHM"), ("NUMBER OF SCENARIOS", "NUMBER OF SCENARIOS"), ("DATA", "DATA")], "DATA") == 5
benchmark_functions_edited/f11742.py
def f(x): if isinstance(x, list): if callable(x[0]): return x[0](*map(evaluate, x[1:])) elif x[0] == 'if': return f(x[2] if f(x[1]) else x[3]) else: raise ValueError("invalid prefix: '{}'".format(x[0])) else: return x assert f(['if', True, 1, lambda: 2]) == 1
benchmark_functions_edited/f6703.py
def f(measurements): windows = zip(measurements[1:], measurements[:-1]) increases = filter(lambda w: w[0] > w[1], windows) return len(list(increases)) assert f([199, 200, 208, 210, 200, 207, 240, 269, 260, 263]) == 7
benchmark_functions_edited/f9130.py
def f(state): return state[0] + 3 * state[1] + 9 * state[2] + 27 * state[3] + 81 * state[4] + 243 * state[5] + 729 * state[ 6] + 2187 * state[7] + 6561 * state[8] assert f( [1, 0, 0, 0, 0, 0, 0, 0, 0] ) == 1
benchmark_functions_edited/f9744.py
def f(vector): #LEFT if vector ==(-1, 0): return 0 #RIGHT if vector ==( 1, 0): return 1 #UP if vector ==( 0, 1) : return 2 #DOWN if vector ==( 0, -1) : return 3 return None assert f( (-1,0) ) == 0
benchmark_functions_edited/f11955.py
def f(value, array): index = 0 # search for the last array item that value is larger than for n in range(0,len(array)): if value >= array[n]: index = n+1 array.insert(index, value) return index assert f(2, [2,3]) == 1
benchmark_functions_edited/f7162.py
def f(x: bool, y: bool) -> float: return 1.0 if x and y else 0.0 assert f(1, 0) == 0
benchmark_functions_edited/f1400.py
def f(x): return ((x ^ 0xffff) + 1) & 0xffff assert f(0) == 0
benchmark_functions_edited/f8346.py
def f(_haystack, _needle, _offset=0): pos = _haystack.find(_needle, _offset) if pos == -1: return False return pos assert f('abcdef abcdef', 'a', 1) == 7
benchmark_functions_edited/f5183.py
def f(a, b): return b if a == 0 else f(b % a, a) assert f(25, 10) == 5
benchmark_functions_edited/f12673.py
def f(file): count = 0 buffer = 16 * 1024 * 1024 # buffer=16MB with open(file, "rb") as inf: while True: block = inf.read(buffer) if not block: break count += block.count(b"\n") return count assert f("/dev/null") == 0
benchmark_functions_edited/f3280.py
def f(base, height): # You have to code here # REMEMBER: Tests first!!! return (1/2) * base * height assert f(0, 10) == 0
benchmark_functions_edited/f2695.py
def f(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) assert f(lambda x, y=1: x, None, (1,), {}) == 1
benchmark_functions_edited/f5563.py
def f(a): order = ['line', 'tag', 'span_id', 'lang_name', 'lang_code', 'fonts'] return order.index(a) if a in order else len(order) assert f("line") == 0
benchmark_functions_edited/f12910.py
def f(first, second): if len(first) != len(second): raise Exception("These vectors must be the same size") return sum([abs(x - y) for x, y in zip(first, second)]) assert f(tuple([0]), tuple([0])) == 0
benchmark_functions_edited/f12055.py
def f(num_points: int, accuracy: int) -> int: order = num_points - accuracy assert order >= 0 # check if the next-larger order would be boosted: if (num_points - (order + 1)) % 2: return order + 1 return order assert f(128, 125) == 3
benchmark_functions_edited/f944.py
def f(x, disp): return x // (2 ** disp) assert f(0b1001, 4) == 0
benchmark_functions_edited/f3502.py
def f(iterable): res = 1 for x in iterable: res *= x return res assert f(range(1, 4)) == 6
benchmark_functions_edited/f9703.py
def f(axis_handle) -> int: if axis_handle is None: return 0 else: if len(axis_handle.lines) == 0: return 0 else: return len(axis_handle.lines)-1 assert f(None) == 0
benchmark_functions_edited/f13230.py
def f(layout, channels): if layout in ("TBD", "BTD"): if channels is not None and channels != 1: raise ValueError( "Expected channels ({}) to be 1 for layout = {}".format( channels, layout ) ) if channels is None: return 1 return channels assert f( "TB", 1, ) == 1
benchmark_functions_edited/f1826.py
def f(a, b): while a: a, b = b % a, a return b assert f(5, -5) == 5
benchmark_functions_edited/f5165.py
def f(raw_value): value = int(raw_value) if value < 0: raise ValueError("negative") return value assert f("1") == 1
benchmark_functions_edited/f13069.py
def f(name, num_layers): if name in ['cls_token', 'pos_embed']: return 0 elif name.startswith('patch_embed'): return 0 elif name.startswith('blocks'): return int(name.split('.')[1]) + 1 else: return num_layers assert f( 'patch_embed.proj.bias', 2) == 0
benchmark_functions_edited/f11883.py
def f(ij): if ij == "11": return 0 elif ij == "22": return 1 elif ij == "33": return 2 elif ij == "12" or ij == "21": return 3 elif ij == "23" or ij == "32": return 4 elif ij == "13" or ij == "31": return 5 assert f("12") == 3
benchmark_functions_edited/f10001.py
def f(base, exponent, digit_length): counter = 1 result = base while counter < exponent: result = result * base result = str(result)[0:digit_length] result = int(result) counter += 1 return result assert f(1, 10, 4) == 1
benchmark_functions_edited/f4132.py
def f(data): minimum = data[0] for value in data: minimum = value if value < minimum else minimum return minimum assert f([1, 3, 2, 1]) == 1
benchmark_functions_edited/f11256.py
def f(nums): # Iterate to check element is greater than its neighbors. for i in range(len(nums)): if ((i == 0 or nums[i] >= nums[i - 1]) and (i == len(nums) - 1 or nums[i] >= nums[i + 1])): return i assert f(list(range(10))) == 9
benchmark_functions_edited/f8125.py
def f(name): if name == name: return len(name) else: return 0 assert f('Foo\tBar') == 7
benchmark_functions_edited/f13906.py
def f(passphrases): return sum(len(words) == len(set(words)) for words in (passphrase.split() for passphrase in passphrases.split('\n'))) assert f( 'aa bb cc dd aa') == 0
benchmark_functions_edited/f4348.py
def f(audio, byte_width): return audio * (2**(8*byte_width-1) - 1) assert f(0, 1) == 0
benchmark_functions_edited/f8506.py
def f(dictionary, key): return dictionary.get(key, None) assert f({'x': 3, 'y': 4}, 'y') == 4
benchmark_functions_edited/f12324.py
def f(a, b, c): ans = '' ans += a[c + 1:] if ans.find(b) == -1: return -1 else: num = ans.find(b) + c + 1 return num assert f( 'abcabc', 'a', 0) == 3
benchmark_functions_edited/f2007.py
def f(start, end): return sum(range(1, abs(start - end) + 1)) assert f(1, 2) == 1
benchmark_functions_edited/f7275.py
def f(current, players): try: next_player = players[players.index(current) + 1] except IndexError: next_player = players[0] return next_player assert f(0, [0, 2, 3, 1]) == 2
benchmark_functions_edited/f3165.py
def f(a, b): if a < b: a, b = b, a while b != 0: a, b = b, a % b return a assert f(2, 0) == 2
benchmark_functions_edited/f11213.py
def f(AU,R): return AU*1.496e8/(R*695510) assert f(0,1) == 0
benchmark_functions_edited/f9895.py
def f(x): a = pow(x, 0.5) if isinstance(x, complex): return a elif x < 0: return complex(0, a.imag) else: return a.real assert f(0) == 0
benchmark_functions_edited/f91.py
def f(arr): return sum(arr) / float(len(arr)) assert f([2, 4, 6, 8, 10]) == 6
benchmark_functions_edited/f9412.py
def f(orbits, cur_object, cur_orbit): if not orbits[cur_object]: return cur_orbit return sum(f(orbits, next_object, cur_orbit + 1) for next_object in orbits[cur_object]) + cur_orbit assert f( {'COM': ['B'], 'B': ['C'], 'C': ['D'], 'D': [], 'E': []}, 'COM', 0) == 6
benchmark_functions_edited/f4907.py
def f(limit) -> int: total = 0 for x in range(limit): if x % 3 == 0 or x % 5 == 0: total += x return total assert f(1) == 0
benchmark_functions_edited/f6023.py
def f(s, fallback=0): try: return int(float(s)) except (ValueError, TypeError, OverflowError): return fallback assert f('', 1) == 1
benchmark_functions_edited/f4078.py
def f(key, value): with open(key, 'w') as f: f.seek(0) f.write(str(value)) return value assert f('3', 3) == 3
benchmark_functions_edited/f14336.py
def f(adjusted_stage, contestant_first_pick): if contestant_first_pick == 0: if adjusted_stage[1] == -1: return 2 else: return 1 elif contestant_first_pick == 1: if adjusted_stage[0] == -1: return 2 else: return 0 else: if adjusted_stage[0] == -1: return 1 else: return 0 assert f( [1, -1, -1], 0 ) == 2
benchmark_functions_edited/f5656.py
def f(search, text): for idx, line in enumerate(text.splitlines()): if search in line: return idx else: return 0 assert f( 'bar', 'foo\nbar\nquux\n' ) == 1
benchmark_functions_edited/f13816.py
def f(lut, label): result = lut[label] if lut[result] != result: result = f(lut, result) lut[label] = result return result assert f(list(range(10)), 7) == 7
benchmark_functions_edited/f1104.py
def f(predictions, new_index): return predictions[new_index]["index"] assert f( [ {"index": 0, "value": 100}, {"index": 1, "value": 50}, {"index": 2, "value": 0}, ], 2 ) == 2
benchmark_functions_edited/f10049.py
def f(trig1: set, trig2: set) -> float: count = 0 for i in trig1: if i in trig2: count += 1 return count / len(trig2) assert f(set([1, 2, 3, 4]), set([1, 2, 3, 4])) == 1
benchmark_functions_edited/f12262.py
def f(a, key, index=0, iteration=0): if len(a) == 1 and a[0] != key: return -1 m = len(a) // 2 # m for middle of the array if a[m] == key: return index + m elif a[m] > key: return f(a[0:m], key, index, iteration + 1) elif a[m] < key: return f(a[m:], key, index + m, iteration + 1) assert f(list(range(10)), 9) == 9
benchmark_functions_edited/f6465.py
def f(instuction_sign, value_1, value_2): if instuction_sign == '+': return value_1 + value_2 elif instuction_sign == '-': return value_1 - value_2 assert f('-', 4, 2) == 2
benchmark_functions_edited/f9290.py
def f(alignment, x): return ((x + alignment - 1) // alignment) * alignment assert f(2, 1) == 2
benchmark_functions_edited/f4331.py
def f(n: int) -> int: if n < 2: return n else: return f(n - 1) + f(n - 2) assert f(3) == 2
benchmark_functions_edited/f532.py
def f(a, b): return a+b+b assert f(1, 0) == 1
benchmark_functions_edited/f8516.py
def f(iterable, key=None, position=1): if key is None: if hasattr(iterable, '__iter__'): return iterable[position] else: return iterable else: return iterable[key] assert f([1, 2, 3], -3) == 1
benchmark_functions_edited/f481.py
def f(y, x): return 2*x - y*(x**2); assert f(1, 2) == 0
benchmark_functions_edited/f4953.py
def f(p, p_other_lag, p_own_lag, rounder_number): return 1 if p == 4 else 0 assert f(0, 0, 2, 0) == 0
benchmark_functions_edited/f8831.py
def f(a, b, c): x = a - b y = b - c z = a - c if x * y > 0: return b if x * z > 0: return c return a assert f(2, 1, 3) == 2
benchmark_functions_edited/f10826.py
def f(results): final_result = 0 for count in results: for word in count: final_result += count[word] return final_result assert f(dict()) == 0
benchmark_functions_edited/f12194.py
def f(pos1, pos2): return sum((a - b)**2 for a, b in zip(pos1, pos2)) assert f( (0,0,0), (1,1,1) ) == 3
benchmark_functions_edited/f1057.py
def f(byte_val: int) -> int: assert 0 <= byte_val < 8 return byte_val assert f(4) == 4
benchmark_functions_edited/f13460.py
def f(nodeState): return sum(nodeState.values()) assert f({}) == 0
benchmark_functions_edited/f5263.py
def f(Parameter,Bounds): if Parameter < Bounds[0] or Parameter > Bounds[1]: return 0 else: return 1 assert f(3, (0, 2)) == 0
benchmark_functions_edited/f6449.py
def f(*args): print("\nmock> f({}) ==> 0".format(args)) # pragma: no cover return 0 # pragma: no cover assert f(2, 3) == 0
benchmark_functions_edited/f437.py
def f(trace): return trace and (trace-1) assert f(8) == 7
benchmark_functions_edited/f9762.py
def f(func, list_of_dict, key): values = [_dict[key] for _dict in list_of_dict if _dict[key] is not None] if len(values) == 0: return None return func(values) assert f(min, [{'x': None, 'y': 3}, {'x': None, 'y': 4}], 'y') == 3
benchmark_functions_edited/f4914.py
def f(acc, w1, w2): return acc + min(w1, w2) assert f(1, 1, 2) == 2