file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f9837.py
def f(arr, target): # Sublist of viable elementsa leq_elements = sorted([x for x in arr if x <= target]) return leq_elements[-1] assert f(range(5), 0) == 0
benchmark_functions_edited/f10457.py
def f(func): if hasattr(func, "_pv_original_func"): return f(func._pv_original_func) return func assert f(1) == 1
benchmark_functions_edited/f10375.py
def f(a,b): def gcf_internal(a,b): if a < b: return gcf_internal(b,a) if b==0: return a return gcf_internal(b, a%b) if a<=0 or b<=0: raise RuntimeError if int(a)!=a or int(b)!=b: raise RuntimeError return gcf_internal(a,b) assert f(2,1) == 1
benchmark_functions_edited/f7104.py
def f(rdoc, pformat): copies = ["Original", "Duplicate", "Triplicate"] return copies.index(rdoc.jasper_report_number_copies) + 1 if pformat == "pdf" else 1 assert f(None, None) == 1
benchmark_functions_edited/f8597.py
def f(a, b): minX, minY, maxX, maxY = max(a[0], b[0]), max(a[1], b[1]), \ min(a[2], b[2]), min(a[3], b[3]) return max(0, maxX - minX) * max(0, maxY - minY) assert f( (0, 0, 10, 10), (15, 15, 20, 20)) == 0
benchmark_functions_edited/f6744.py
def f(cost: int) -> int: if cost == 0: return 1 elif cost == 1: return 2 elif cost == 2: return 4 else: return cost + 4 assert f(0) == 1
benchmark_functions_edited/f8561.py
def f(preference_threshold, distance): if distance < 0: return 0 elif distance < preference_threshold: return distance*1.0 / preference_threshold else: return 1 assert f(0.5, 0.75) == 1
benchmark_functions_edited/f6624.py
def f(data_list, optimal_distance): count = sum(1 for i in data_list if optimal_distance in i) return count assert f( [ '2017-08-10 17:45:51.004000', '2017-08-10 17:45:53.005000', '2017-08-10 17:45:55.006000', '2017-08-10 17:45:57.007000', '2017-08-10 17:45:59.008000', '2017-08-10 17:46:01.009000', '2017-08-10 17:46:03.010000' ], '2017-08-10 17:46:05.011000' ) == 0
benchmark_functions_edited/f778.py
def f(m,s): return max(abs(m),abs(s)) assert f(1,0) == 1
benchmark_functions_edited/f9799.py
def f(ident, env): # Check if the value is defined anywhere in the environment if not ident in env: return 0 # If so, get it and query it for it's data var = env.get(ident, get_var=True) return var.data(ident) assert f('c', {'a': 1, 'b': 2}) == 0
benchmark_functions_edited/f11817.py
def f(a, b): dx = (a[2] - b[2]) ** 2 dy = (a[1] - b[1]) ** 2 dz = (a[0] - b[0]) ** 2 return (dx + dy + dz) ** 0.5 assert f( (0, 0, 0), (2, 0, 0) ) == 2
benchmark_functions_edited/f10570.py
def f(w, x): eps = 1e-10 if x < 0 - eps: d = w + 1 elif x > 0 + eps: d = w - 1 else: if -1 <= w <= 1: d = 0 elif w > 1: d = w - 1 else: d = -w - 1 return d assert f(-2, 1e-12) == 1
benchmark_functions_edited/f1026.py
def f(X, Y): return (0.26 * (X ** 2 + Y ** 2)) - (0.48 * X * Y) assert f(0, 0) == 0
benchmark_functions_edited/f9301.py
def f(file, content): nchar_written = 0 with open(file, 'w') as f: nchar_written = f.write(content) return nchar_written assert f('tmp.txt', 'hello\n') == 6
benchmark_functions_edited/f5396.py
def f(byte, offset, value): if value: return byte | (1 << offset) else: return byte & ~(1 << offset) assert f(1, 7, 0) == 1
benchmark_functions_edited/f7324.py
def f(nums): nums = sorted(nums) first_option=nums[0]*nums[1]*nums[-1] second_option=nums[-3] * nums[-2] * nums[-1] return first_option if first_option > second_option else second_option assert f( [1, 2, 3] ) == 6
benchmark_functions_edited/f3176.py
def f(n): if n == 0 or n == 1: return 1 else: return f(n-1) + f(n-2) assert f(0) == 1
benchmark_functions_edited/f12521.py
def f(risk): _index = 0 if risk >= 0.8 and risk < 1.0: _index = 1 elif risk >= 1.0 and risk <= 1.2: _index = 2 elif risk > 1.2: _index = 3 return _index assert f(1.3) == 3
benchmark_functions_edited/f5831.py
def f(n: int) -> int: if n == 0: return n elif n <= 2: return 1 return f(n - 1) + f(n - 2) assert f(4) == 3
benchmark_functions_edited/f11112.py
def f(mu_i, n, x): delta = (x - mu_i) / float(n + 1) mu_f = mu_i + delta return mu_f assert f(1, 0, 0) == 0
benchmark_functions_edited/f5309.py
def f( argv ): # return success return 0 assert f( ['-v', '--quiet'] ) == 0
benchmark_functions_edited/f4017.py
def f(bytes_arr): return int.from_bytes(bytes_arr, byteorder='big', signed=False) assert f(b'\x08') == 8
benchmark_functions_edited/f1135.py
def f(num) -> int: return len(f"{num}") assert f(-0) == 1
benchmark_functions_edited/f13883.py
def f(x): if x == 'Never-married': return 1 elif x == 'Married-civ-spouse': return 2 elif x == 'Divorced': return 3 elif x == 'Married-spouse-absent': return 4 elif x == 'Widowed': return 5 elif x == 'Separated': return 6 elif x == 'Married-AF-spouse': return 7 else: return 0 assert f('Unmarried') == 0
benchmark_functions_edited/f10225.py
def f(seq1, seq2): set1, set2 = set(seq1), set(seq2) return 1 - len(set1 & set2) / float(len(set1 | set2)) assert f((1, 1, 1), (1, 1, 1)) == 0
benchmark_functions_edited/f12474.py
def f(total_cost, total_recipients): return (total_cost / total_recipients) * 1000 assert f(0, 1) == 0
benchmark_functions_edited/f8094.py
def f(iter: list or range): if type(iter) == list: return iter[0] elif type(iter) == range: return iter.start else: raise ValueError("iter must be of type list or range") assert f(list(range(1, 10))) == 1
benchmark_functions_edited/f9193.py
def f(i_list: list)-> int: i=0 _sum = 0 for row in i_list: _sum += row[i] i+=1 return _sum assert f( [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ] ) == 4
benchmark_functions_edited/f4824.py
def f(value, lower, upper): if upper < lower: lower, upper = upper, lower # Swap variables return min(max(value, lower), upper) assert f(-5, 5, 0) == 0
benchmark_functions_edited/f12485.py
def f(in_features: int, out_features: int, bias: bool = True): m = out_features + 1 if bias else out_features return in_features * m assert f(2, 1) == 4
benchmark_functions_edited/f7456.py
def f(s): try: return int(s) except ValueError: return s except TypeError: return s assert f('0') == 0
benchmark_functions_edited/f13146.py
def f(start: list, end: list) -> int: return_value: int = 1 index: int = 1 length: int = len(start) prev_index: int = 0 while index < length: if start[index] >= end[prev_index]: return_value += 1 prev_index = index index += 1 return return_value assert f( [1, 2, 3, 4], [3, 4, 5, 6] ) == 2
benchmark_functions_edited/f5593.py
def f(iso): splited_iso = iso.split(':') return int(float(splited_iso[0]) * 3600 + float(splited_iso[1]) * 60 + float(splited_iso[2])) assert f( '00:00:00.12345678912') == 0
benchmark_functions_edited/f855.py
def f(n): a, b = 0, 1 for i in range(1, n): a, b = b, a+b return b assert f(5) == 5
benchmark_functions_edited/f8139.py
def f(s): for i, c in enumerate(s): if c.isdigit(): return i raise ValueError('digit not found') assert f('12') == 0
benchmark_functions_edited/f11684.py
def f(obj, standard): if obj is None: return standard return obj assert f(3, 0) == 3
benchmark_functions_edited/f3734.py
def f(x): a, b = 1, 1 for i in range(1, x): a, b = b, a + b x += 1 return(a) assert f(4) == 3
benchmark_functions_edited/f14446.py
def f(x, a): print ("Top of loop:", x, a) if x == a: print ("In x == a: ", x, a) return 0 elif x < a: print ("In x < a: ", x, a) return x elif x > a: print ("In else: ", x, a) # print(x, a) # This needs to be changed to: # return f(x-a, a) f(x-a, a) assert f(0, 9) == 0
benchmark_functions_edited/f11856.py
def f(files, models): exitcode = 0 for file_index in range(0, len(files)): if isinstance(models[file_index], dict): print("Syntax invalid: %s" % models[file_index]) exitcode = 1 else: print("Syntax OK: %s" % (files[file_index])) return exitcode assert f( [], [] ) == 0
benchmark_functions_edited/f6584.py
def f(N, i, j): return i + N * j assert f(2, 0, 1) == 2
benchmark_functions_edited/f10652.py
def f(coords0, coords1): if coords0[1] > coords1[0] and coords1[1] > coords0[0]: return min(coords1[1], coords0[1]) - max(coords1[0], coords0[0]) return assert f( (10, 20), (15, 25) ) == 5
benchmark_functions_edited/f6963.py
def f(step): if hasattr(step, 'tune'): step.tune = False elif hasattr(step, 'methods'): step.methods = [f(s) for s in step.methods] return step assert f(1) == 1
benchmark_functions_edited/f10532.py
def f(value, empty): return empty if value is None else value assert f(1, 'empty') == 1
benchmark_functions_edited/f8725.py
def f(x, default=None): if (x is not None and x != 'None' and x != ''): return int(x) else: return default assert f('None', 2) == 2
benchmark_functions_edited/f31.py
def f(x, y): return (x - y) assert f(1, 1) == 0
benchmark_functions_edited/f4705.py
def f(ifm_dim, k, stride, pad=0): return int(((ifm_dim + 2 * pad - k) / stride) + 1) assert f(3, 1, 2) == 2
benchmark_functions_edited/f6209.py
def f(arr, val): i = 0 while i < len(arr): if val == arr[i]: return i i += 1 raise Exception('val not found in arr') assert f(list(range(3)), 0) == 0
benchmark_functions_edited/f5334.py
def f(acc): if acc > 1: acc -= 1 elif acc < -1: acc += 1 else: acc = 0 return acc assert f(10) == 9
benchmark_functions_edited/f11709.py
def f(base, power, mod): if power < 0: return -1 base %= mod result = 1 while power > 0: if power & 1: result = (result * base) % mod power = power >> 1 base = (base * base) % mod return result assert f(2, 2, 3) == 1
benchmark_functions_edited/f5293.py
def f(nums: list, target: int) -> int: return len(list(filter(lambda x: x == target, nums))) assert f( [1, 2, 3], 3 ) == 1
benchmark_functions_edited/f5492.py
def f(rows, has_steps=False): total = len(rows) if has_steps: total += sum([len(row.statements) for row in rows]) return total assert f([]) == 0
benchmark_functions_edited/f12967.py
def f(sel_list, useconds_of_selections): assert len(sel_list) == len(useconds_of_selections) result = 0 for selection, usecond in zip(sel_list, useconds_of_selections): if usecond == 0: break result = selection return result assert f( [10, 20, 30, 40, 50], [0, 0, 0, 0, 0] ) == 0
benchmark_functions_edited/f577.py
def f(*args): return args[-1] / 1024 assert f(1, 1, 1024) == 1
benchmark_functions_edited/f5797.py
def f(word: str) -> int: if len(word) == 4: score = 1 else: score = len(word) if len(set(word)) == 7: score += 7 return score assert f('goof') == 1
benchmark_functions_edited/f5796.py
def f(fetched, stored): i=0 for post in fetched: if not fetched[post] in [stored[item] for item in stored]: i+=1 return i assert f( { "post1": 1, "post2": 2, "post3": 3, }, { "post1": 1, "post2": 2, }, ) == 1
benchmark_functions_edited/f3378.py
def f(pos1, pos2): return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1]) assert f( (-3, -3), (0, 0) ) == 6
benchmark_functions_edited/f1657.py
def f(byte): if byte > 127: return (256-byte) * (-1) else: return byte assert f(1) == 1
benchmark_functions_edited/f10529.py
def f(a, b): if not isinstance(a, tuple): a = (a['x'], a['y']) if not isinstance(b, tuple): b = (b['x'], b['y']) return abs(a[0] - b[0]) + abs(a[1] - b[1]) assert f((3, 4), (0, 0)) == 7
benchmark_functions_edited/f9106.py
def f(othersys): rf2pos = 0 for pos in range(len(othersys)): if othersys[pos]['workflow_spec_id'] == 'random_fact': rf2pos = pos return rf2pos assert f([{'workflow_spec_id': 'other'}, {'workflow_spec_id': 'random_fact'}, {'workflow_spec_id': 'other'}]) == 1
benchmark_functions_edited/f1839.py
def f(L, val): return len(L) - L[::-1].index(val) - 1 assert f(list("1234567890"), "5") == 4
benchmark_functions_edited/f13992.py
def f(initial_velocity, acceleration, dist): vel = (initial_velocity ** 2 + 2 * acceleration * dist) ** 0.5 return vel assert f(5, 0, 3) == 5
benchmark_functions_edited/f5637.py
def f(i, scale): nonzeroscale = 0 if scale != 0: nonzeroscale = 1 if i != 0: i = ((i * scale) >> 8) + nonzeroscale return i assert f(2, 0) == 0
benchmark_functions_edited/f6129.py
def f(x1, y1, x2, y2): return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 assert f(5, 5, 5, 5) == 0
benchmark_functions_edited/f4540.py
def f(x, y, p): # two bytes per entry return (p + (18 * y) + (18 * 8 * x)) * 2 assert f(0, 0, 1) == 2
benchmark_functions_edited/f2902.py
def f(l=1): return (lambda x: x+1)(l) assert f(1) == 2
benchmark_functions_edited/f10709.py
def f(dicts, f): values = (f(d) for d in dicts) first_value = next(values) if all(value == first_value for value in values): return first_value return None assert f( [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}], lambda d: d.get('z', 0)) == 0
benchmark_functions_edited/f1497.py
def f(value, range_min, range_max): return min(max(value, range_min), range_max) assert f(3, 1, 4) == 3
benchmark_functions_edited/f12859.py
def f(v): a = 1.0993 b = 0.0181 d = 4.5 g = (1.0 / 0.45) if v < b * d: return v / d return pow(((v + (a - 1)) / a), g) assert f(0) == 0
benchmark_functions_edited/f14236.py
def f(nums): if not nums: return 0 max_so_far = nums[0] current_max = nums[0] for i in range(1, len(nums)): current_max = max(nums[i], current_max + nums[i]) max_so_far = max(max_so_far, current_max) print(max_so_far) return max_so_far assert f([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
benchmark_functions_edited/f4224.py
def f(angle): while angle < 0: angle += 360 while angle > 360: angle -= 360 return angle assert f(-0) == 0
benchmark_functions_edited/f1377.py
def f(cond,v1,v2): if cond: return v1 else: return v2 assert f(True, 1, 2.0 + 5.0*3.0**2.0) == 1
benchmark_functions_edited/f803.py
def f(x: int, y: int) -> int: return x if y == 0 else f(y, x % y) assert f(16, 2) == 2
benchmark_functions_edited/f3864.py
def f(ani): return ani['r'][0] assert f({'r': [2, 'Rato']}) == 2
benchmark_functions_edited/f3146.py
def f(content, path): with open(path, "wb") as f: return f.f(content.encode("utf-8")) assert f(u"\n\nHello", "test.txt") == 7
benchmark_functions_edited/f3669.py
def f(values): return sum(values) / len(values) assert f([1, 2, 3]) == 2
benchmark_functions_edited/f3284.py
def f(address: int, align: int) -> int: return address + ((align - (address % align)) % align) assert f(6, 2) == 6
benchmark_functions_edited/f4769.py
def f(x): return x * (x > 0) assert f(0) == 0
benchmark_functions_edited/f11992.py
def f(v, divisor, min_value=None): if min_value is None: min_value = divisor new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) # Make sure that round down does not go down by more than 10%. if new_v < 0.9 * v: new_v += divisor return new_v assert f(5, 5) == 5
benchmark_functions_edited/f9529.py
def f(s, buf): nleft = len(buf) i = 0 while nleft > 1: s += ord(buf[i]) * 256 + ord(buf[i+1]) i += 2 nleft -= 2 if nleft: s += ord(buf[i]) * 256 return s assert f(0, "") == 0
benchmark_functions_edited/f12420.py
def f(n): if n==0: return None if n==1 or n==2: return n-1 array = [0, 1] for i in range(2, n): array.append(array[i-1] + array[i-2]) return array assert f(2) == 1
benchmark_functions_edited/f14283.py
def f(arr): n = len(arr) dp = [1 for i in range(n)] for i in range(1, n): for j in range(i): if arr[i] > arr[j] and dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 longest_subsequence_len = None for val in dp: if longest_subsequence_len is None or longest_subsequence_len < val: longest_subsequence_len = val return longest_subsequence_len assert f([10, 9, 2, 5, 3, 7, 101, 18]) == 4
benchmark_functions_edited/f4679.py
def f(numerator, denominator): if denominator == 0: return None return numerator / denominator assert f(1, 1) == 1
benchmark_functions_edited/f11071.py
def f(a, b=2): # Add a with b (this is a comment) return a + b assert f(5, 2) == 7
benchmark_functions_edited/f13271.py
def f(metric_fn, prediction, ground_truths): scores_for_ground_truths = [] for ground_truth in ground_truths: score = metric_fn(prediction, ground_truth) scores_for_ground_truths.append(score) return max(scores_for_ground_truths) assert f(lambda p, a: len(p) + len(a), "a", ["b"]) == 2
benchmark_functions_edited/f6462.py
def f(config, key_seq): if 1 == len(key_seq): return config[key_seq[0]] else: return f(config[key_seq[0]], key_seq[1:]) assert f({"foo": {"bar": {"baz": 3}}}, ["foo", "bar", "baz"]) == 3
benchmark_functions_edited/f8182.py
def f(str1, str2): pos = str1.find(str2) if pos>-1: ret= pos+len(str2) else: ret = -1 return ret assert f( 'a', 'a' ) == 1
benchmark_functions_edited/f9899.py
def f(fd_or_obj): try: return int(fd_or_obj) except: if hasattr(fd_or_obj, 'fileno') and callable(fd_or_obj.fileno): return fd_or_obj.fileno() raise TypeError("Unable to get fd from %s" % fd_or_obj) assert f(True) == 1
benchmark_functions_edited/f3865.py
def f(x, y): if x is not None and y is not None: return x * y return None assert f(2, 1) == 2
benchmark_functions_edited/f9025.py
def f(num): answer = 0 while (answer+1)**2 < num: answer += 1 return answer**2 assert f(0) == 0
benchmark_functions_edited/f7922.py
def f(active_players): tricks_needed = 0 for player in active_players: tricks_needed += max(player.bid - player.curr_round_tricks, 0) return tricks_needed assert f([]) == 0
benchmark_functions_edited/f6859.py
def f(imgblocks): sum_areas = 0 for imgblock in imgblocks: block_area = imgblock['width'] * imgblock['height'] sum_areas = sum_areas + block_area return(sum_areas) assert f([{"width": 0, "height": 0}]) == 0
benchmark_functions_edited/f11188.py
def f(x, floor=1, ceiling=5): if x > ceiling: x = ceiling elif x < floor: x = floor return x assert f(2, 3, 4) == 3
benchmark_functions_edited/f584.py
def f(time): return time[0] * 60 + time[1] assert f( (0, 0) ) == 0
benchmark_functions_edited/f3689.py
def f(x, *args): result = x.conjugate() for y in args: result *= y return result assert f(1, 2) == 2
benchmark_functions_edited/f13308.py
def f(data): result = 0 for i in range(1, len(data)): first = int(data[i - 1]) second = int(data[i]) if first == second: result += first while first == second and i < len(data) - 1: i += 1 first = int(data[i - 1]) second = int(data[i]) if data[0] == data[len(data) - 1]: result += int(data[0]) return result assert f( "1122" ) == 3
benchmark_functions_edited/f6800.py
def f(SNR, Eb): return Eb / (10 ** (SNR/10)) assert f(10, 10) == 1
benchmark_functions_edited/f9630.py
def leap_year (year): if (year % 100 == 0 ): # Gregorian fix if (year % 400 == 0 ): return (1) else: return (0) else: if (year % 4 == 0 ): return (1) else: return (0) assert f(2100) == 0
benchmark_functions_edited/f11349.py
def f(m: int, n: int) -> int: while m >= 4: if n == 0: n = 1 else: n = f(m, n - 1) m -= 1 if m == 3: return (1 << n + 3) - 3 elif m == 2: return (n << 1) + 3 elif m == 1: return n + 2 else: return n + 1 assert f(0, 0) == 1
benchmark_functions_edited/f7905.py
def f(array): max_ending = max_slice = 0 for a in array: max_ending = max(0, max_ending + a) max_slice = max(max_slice, max_ending) return max_slice assert f(list()) == 0
benchmark_functions_edited/f1693.py
def f(a, b): return sum(abs(ai - bi) for ai, bi in zip(a, b)) assert f((1, 1), (1, 1)) == 0