file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f11262.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', '0.0.0') == 1
benchmark_functions_edited/f14021.py
def f(reference_start): in_frame_adjustment = 0 while (reference_start + in_frame_adjustment) % 3 != 0: in_frame_adjustment += 1 if in_frame_adjustment > 3: return return in_frame_adjustment assert f(17) == 1
benchmark_functions_edited/f7605.py
def f(d1, d2, p = 2): keys = set.union(set(d1.keys()), set(d2.keys())) diff = 0. for key in keys: diff += abs(d1.get(key, 0.) - d2.get(key, 0.))**p return diff ** (1./p) assert f(dict(), dict()) == 0
benchmark_functions_edited/f9670.py
def f(text: str): repeat_list = [] fixed_text = text.upper() for char in fixed_text: counts = fixed_text.count(char) if counts > 1: repeat_list.append(char) return len(set(repeat_list)) assert f( "abcde" ) == 0
benchmark_functions_edited/f2171.py
def f(string, list): return [i for i, s in enumerate(list) if string in s][0] assert f("0", ["0", "1", "2"]) == 0
benchmark_functions_edited/f7768.py
def f(unit, timestamp, summary): count = 0 for item in summary['queue']: if item['unit'] == unit and item['timestamp'] < timestamp: count += 1 return count assert f(2, 2, {'queue': [{'unit': 1, 'timestamp': 1}, {'unit': 1, 'timestamp': 2}]}) == 0
benchmark_functions_edited/f6149.py
def f(u, v, w): return u[0] * (v[1] * w[2] - v[2] * w[1]) + u[1] * (v[2] * w[0] - v[0] * w[2]) + u[2] * (v[0] * w[1] - v[1] * w[0]) assert f( (10, 100, 1000), (100, 1000, 10000), (1000, 10000, 100000) ) == 0
benchmark_functions_edited/f13000.py
def f(d1, d2): if len(d1) + len(d2) == 0: return 0 intj = 0 for i in d1.keys(): if d2.has_key(i): intj += 1 return 2 * intj / float(len(d1) + len(d2)) assert f(dict(), dict()) == 0
benchmark_functions_edited/f2714.py
def f(my_list): try: return sum(my_list) / len(my_list) except ZeroDivisionError: aa = 5 assert f([5, 4, 3, 2, 1]) == 3
benchmark_functions_edited/f8726.py
def f(grille): max=0 for i in range(len(grille)): for j in range(len(grille[0])): if grille[i][j]==None: continue if grille[i][j]>max: max = grille[i][j] return max assert f( [[None, 1, 1], [None, 1, 1], [None, 1, 1]]) == 1
benchmark_functions_edited/f14062.py
def f(value, scale): if scale == 0 or value == 0: return value # Add pow(10.0, -scale - 3) to ensure our smallest digit according to the # scale is correct return (value * pow(10.0, -scale)) + pow(10.0, -scale - 3) assert f(0, 0) == 0
benchmark_functions_edited/f2371.py
def f(t): m = max(t) for i in range(len(t)): if t[i] == m: return i assert f([1, 2, 3]) == 2
benchmark_functions_edited/f6331.py
def f(loss): grads = loss return loss assert f(5) == 5
benchmark_functions_edited/f9921.py
def f(ni, ki, n_back=1.0, k_back=0): ans = 2 * (n_back * ki - ni * k_back) / ((n_back + ni) ** 2 + (k_back + ki) ** 2) return ans assert f(2, 2, 1, 1) == 0
benchmark_functions_edited/f5991.py
def f(rank, nb_lemmas_in_stopwords): return max(1, rank - nb_lemmas_in_stopwords) assert f(3, 1) == 2
benchmark_functions_edited/f6546.py
def f(factor): ret_val = int(round((float(factor) - 0.5) * 2)) if ret_val < 0: ret_val = 0 if ret_val > 1: ret_val = 1 return ret_val assert f(0.0) == 0
benchmark_functions_edited/f12670.py
def f(f, x, eps=1e-6): return (f(x + eps/2) - f(x - eps/2))/eps assert f(lambda x: x**2, 0) == 0
benchmark_functions_edited/f6797.py
def findIndexInList (L: list, item) -> int: for i in range (len (L)): if L[i] == item: return i # return -1 when unsuccessful return -1 assert f([1, 2, 3], 1) == 0
benchmark_functions_edited/f14342.py
def f(n, edges): parents = list(range(n)) def find(x, parents): return x if parents[x] == x else find(parents[x], parents) for x, y in edges: x, y = find(x, parents), find(y, parents) parents[x] = y count = 0 for i in range(len(parents)): count += 1 if parents[i] == i else 0 return count assert f(5, [(0, 1), (1, 2), (2, 3), (3, 4), (0, 4)]) == 1
benchmark_functions_edited/f3016.py
def f(antall): return max(antall, key = antall.count) assert f([1, 2, 3, 4, 5, 6, 7, 8, 9, 9]) == 9
benchmark_functions_edited/f12018.py
def f(obj, start_angle, range_angle): return (obj - start_angle + range_angle) % range_angle + start_angle assert f(7, 1, 2) == 1
benchmark_functions_edited/f4821.py
def f(z): return (z > 0) assert f(0) == 0
benchmark_functions_edited/f12257.py
def f(l): max_sum = 0 start = 0 end = 1 while (end < len(l)): if l[start] + l[start+1] > 0: curr_sum = sum(l[start:end]) max_sum = max(curr_sum, max_sum) end += 1 else: # Start new sequence start = end + 1 end = start + 1 return max_sum assert f([-2, -3, 4, -1, -2, 1, 5, -3]) == 7
benchmark_functions_edited/f7061.py
def f(l_weight, l_length, r_weight, r_length, not_repeated): return -(l_weight / l_length + r_weight / r_length) * not_repeated assert f(0.25, 1, 0.25, -2, False) == 0
benchmark_functions_edited/f5793.py
def f(value, replace_value): if value is None: return replace_value else: return value assert f(1, 0) == 1
benchmark_functions_edited/f454.py
def f(ok): if ok: return 1 else: return -1 assert f(f(True)) == 1
benchmark_functions_edited/f7903.py
def f(xs, slope, y0): ys = slope * xs + y0 return ys assert f(1, 0, 0) == 0
benchmark_functions_edited/f8957.py
def f(num: int, array: list) -> int: if num < 2: return num array[num] = f(num - 1, array) + f(num - 2, array) return array[num] assert f(1, [0, 1]) == 1
benchmark_functions_edited/f3600.py
def f(x): if x <= 0.0031308: return x*12.92 else: return 1.055 * x**(1/2.4) - 0.055 assert f(0) == 0
benchmark_functions_edited/f7987.py
def f(game): diff = 0 for row in game: for x in row: if x == 1: diff += 1 return diff assert f( [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]) == 4
benchmark_functions_edited/f13369.py
def f(x, in_min, in_max, out_min, out_max): return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min) assert f(100, 100, 0, 1, 10) == 1
benchmark_functions_edited/f11150.py
def f(value, type_): try: return type_(value) except Exception: return None assert f("5", lambda x: int(x) + 1) == 6
benchmark_functions_edited/f2526.py
def f(arr): assert len(arr) == 1 return arr[0] assert f([1]) == 1
benchmark_functions_edited/f993.py
def f(y_eval, mean_y, std_y): return (y_eval - mean_y) / std_y assert f(10, 10, 10) == 0
benchmark_functions_edited/f9284.py
def f(coords1, coords2): return abs(coords1[0] - coords2[0]) + abs(coords1[1] - coords2[1]) assert f( [0, 0], [0, 0]) == 0
benchmark_functions_edited/f12310.py
def f(a, ir): as_sorted = sorted(a, reverse=True) qtile1 = as_sorted[ir] return qtile1 assert f( [1, 2, 3, 4, 5], 2 ) == 3
benchmark_functions_edited/f4220.py
def f(seq1, seq2): return sum(map(lambda x: x[0] != x[1], zip(seq1, seq2))) assert f( "AAAA", "AAAA") == 0
benchmark_functions_edited/f13141.py
def f(boutlist, idle_threshold=15): idle_time = 0 for i in range(0, len(boutlist) - 2): inter_bout_time = boutlist[i + 1] - boutlist[i] if inter_bout_time > idle_threshold: idle_time += inter_bout_time return idle_time assert f([1, 2, 3, 4, 5, 6]) == 0
benchmark_functions_edited/f11618.py
def f(first_leg, second_leg): return first_leg**2 + second_leg**2 assert f(0, 1) == 1
benchmark_functions_edited/f6930.py
def f(a, b): r = a % b if r < 0: r = r + abs(b) return r assert f(4, 3) == 1
benchmark_functions_edited/f1412.py
def f(q, p): for i in range(p): if q * i % p == 1: return i assert f(4, 3) == 1
benchmark_functions_edited/f2670.py
def f(value, smallest, largest): return max(smallest, min(value, largest)) assert f(4, 1, 3) == 3
benchmark_functions_edited/f450.py
def f(item): return len(str(item)) assert f(11111111) == 8
benchmark_functions_edited/f4181.py
def f(a,b): if type(a) is int and type(b) is int: return a/b return "A and B must be ints!" assert f(8, 2) == 4
benchmark_functions_edited/f11586.py
def f( wall_x_position: float, wall_x_scale: float, sideways_left: bool ) -> float: if sideways_left: return -3 + wall_x_position - wall_x_scale / 2 return 3 + wall_x_position + wall_x_scale / 2 assert f(0, 0, False) == 3
benchmark_functions_edited/f11155.py
def f(value: str) -> int: if value == "P": return 9 elif value == "B": return 4 else: return 0 assert f(" ") == 0
benchmark_functions_edited/f244.py
def f(v): return 0 if v <= 0 else v assert f(-1) == 0
benchmark_functions_edited/f3662.py
def f(n, b=10): x, y = n, 0 while x >= b: x, r = divmod(x, b) y = b * y + r return b * y + x assert f(10) == 1
benchmark_functions_edited/f5080.py
def f(x, r, n): return pow(x, r, n) assert f(3, 0, 3) == 1
benchmark_functions_edited/f13470.py
def f(A,target): def rf(lo, hi, target): if lo == hi: return 1 if A[lo] == target else 0 mid = (lo+hi)//2 left = rf(lo, mid, target) right = rf(mid+1, hi, target) return left + right return rf(0, len(A)-1, target) assert f(list(range(10)), 10) == 0
benchmark_functions_edited/f3221.py
def f(x, y): while (y): x, y = y, x % y return x assert f(10, 5) == 5
benchmark_functions_edited/f8205.py
def f(data): if not data: raise Exception("Empty data.") sum_x = sum(data) mean = float(sum_x) / len(data) return mean assert f([1, 2, 3, 4, 5]) == 3
benchmark_functions_edited/f1619.py
def f(a, b): return abs((a - b) / a) assert f(1, 0) == 1
benchmark_functions_edited/f12561.py
def f(vals)->float: rval=1.0 count = 0 for val in vals: val = vals[count] if val != 0: rval *= val count+=1 if count != 0: rval = pow(rval, 1.0/count) return(rval) assert f([1]) == 1
benchmark_functions_edited/f9376.py
def f( r0: float, params: dict ) -> float: return r0 * params["gamma"] assert f(1, {"gamma": 1}) == 1
benchmark_functions_edited/f4019.py
def f(i): if i > 2147483647: return 2 else: return 3 assert f(12345) == 3
benchmark_functions_edited/f9974.py
def f(e): if isinstance(e, PermissionError): code = 126 elif isinstance(e, FileNotFoundError): code = 127 else: code = 1 return code assert f(TypeError('spam')) == 1
benchmark_functions_edited/f7525.py
def f(x): x_sorted = sorted(x) mid = len(x) // 2 if len(x) % 2 == 1: return x_sorted[mid] else: l = mid - 1 h = mid return (x_sorted[l] + x_sorted[h]) / 2 assert f([1,2,3]) == 2
benchmark_functions_edited/f1142.py
def f(v,epsilon, sigma): return (4*epsilon*(pow(sigma/v,12) - pow(sigma/v,6))) assert f(20, 0, 2) == 0
benchmark_functions_edited/f12622.py
def f(size, *coordinates): x_axis = size[0] result = tuple(x + y * x_axis for x, y in coordinates) if len(result) == 1: return result[0] return result assert f((3, 3), (0, 2)) == 6
benchmark_functions_edited/f6478.py
def f(n, r): s = 0 for k in range(1, n + 1): s += pow(r, k) return s assert f(0, 2) == 0
benchmark_functions_edited/f9048.py
def f(ls): m = -1.0 result = -1 for n, l in enumerate(ls): if l > m: m = l result = n return result assert f( [0, 1, 0] ) == 1
benchmark_functions_edited/f2988.py
def f(a,b): return (a[0]-b[0])**2 +(a[1]-b[1])**2 + (a[2]-b[2])**2 assert f( (1,1,1), (1,1,1) ) == 0
benchmark_functions_edited/f9234.py
def f(prices): max_p = c_p = 0 for i in range(1, len(prices)): c_p += prices[i] - prices[i - 1] if c_p < 0: c_p = 0 if c_p > max_p: max_p = c_p return max_p assert f([3]) == 0
benchmark_functions_edited/f9445.py
def f(a, b, c): if a == b: return c elif a == c: return b elif b == c: return a assert f(3, 3, 2) == 2
benchmark_functions_edited/f9145.py
def f(value): value = value & 0xFFFFFFFFFFFFFFFF if value & 0x8000000000000000: value = ~value + 1 & 0xFFFFFFFFFFFFFFFF return -value else: return value assert f(0x0000000000000002) == 2
benchmark_functions_edited/f7740.py
def f(cards, colour): iter = [card.rank for card in cards if card.colour.lower() == colour.lower()] if not iter: return 0 return max(iter) assert f([], 'hearts') == 0
benchmark_functions_edited/f14061.py
def f(self, attrsD, contentparams): if attrsD.get('mode', '') == 'base64': return 0 if self.contentparams['type'].startswith('text/'): return 0 if self.contentparams['type'].endswith('+xml'): return 0 if self.contentparams['type'].endswith('/xml'): return 0 if self.contentparams['type'].endswith('/json'): return 0 return 0 assert f(None, {'mode': 'base64'}, None) == 0
benchmark_functions_edited/f3235.py
def f(number): if number < 2: return number return f(number - 1) + f(number - 2) assert f(5) == 5
benchmark_functions_edited/f983.py
def f(number): result = number ** 2 return result assert f(2) == 4
benchmark_functions_edited/f7580.py
def f(x): if x < 0: x = 360 - x elif x > 360: x = x - 360 return x assert f(5) == 5
benchmark_functions_edited/f9096.py
def f(strand_a: str, strand_b: str) -> int: if not len(strand_a) == len(strand_b): raise ValueError("Sequences must be of equal length.") return sum([s1 != s2 for s1, s2 in zip(strand_a, strand_b)]) assert f( "GAGCCTACTAACGGGAT", "CATCGTAATGACGGCCT") == 7
benchmark_functions_edited/f11075.py
def f(json, abspath): out = json for elt in abspath: out = out[elt] return out assert f({'a': 1, 'b': 2}, ['a']) == 1
benchmark_functions_edited/f2834.py
def f(poly): while poly and poly[-1] == 0: poly.pop() # normalize return len(poly)-1 assert f( [0,1] ) == 1
benchmark_functions_edited/f9221.py
def f(word: str): return len(set(word)) assert f("taste") == 4
benchmark_functions_edited/f138.py
def f(v): return int(v) if v is not None else None assert f(1.9) == 1
benchmark_functions_edited/f10646.py
def f(fitness, logger, ind): if not ind: return fitness # Punish for number of actions if fitness > 0: logger.debug("Punishing for complexity: %d" % len(ind)) fitness -= len(ind) return fitness assert f(0, None, None) == 0
benchmark_functions_edited/f787.py
def f(A, B): return (A[1] - B[1]) / (A[0] - B[0]); assert f( (0,0), (1,1) ) == 1
benchmark_functions_edited/f2887.py
def f(x, y): return sum(xi == yi for xi, yi in zip(x, y)) assert f('', '') == 0
benchmark_functions_edited/f8401.py
def f(val, minimum, maximum): return min(max(val, minimum), maximum) assert f(3, 1, 3) == 3
benchmark_functions_edited/f2202.py
def count_missing (vect): return vect.count('NA') assert f( ['1','2','NA'] ) == 1
benchmark_functions_edited/f3583.py
def f(in_size: int) -> int: conv = 1024 * 1024 * 1024 return in_size // conv assert f(1000) == 0
benchmark_functions_edited/f980.py
def f(y, p_x): v_x = p_x + y return v_x assert f(0, 1) == 1
benchmark_functions_edited/f7651.py
def f(value): if value <= 127: return 1 elif value <= 16383: return 2 elif value <= 2097151: return 3 else: return 4 assert f(0) == 1
benchmark_functions_edited/f7295.py
def f(remain, coin, qty): max_qty = 0 while remain >= coin and qty - max_qty > 0: remain = remain-coin max_qty += 1 return max_qty assert f(10, 10, 1) == 1
benchmark_functions_edited/f13719.py
def f(strArg, composList, atomDict): accum = [] for atom, num in composList: tStr = strArg.replace('DEADBEEF', atom) accum.append(eval(tStr)) return min(accum) assert f( '1', [('O', 2), ('N', 1)], {'O': 1.0, 'N': 0.0}) == 1
benchmark_functions_edited/f7404.py
def f(value, default=0): if value is None: return default try: return int(value) except ValueError: return default assert f("") == 0
benchmark_functions_edited/f4148.py
def f(rate): from math import floor return floor((1.0 / rate) * (1e9 / 25)) assert f(220e6) == 0
benchmark_functions_edited/f11411.py
def f(q, u_dc): u_ac = q*u_dc return u_ac assert f(0, 1) == 0
benchmark_functions_edited/f10104.py
def f(element, table_size): char_val_list = list(map(lambda x: ord(x), str(element))) hash_val = 0 for val in char_val_list: hash_val += val index = hash_val % table_size return index assert f({'a': 1, 'b': 2, 'c': 3}, 1) == 0
benchmark_functions_edited/f1749.py
def f(x, limits): return limits[1] - (x - limits[0]) assert f(3, [1,4]) == 2
benchmark_functions_edited/f6307.py
def f(x): return 1 if x==0 else 2**(x - 1).bit_length() assert f(3) == 4
benchmark_functions_edited/f509.py
def f(A, B): return A[0] * B[1] - A[1] * B[0] assert f( (0, 0), (3, 4) ) == 0
benchmark_functions_edited/f7636.py
def f(tn, fp): if (fp+tn) == 0: return 0 return fp/float(fp+tn) assert f(100, 0) == 0
benchmark_functions_edited/f13731.py
def f(tokens): return sum([len(t) for t in tokens["target"]]) assert f({"train": [[], [], []], "target": [["test", "test"]]}) == 2
benchmark_functions_edited/f572.py
def f(n): return int((1 + (-1)**(n+1))/2) assert f(2) == 0
benchmark_functions_edited/f12694.py
def f(obj, value): if type(obj) == dict: return dict.get(obj, value) else: return getattr(obj, value) assert f( {'a': 2, 'b': 3}, 'a' ) == 2
benchmark_functions_edited/f12267.py
def f(box1, box2): A1 = (box1[2] - box1[0])*(box1[3] - box1[1]) A2 = (box2[2] - box2[0])*(box2[3] - box2[1]) xmin = max(box1[0], box2[0]) ymin = max(box1[1], box2[1]) xmax = min(box1[2], box2[2]) ymax = min(box1[3], box2[3]) if ymin >= ymax or xmin >= xmax: return 0 return ((xmax-xmin) * (ymax - ymin)) / (A1 + A2) assert f( (1, 2, 2, 3), (1, 1, 2, 2), ) == 0
benchmark_functions_edited/f13600.py
def f(n,r): maxProd = 1 nStr = str(n) nStrLen = len(nStr) for chunkIdx in range(nStrLen - r + 1): subStr= nStr[chunkIdx:chunkIdx+r] subProd=1 for digit in subStr: subProd *= int(digit) if subProd>maxProd: maxProd=subProd return maxProd assert f(123, 3) == 6
benchmark_functions_edited/f6558.py
def f(Q1,Q2,Q3,num,denom): if (num > 0 and denom > 0) or (num < 0 and denom < 0): Q_r = Q1+min(num/denom,1)/2*(Q2-Q3) else: Q_r = Q1 return Q_r assert f(1,2,3,-0,0) == 1