file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f14173.py
def f(iterator, n): # throw away n-1 elements for index in range(1, n): next(iterator, None) return next(iterator, None) assert f(iter([1, 2, 3, 4]), 3) == 3
benchmark_functions_edited/f6410.py
def f(product_list): largest = 1 for products in product_list: if largest < max(products): largest = max(products) return largest assert f(list()) == 1
benchmark_functions_edited/f5646.py
def f(value): return value + 6 * (value // 10) assert f(0b00000110) == 6
benchmark_functions_edited/f13423.py
def f(index: int, length: int) -> int: # assert length >= 0 index = index if index >= 0 else index + length return 0 if index < 0 else length if index > length else index assert f(-6, 5) == 0
benchmark_functions_edited/f13408.py
def f(a_list, item): if item in a_list: for i, value in enumerate(a_list): if value == item: return i assert f(list('abcd'), 'd') == 3
benchmark_functions_edited/f4729.py
def f(n): return int(n, 2) assert f('0001') == 1
benchmark_functions_edited/f13522.py
def f(max_base: int = 10, max_power: int = 22) -> int: bases = range(1, max_base) powers = range(1, max_power) return sum( 1 for power in powers for base in bases if len(str(base**power)) == power ) assert f(0, 2) == 0
benchmark_functions_edited/f2373.py
def f(_list, idx, default): try: return _list[idx] except IndexError: return default assert f(list(), 2, 3) == 3
benchmark_functions_edited/f902.py
def f(val, width): x = (width >> 3) - 1 return (val + x) & ~x assert f(0, 4) == 0
benchmark_functions_edited/f9527.py
def f(theta1, theta2, p): return theta1 + (theta2-theta1) * p assert f(0, 10, 0) == 0
benchmark_functions_edited/f13217.py
def f(clusters, shape): if len(clusters) == 0: return 0 else: return max(clusters) / (shape[0] * shape[1]) assert f([0, 0, 0], (3, 3)) == 0
benchmark_functions_edited/f11999.py
def f(v0, v1, v2, v3, alpha): alpha2 = alpha * alpha a0 = (v3 - v2) - v0 + v1 a1 = (v0 - v1) - a0 a2 = v2 - v0 a3 = v1 return (a0 * alpha) * alpha2 + a1 * alpha2 + a2 * alpha + a3 assert f(1, 1, 1, 1, 1) == 1
benchmark_functions_edited/f10561.py
def f(list, value): return next(x[0] for x in enumerate(list) if x[1] > value) assert f( [3, 5, 10, 20, 25, 30, 35], 24 ) == 4
benchmark_functions_edited/f6013.py
def f(obj, attr, sentinel=None): try: return getattr(obj, attr) except AttributeError: return sentinel assert f({},'real', 4) == 4
benchmark_functions_edited/f7584.py
def f(n, alpha=1, beta=0): kMAP = (n + alpha - 1) / (1 + beta) if kMAP < 0: raise ValueError("kMAP < 0") return kMAP assert f(4, 1, 1) == 2
benchmark_functions_edited/f9823.py
def f(element, sample): return sample.count(element) assert f(1, [1, 2, 3]) == 1
benchmark_functions_edited/f4071.py
def f(text): try: _ = float(text) except ValueError: return 0 else: return 1 assert f("2.3e+10.5") == 0
benchmark_functions_edited/f6491.py
def f(data,value): data.sort() i = 0 lgt = len(data) while i < lgt and value > data[i]: i+=1 return i if i <lgt else lgt-1 assert f([1,2,3], 2.5) == 2
benchmark_functions_edited/f13225.py
def f(value: int) -> int: if value < 0: return -1 elif value == 0: return 0 else: return 1 assert f(27) == 1
benchmark_functions_edited/f14298.py
def f(iterable, condition = lambda x: True): return next(x for x in iterable if condition(x)) assert f( range(3, 100) ) == 3
benchmark_functions_edited/f1551.py
def f(path): return int(path.split("_")[-2]) assert f( "predictions_000000001_000000000.pb") == 1
benchmark_functions_edited/f1903.py
def f(val: int) -> int: tmp = 255 if val>255 else val return 0 if tmp<0 else tmp assert f(5) == 5
benchmark_functions_edited/f9536.py
def f(k, cao, x): return k * cao * (1 - x) assert f(1, 10, 1) == 0
benchmark_functions_edited/f4126.py
def f(value, min_value, max_value): return min(max(value, min_value), max_value) assert f(2, 0, 2) == 2
benchmark_functions_edited/f10170.py
def f(value, shift_value): if shift_value == None: return 0 if shift_value < 0: return value << (-shift_value) else: return value >> shift_value assert f(1, -2) == 4
benchmark_functions_edited/f10634.py
def f(map_or_seq): if isinstance(map_or_seq, dict): return 1 + max(map(guess_max_depth, map_or_seq.values()), default=0) elif isinstance(map_or_seq, list): return 1 + max(map(guess_max_depth, map_or_seq[0].values()), default=0) return 0 assert f(1) == 0
benchmark_functions_edited/f4924.py
def f(start, stop): number_of_set_bits = stop - start + 1 return ((1 << number_of_set_bits) - 1) << start assert f(0, 0) == 1
benchmark_functions_edited/f6716.py
def f(n): if n <= 2: return 1 return f(n - 1) + f(n - 2) assert f(5) == 5
benchmark_functions_edited/f6754.py
def f(input_dict, key, default_value): result = input_dict.get(key, default_value) if result is None: result = default_value return result assert f(dict(), 'foo', 0) == 0
benchmark_functions_edited/f14519.py
def f(iterable, condition=lambda x: True): return next(x for x in iterable if condition(x)) assert f(range(3)) == 0
benchmark_functions_edited/f3465.py
def f(value, dp=0): try: return round(int(value), dp) except ValueError: return 0 assert f('', 0) == 0
benchmark_functions_edited/f457.py
def f(param): if param == 0: return 1 return 0 assert f(1) == 0
benchmark_functions_edited/f3572.py
def f(dictionary: dict) -> int: return len(set(dictionary.values())) assert f(dict({'a': 1})) == 1
benchmark_functions_edited/f11396.py
def f(two_level_dict): tot_sum = 0 for j in two_level_dict.values(): tot_sum += sum(j.values()) return tot_sum assert f( { "A": {}, } ) == 0
benchmark_functions_edited/f6359.py
def f(values, index, fallback): if index < len(values): return values[index] return fallback assert f(list(range(3)), 1, 99) == 1
benchmark_functions_edited/f1758.py
def f(x, y, z): return (abs(x) + abs(y) + abs(z)) // 2 assert f(0, -1, -1) == 1
benchmark_functions_edited/f5862.py
def f(number, n): nth_root = int(round(pow(number, 1.0 / n))) if nth_root ** n != number: nth_root = None return nth_root assert f(4, 1) == 4
benchmark_functions_edited/f8138.py
def f(seq): if '*' in seq: return seq.index('*') else: return len(seq) assert f('M*R') == 1
benchmark_functions_edited/f726.py
def f(a, b, c): if a: return b else: return c assert f(False, 1, 2) == 2
benchmark_functions_edited/f4288.py
def f(s, i): c = s[i] s = list(sorted(s)) return s.index(c) assert f("ba", 0) == 1
benchmark_functions_edited/f13567.py
def f(old_value, old_min, old_max, new_min, new_max): ## calculate the value new_value = ( (old_value - old_min) / (old_max - old_min) ) * (new_max - new_min) + new_min return new_value assert f(0, 0, 10, 0, -20) == 0
benchmark_functions_edited/f11154.py
def f(loglines, start_line): last_line = len(loglines) - 1 for i in range(start_line, len(loglines)): if len(loglines[i].strip()) == 0: last_line = i - 1 break return last_line assert f( ["", "a", "b", "", "c", ""], 4 ) == 4
benchmark_functions_edited/f6663.py
def f(link_counters): for processor in link_counters.values(): if 'to_read' in processor: return processor['to_read'] assert f( {'proc0': {'to_read': 1,'read_ok': 0, 'write_ok': 0, 'to_write': 0}} ) == 1
benchmark_functions_edited/f9411.py
def f(cfg): toVisit = set() for adj in cfg['adjacency']: for n in adj: toVisit.add(n['id']) for i in range(len(cfg['nodes'])): if cfg['nodes'][i]['id'] not in toVisit: return i return 0 assert f( {'nodes': [ {'id': 0}, {'id': 1}, {'id'...
benchmark_functions_edited/f134.py
def f(n, d): return int((n + d - 1) / d) assert f(3, 1) == 3
benchmark_functions_edited/f4618.py
def f(a, b): return (abs(a[0] - b[0]) + abs(a[0] + a[1] - b[0] - b[1]) + abs(a[1] - b[1])) / 2 assert f( (1, 2), ( 3, 4)) == 4
benchmark_functions_edited/f8737.py
def f(x, y): return (x*y)/(x+y) assert f(1, 0) == 0
benchmark_functions_edited/f5109.py
def f(x_1, x_2): return len(x_1) + len(x_2) - len(x_1.intersection(x_2)) * 2 assert f(set([]), set([1])) == 1
benchmark_functions_edited/f12529.py
def f(index): return index ^ (index // 2) assert f(2) == 3
benchmark_functions_edited/f1207.py
def f(n): if n == 0 or n == 1: return n #base case return f(n-1) + f(n-2) assert f(2) == 1
benchmark_functions_edited/f13967.py
def f(slc, sequence_len): # This will translate slice to a range, from which we can retrieve length return len(range(*slc.indices(sequence_len))) assert f(slice(1, 3), 3) == 2
benchmark_functions_edited/f12575.py
def f(tree_map, width, pos): x = pos[0] % width y = pos[1] if tree_map[y] != '' and tree_map[y][x] == '#': return 1 return 0 assert f( ['###', '###'], 3, (3, 0)) == 1
benchmark_functions_edited/f5235.py
def f(s1, s2): return (len(s1 + s2)) assert f("foo", "bar") == 6
benchmark_functions_edited/f5727.py
def f(*args): sum_ = 0 for number in args: sum_ = sum_ + number return sum_ assert f(1) == 1
benchmark_functions_edited/f8960.py
def f(arg, argname, valid_args): if arg not in valid_args: msg = 'Invalid value for {} ({}). Must be on of {}.' raise ValueError(msg.format(argname, arg, valid_args)) return arg assert f(1, 'argname', [3, 2, 1]) == 1
benchmark_functions_edited/f13047.py
def f(row, col, width=3, height=3): return col // width + row - (row % height) assert f(1, 0) == 0
benchmark_functions_edited/f7815.py
def f(hand): length =0 for letter in hand: length += hand[letter] return length assert f({}) == 0
benchmark_functions_edited/f8172.py
def f(number, binsize, direction): if direction == 'down': return number - (number % binsize) elif direction == 'up': return number - (number % binsize) + binsize assert f(2, 1, 'up') == 3
benchmark_functions_edited/f1293.py
def f(x): return int(round(1.0 / x)) assert f(0.333) == 3
benchmark_functions_edited/f5057.py
def f(medians): sum_of_medians = 0 for m in medians: sum_of_medians += m return sum_of_medians assert f([1, 1, 1]) == 3
benchmark_functions_edited/f11948.py
def f(x, xmx): if (x <= xmx): c = 1 else: c = 1/(1+x-xmx) return c assert f(0.2, 0.2) == 1
benchmark_functions_edited/f1523.py
def f(n, b): return ((n << b) | (n >> (32 - b))) & 0xffffffff assert f(0x00000000, 1) == 0
benchmark_functions_edited/f1437.py
def f(val, min_, max_): return min(max(val, min_), max_) assert f(-1, 2, 3) == 2
benchmark_functions_edited/f9579.py
def f(m, n): while n != 0: m, n = n, m % n return m assert f(100000, 1) == 1
benchmark_functions_edited/f1729.py
def f(a: int, b: int) -> int: return (a % b + b) % b assert f(0, 5) == 0
benchmark_functions_edited/f4428.py
def f(i): ii = 1 while ii<i: ii*=2 return ii assert f(8)==8
benchmark_functions_edited/f1575.py
def f(answers: list) -> int: return len(set("".join(answers))) assert f(['b', 'b', 'b']) == 1
benchmark_functions_edited/f1953.py
def f(coordinates): return sum(abs(num) for num in coordinates) assert f((1, 1, 0)) == 2
benchmark_functions_edited/f13042.py
def f(seq, lo, hi): m = lo + (hi - lo) // 2 # middle element if seq[lo] < seq[m]: if seq[m] < seq[hi - 1]: return m elif seq[hi - 1] < seq[lo]: return lo else: if seq[hi - 1] < seq[m]: return m elif seq[lo] < seq[hi - 1]: retur...
benchmark_functions_edited/f6400.py
def f(gwh): kwh = gwh * 1000000 return kwh assert f(0) == 0
benchmark_functions_edited/f11098.py
def f(states_importance): sum_delta = 0 for i in range(len(states_importance)): sum_delta += states_importance[i] - states_importance[i - 1] avg_delta = sum_delta / len(states_importance) return avg_delta assert f( [0, 0, 0, 0, 0, 0]) == 0
benchmark_functions_edited/f5032.py
def f(d): test = 0 while True: test += 1 if (10 ** test) % d == 1: return test assert f(7) == 6
benchmark_functions_edited/f8033.py
def f(num): aux = 0 while (num > 0): remainder = num % 10 aux = (aux * 10) + remainder num = num // 10 return aux assert f(100) == 1
benchmark_functions_edited/f2403.py
def f(level): return int((level * 100) / 255) assert f(0) == 0
benchmark_functions_edited/f8813.py
def f(data, max_value=100, min_value=0): if max_value > 0: scaler = max_value - min_value data = data * scaler + min_value return data assert f(0, 100, 0) == 0
benchmark_functions_edited/f10309.py
def f(container): max_index = 0 for i in range(len(container)): if container[max_index] < container[i]: max_index = i return max_index assert f((1,)) == 0
benchmark_functions_edited/f12158.py
def f(group): # get the label of each instance in the group outcomes = [row[-1] for row in group] return max(set(outcomes), key=outcomes.count) assert f([ [1, 2, 3, 4, 5, 6], [2, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]]) == 6
benchmark_functions_edited/f456.py
def f(x, y): result = max(x, y) return result assert f(3, 5) == 5
benchmark_functions_edited/f5957.py
def f(s1, s2): count = 0 for i in range(len(s1)): if s1[i] != s2[i]: count += 1 return count assert f("a", "a") == 0
benchmark_functions_edited/f6081.py
def f(iterable): if iterable: return max(iterable) return 0 assert f([1, 2, 3]) == 3
benchmark_functions_edited/f13573.py
def f(limit, vs, ws): def _knapsack(limit, vs, ws, i): if limit == 0 or i == len(vs): return 0 accept, reject = 0, _knapsack(limit, vs, ws, i + 1) if ws[i] <= limit: accept = vs[i] + _knapsack(limit - ws[i], vs, ws, i + 1) return max(accept, reject) r...
benchmark_functions_edited/f2190.py
def f(n_numbers): return sum([1.0/(i + 1) for i in range(n_numbers)]) assert f(1) == 1
benchmark_functions_edited/f6547.py
def f(mod, num_patches): if mod > 0: num_patches += 1 return num_patches assert f(5, 1) == 2
benchmark_functions_edited/f3496.py
def f(x, n): while n < x: n = n << 1 return n assert f(4, 3) == 6
benchmark_functions_edited/f14381.py
def f(cores): total = 0 with open('/proc/cpuinfo') as cpuinfo: for cpu in cpuinfo.read().split('\n\n'): for line in cpu.splitlines(): if line.startswith('processor'): if int(line.split(':')[1]) not in cores: break if...
benchmark_functions_edited/f2348.py
def f(s, row, column): return s[row * 3 + column] assert f(list(range(9)), 0, 0) == 0
benchmark_functions_edited/f8287.py
def f(layer, cols): found = -1 pos = cols - 1 while (pos >= 0) and (found < 0): if layer[pos] == 1: found = pos pos = pos - 1 return found assert f( [1, 1, 1, 1, 1, 1, 1], 6) == 5
benchmark_functions_edited/f6190.py
def f(n : int) -> int: acc : int # accumulateur acc = 1 i : int # compteur i = 2 while i <= True: acc = acc * i i = i + 1 return acc assert f(0) == 1
benchmark_functions_edited/f12379.py
def f(arrayOfSheeps: list) -> int: return 0 if arrayOfSheeps is None \ else arrayOfSheeps.count(True) assert f(None) == 0
benchmark_functions_edited/f4061.py
def f(module): try: __import__(module) return 1 except ImportError: return 0 assert f("nonexistentmodule.nonexistentsubmodule") == 0
benchmark_functions_edited/f10814.py
def f(d: dict, *keys): if len(keys) == 1: return d[keys[0]] else: nested = d.get(keys[0], None) if nested is not None: return f(nested, *keys[1:]) else: return None assert f( {'a': {'b': 1}}, 'a', 'b' ) == 1
benchmark_functions_edited/f3116.py
def f(n, m): f = 1 for i in range(n - m + 1, n + 1): f *= i return f assert f(3, 0) == 1
benchmark_functions_edited/f5943.py
def f(a,lo,hi): return min(hi, max(lo, a)) assert f(5, 3, 4) == 4
benchmark_functions_edited/f2620.py
def f(arr): return 0 if arr is None or arr == [] else sum(sorted(arr)[1:-1]) assert f([1]) == 0
benchmark_functions_edited/f10355.py
def f(stepnumber , zin = 200. , zfinal = 0. , numsteps = 500) : ain = 1.0/(1.0 + zin) afinal = 1.0/(1.0 + zfinal) astep = (afinal - ain)/numsteps aatstep = astep * (stepnumber +1.)+ ain z = 1.0/aatstep - 1.0 return z assert f(0,0,0,100) == 0
benchmark_functions_edited/f2970.py
def f(array: list) -> int: result = 0 for i in array: result += i return result assert f(list([1, 2])) == 3
benchmark_functions_edited/f11007.py
def f(x, p): return 1. / (1. - p + p/x) assert f(1., 1.) == 1
benchmark_functions_edited/f12206.py
def f(pos: int, steps: int) -> int: return (pos + steps - 1) % 10 + 1 assert f(1, 1) == 2
benchmark_functions_edited/f4610.py
def f(line): i = 0 for char in line: if char != " ": break i += 1 return i assert f(" \t") == 1
benchmark_functions_edited/f5079.py
def f(grid_values): score = max(grid_values) return score assert f([1, 3, 2, 5, 4, 1, 7, 8, 9]) == 9