file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f7319.py
def f(lyrics): lyrics_a = lyrics.replace(r"\n", " ") lyrics_b = lyrics_a.replace(r"\r", " ") text_list = list(lyrics_b.rsplit()) words_count = len(text_list) return words_count assert f("") == 0
benchmark_functions_edited/f12238.py
def f(values, target): first = 0 last = len(values) while first < last: middle = (first + last) // 2 if values[middle][0] < target: first = middle + 1 else: last = middle return first assert f(((1, 2), (3, 4), (5, 6)), 42) == 3
benchmark_functions_edited/f13167.py
def f(dataset_name): dataset_name = dataset_name.lower() mapping = { 'mnist': 28 * 28, 'adult': 6, 'pums': 4, 'power': 8 } if dataset_name not in mapping: err_msg = f"Unknown dataset '{dataset_name}'. Please choose one in {list(mapping.keys())}." raise Va...
benchmark_functions_edited/f620.py
def f(a, b): out = a + b return out assert f(4, 5) == 9
benchmark_functions_edited/f11279.py
def f(n: int, d: int) -> int: assert n > 1 assert 0 <= d <= 1 return round((2 * n - 4) * d ** 2 + d * (n - 2) ** 2 + n) assert f(3, 1) == 6
benchmark_functions_edited/f9026.py
def f(values): if isinstance(values, (list, tuple)): res = [] for v in values: res.append(f(v)) return tuple(res) return int(values) assert f(0.1) == 0
benchmark_functions_edited/f4474.py
def f(matrix): for a in matrix: for color in a: if color != 0: return color assert f( [[1, 1, 1], [1, 1, 1]] ) == 1
benchmark_functions_edited/f8095.py
def f(sections, id): for idx, section in enumerate(sections): try: if section['id'] == id: return idx except KeyError: continue return None assert f( [ {"name": "intro", "id": "intro"}, {"name": "body", "id": "body"}, {"name": ...
benchmark_functions_edited/f7929.py
def f(iterator, msg): try: retval = next(iterator) except StopIteration as e: raise ValueError("Data prematurely exhausted in '{0}' dataset" .format(msg)) from e return retval assert f(iter([1, 2, 3]), 'test') == 1
benchmark_functions_edited/f12820.py
def f(expr): if isinstance(expr, list): return len(expr) return len(expr.args) assert f([1, 2, 3, 4, 5]) == 5
benchmark_functions_edited/f6629.py
def f(string, offset): for index in range(offset, len(string)): if string[index].isupper(): return index return None assert f(u"A1234", 0) == 0
benchmark_functions_edited/f11254.py
def f(y_true, y_pred): # intialize the counter fn = 0 for yt, yp in zip(y_true, y_pred): if yt == 1 and yp == 0: fn += 1 return fn assert f( [0, 1, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1] ) == 0
benchmark_functions_edited/f5015.py
def f(n, k, q = 2): c = 1 for j in range(k): c *= q**n - q**j for j in range(k): c //= q**k - q**j return c assert f(3, 3) == 1
benchmark_functions_edited/f3654.py
def f(pGate, pRef, dimension): return ((1 - (pGate / pRef)) * (dimension - 1)) / dimension assert f(1 / 8, 1 / 8, 8) == 0
benchmark_functions_edited/f5389.py
def f(x): x = sorted(x) m = int(len(x) / 2.0) if len(x) % 2 == 0: return (x[m] + x[m-1]) / 2.0 else: return x[m] assert f([1,2,3]) == 2
benchmark_functions_edited/f2408.py
def f(m, point): b = (point[1] - (m * point[0])) return b assert f(0, [1, 1]) == 1
benchmark_functions_edited/f6945.py
def f(x, fx): fx = fx % 3 x = x % 3 if fx > x: return x + 1 elif fx < x: return x - 1 else: return x assert f(0, 1) == 1
benchmark_functions_edited/f12717.py
def f(x): # e.g. x= 95 (1101111) count = 0 while x > 0: x = x & (x << 1) count += 1 return count assert f(255) == 8
benchmark_functions_edited/f353.py
def f(n): return int(n * (3*n - 2)) assert f(1) == 1
benchmark_functions_edited/f10752.py
def f(x, y): r = (x + int(y / 2)) & ~(y - 1) if r > x: r = r - y return r assert f(0, 4) == 0
benchmark_functions_edited/f12287.py
def f(m, v, r): return m * v**2 / r assert f(2, 2, 2) == 4
benchmark_functions_edited/f3540.py
def f(buf): value = 0 for idx, val in enumerate(buf): value += val << (idx * 8) return value assert f(b'\x00') == 0
benchmark_functions_edited/f5155.py
def f(field): hype = 0 for y in range(len(field)): for x in range(len(field[y])): if field[y][x] == 'o': hype += 1 return hype assert f( [ [None, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, ...
benchmark_functions_edited/f14539.py
def f(xi, yi, h, f): m1 = f(xi, yi) m2 = f(xi + h, yi + h * m1) return yi + h /2 * (m1 + m2) assert f(0, 1, 1, lambda x,y: 2*x) == 2
benchmark_functions_edited/f11157.py
def f(rel): for index, element in enumerate(rel): if element == 1: return index continue # Should never reach here: None only on error return None assert f([None,None,1]) == 2
benchmark_functions_edited/f10920.py
def f(target): step = 0 while target !=0: if target%2!=0: target -=1 else: target = target/2 step += 1 return step assert f(24) == 6
benchmark_functions_edited/f2102.py
def f(x, y, a=1, b=100): return -1 * ((a - x)**2 + b * (y - x**2)**2) assert f(1, 1) == 0
benchmark_functions_edited/f3967.py
def f(group_size, bytes_wide): return int((group_size * 2) * bytes_wide / (group_size) + bytes_wide / (group_size)) - 1 assert f(5, 2) == 3
benchmark_functions_edited/f14091.py
def f(val1, val2): return int(val1 + int(val2[0])) assert f(3, ['1']) == 4
benchmark_functions_edited/f4029.py
def f(v, lag): tmp = 0 N = len(v)-lag for j in range(N): tmp += v[j]*v[j+lag] return tmp/N assert f( [0,1,0], 1 ) == 0
benchmark_functions_edited/f6175.py
def f(num_1: float, num_2: float, num_3: float) -> float: return max(num_1 + num_2, num_1 + num_3, num_2 + num_3) assert f(-1, 2, 3) == 5
benchmark_functions_edited/f13543.py
def f(d, ks, default=None): *ks_, last = ks d_ = d for k in ks_: if type(d_) != dict or k not in d_: return default d_ = d_[k] if type(d_) == dict: return d_.get(last, default) return default assert f({"x": 1}, ["x"]) == 1
benchmark_functions_edited/f9490.py
def f(x, x1, y1, x2, y2): return complex((y1.real - y2.real) / (x1 - x2) * x + (y2.real * x1 - x2 * y1.real) / (x1 - x2), (y1.imag - y2.imag) / (x1 - x2) * x + (y2.imag * x1 - x2 * y1.imag) / (x1 - x2)) assert f(0, 0, 1, 1, 2) == 1
benchmark_functions_edited/f11386.py
def f(dividend, divisor): try: return int(dividend) // int(divisor) except (ZeroDivisionError, ValueError) as exception: return f"{exception.__class__.__name__}: {exception}" assert f(5, 3) == 1
benchmark_functions_edited/f1418.py
def f(x): return 63 * x**5 - 70 * x**3 + 15 * x + 2 assert f(0) == 2
benchmark_functions_edited/f13861.py
def f(number_blocks): if number_blocks == 0: return 0 if number_blocks == 1: return 1 else: return (1 + 2 * f(number_blocks -1)) assert f(0) == 0
benchmark_functions_edited/f4177.py
def f(n): base = [1, 1] for i in range(2, n + 1): base.append(base[i - 1] + base[i - 2]) return base[n] assert f(0) == 1
benchmark_functions_edited/f1187.py
def f(value, low, high): return max(low, min(high, value)) assert f(3, 1, 2) == 2
benchmark_functions_edited/f9993.py
def f(string: str) -> int: try: output = int(float(string)) except ValueError: output = 0 return output assert f(1.5) == 1
benchmark_functions_edited/f2655.py
def f(x,coefs): y = 0. for coef in coefs[-1::-1]: y = y*x + coef return y assert f(1,[1,1,1,1,0]) == 4
benchmark_functions_edited/f1722.py
def f(s3,s5): totalsum=s3+s5 return totalsum assert f(0,0) == 0
benchmark_functions_edited/f8052.py
def f(_int, default): try: integer = int(_int) except: # pylint: disable-msg=bare-except integer = default return integer assert f('2', 1) == 2
benchmark_functions_edited/f5484.py
def f(edge_u, edge_v, edge_data): if edge_data.get("priority"): return edge_data["priority"] return 1 assert f(None, None, {}) == 1
benchmark_functions_edited/f12674.py
def f(name, table): start_point = len(table) for character in name: table.append(ord(character)) # closing \0' character table.append(0) return start_point assert f( "a", bytearray() ) == 0
benchmark_functions_edited/f13477.py
def f(box_a, box_b): x_a = max(box_a[0], box_b[0]) y_a = max(box_a[1], box_b[1]) x_b = min(box_a[2], box_b[2]) y_b = min(box_a[3], box_b[3]) intersection_area = max(0, x_b - x_a) * max(0, y_b - y_a) return intersection_area assert f( [0, 0, 0, 0], [0, 0, 0, 0] ) == 0
benchmark_functions_edited/f11358.py
def f(n, l_n): if n < 10: if n > l_n: l_n = n return l_n else: k = n % 10 # get units digit if k > l_n: # get largest digit l_n = k n //= 10 # divide by 10 return f(n, l_n) assert f(12345, 0) == 5
benchmark_functions_edited/f6266.py
def f(input_text: str, token_lexpos: int) -> int: line_start = input_text.rfind('\n', 0, token_lexpos) + 1 return (token_lexpos - line_start) + 1 assert f( 'hello\nworld', 0) == 1
benchmark_functions_edited/f7276.py
def f(val, mask): val = val & mask if val & ~(mask>>1): val |= ~mask return val assert f(0b11111111, 0b00000000) == 0
benchmark_functions_edited/f5606.py
def f(lst, search_term): return lst.count(search_term) assert f([1, 4, 3, 4, 4], 4) == 3
benchmark_functions_edited/f13615.py
def f(increment, level): if level == 1: return 3 return increment*level+1 assert f(2, 3) == 7
benchmark_functions_edited/f1924.py
def f(binary: str): return int(binary, 2) assert f("11") == 3
benchmark_functions_edited/f14086.py
def f(a, b): # get commong dict keys: common_keys = set(a).intersection(set(b)) dotproduct = 0 for key in common_keys: prod = a[key] * b[key] dotproduct += prod return dotproduct assert f({"a": 1}, dict()) == 0
benchmark_functions_edited/f5298.py
def f(i,j,table): product = 1 for num in range(4): if i+num>19 or j-num<0: product *= 1 else:product *= int(table[i+num][j-num]) return product assert f(0, 0, [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]) == 1
benchmark_functions_edited/f14372.py
def f(string): BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" base = len(BASE62) strlen = len(string) num = 0 idx = 0 for char in string: power = (strlen - (idx + 1)) num += BASE62.index(char) * (base ** power) idx += 1 return num as...
benchmark_functions_edited/f8677.py
def f(angle): if angle < -10: return 1 elif angle > 10: return 2 return 0 assert f(100) == 2
benchmark_functions_edited/f10706.py
def f(string: int, bitval: str = '1') -> int: return bin(string).count(bitval) assert f(0b0111) == 3
benchmark_functions_edited/f7866.py
def f(val, params): # print(val) if val < params[1]: # sea return 0 if val < params[2]: # plains return 1 if val < params[3]: # hills return 2 return 3 assert f(100, (300, 200, 350, 500)) == 0
benchmark_functions_edited/f1406.py
def f(x): res = 0 for v in x: res += v return res assert f(set([1, 2, 3])) == 6
benchmark_functions_edited/f9057.py
def f(str_x): try: # multiplied and divided by 100 to overcome rounding bug x = round((float(str_x) * 100) / 100, 4) return int(x) if x.is_integer() else x except ValueError: print(f"{str_x} is not a number") assert f(0.0) == 0
benchmark_functions_edited/f11241.py
def f(a, b): "*** YOUR CODE HERE ***" if a < b: return f(b, a) if a % b == 0: return b return f(b, a % b) assert f(29, 10) == 1
benchmark_functions_edited/f12256.py
def f(check_number): def digits_of(n): return [int(d) for d in str(n)] digits = digits_of(check_number) odd_digits = digits[-1::-2] even_digits = digits[-2::-2] checksum = 0 checksum += sum(odd_digits) for d in even_digits: checksum += sum(digits_of(d * 2)) return checksu...
benchmark_functions_edited/f3881.py
def f(toks, start_idx): idx = start_idx while idx < len(toks) and toks[idx] == ";": idx += 1 return idx assert f( [";", "a", "b", "c"], 0 ) == 1
benchmark_functions_edited/f4264.py
def f(name): try: counts = int(name.split("_x")[1]) except: return 0 return counts assert f(r"../data/reads/A.fq.gz") == 0
benchmark_functions_edited/f5139.py
def f(sample): return sum(sample) / len(sample) assert f([1, 2, 3, 4, 5]) == 3
benchmark_functions_edited/f2674.py
def f(elements): if not elements: return 0 return max(e["trials"] for e in elements) assert f([{"trials": 1}, {"trials": 1}, {"trials": 2}]) == 2
benchmark_functions_edited/f4355.py
def f(x, factor=10): return int(x/factor) * factor assert f(5, 5) == 5
benchmark_functions_edited/f8185.py
def f(kwargs, key, replacement): if key not in kwargs: return replacement elif key in kwargs and kwargs[key] is None: return replacement else: return kwargs[key] assert f( {'a': 1, 'b': None, 'c': None}, 'd', 4) == 4
benchmark_functions_edited/f11514.py
def f(S): denom = S[0][0] + S[1][1] + S[0][1] + S[1][0] if denom == 0: return 0 return (S[0][1] - S[1][0]) / denom assert f( [ [10, 0], [0, 9] ] ) == 0
benchmark_functions_edited/f12507.py
def f(array, item): # loop over all array values until item is found for index, value in enumerate(array): #O(n) if item == value: #O(1) return index # found O(1) return None assert f( [6, 5, 2, 7, 1, 3, 8, 9, 4], 6) == 0
benchmark_functions_edited/f4778.py
def f(x0, y0, x1, y1, x_new): return y0 + ((x_new - x0) / (x1 - x0)) * (y1 - y0) assert f(1, 2, 3, 4, 5) == 6
benchmark_functions_edited/f9586.py
def f(array, value): result = -1 for i in reversed(range(len(array))): entry = array[i] if entry == value or (callable(value) and value(entry)): return i return result assert f(list("foo"), "f") == 0
benchmark_functions_edited/f1880.py
def f(pos, vel): return sum([abs(e) for e in pos]) * sum([abs(e) for e in vel]) assert f( (3, 0, 0), (2, 0, 0) ) == 6
benchmark_functions_edited/f10562.py
def f(x, a, b): return a*(x**b) assert f(0, 0, 2) == 0
benchmark_functions_edited/f12294.py
def f(yield_potential): farm_hours = yield_potential*0.2 labour_cost = farm_hours * 7 # wage return labour_cost assert f(0) == 0
benchmark_functions_edited/f6283.py
def f(a, b): if b == 0: return a else: return f(b, a % b) assert f(15, 10) == 5
benchmark_functions_edited/f1967.py
def f(s): return s.strip().count("\n") + 1 assert f( "\n" "hello world\n" "hello again\n" "goodbye" ) == 3
benchmark_functions_edited/f12413.py
def f(Letter): Number = ord(Letter) - 64 return Number assert f( "G" ) == 7
benchmark_functions_edited/f3017.py
def f(data, start, length): return int.from_bytes(data[start:start+length], byteorder='big') assert f(b'\x05', 0, 1) == 5
benchmark_functions_edited/f11712.py
def f(blur_o, blur_d, routing): if routing == 'slope': c = 0 elif routing == 'balance': c = 1 else: c = 2 if (not blur_o) or (not blur_d): return 0 else: return int(blur_o) + int(blur_d) + c assert f(0, 0, 'balance') == 0
benchmark_functions_edited/f12922.py
def f(array): if not array: return 0 elif len(array) == 1: return array[0] max_sum = float() second = array[0] first = max(array[0], array[1]) for x in array[2:]: current = max(second + x, first) second = first first = current return first assert f...
benchmark_functions_edited/f6312.py
def f(step, num_steps, values): num_segments = len(values) index = min(step * num_segments // num_steps, num_segments - 1) return values[index] assert f(100, 100, [1, 2, 3]) == 3
benchmark_functions_edited/f13665.py
def f(a, m, k): if a == 0: if k == 0: return 0 else: raise ValueError(f"{a}x%{m}={k} - No SOLUTIONS") if a == 1: return k % m if k % a == 0: return k // a new_x = f( a=m % a, m=a, k=(a - k) % a ) x = (k + new_x * ...
benchmark_functions_edited/f9388.py
def f(data_per_month_gb, percentage_share): per_user_mbps = ( data_per_month_gb * 1000 * 8 * (1/30) * (percentage_share/100) * (1/3600) ) return per_user_mbps assert f(2, 0) == 0
benchmark_functions_edited/f4765.py
def f(x, y, a): return x * (1 - a) + y * a assert f(1, 2, 1.) == 2
benchmark_functions_edited/f10621.py
def f(y): import numpy as np mxabs = np.max(np.abs(y)) if mxabs == 0.0: return 0 else: mx = np.max(y) if mxabs == mx: return 1 else: return -1 assert f([1, 2]) == 1
benchmark_functions_edited/f9540.py
def f(left, right): distance = 0 for left_token, right_token in zip(left, right): if left_token != right_token: distance += 1 return distance assert f('ab', 'ac') == 1
benchmark_functions_edited/f2445.py
def f(*_x): _sum = 0 for _temp in _x: _sum = int(_temp) + _sum return _sum assert f(1) == 1
benchmark_functions_edited/f9359.py
def f(original: list, new: list) -> int: for index, (e1, e2) in enumerate(zip(original, new)): if e1 != e2: return index return min(len(original), len(new)) assert f( [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8]) == 8
benchmark_functions_edited/f5752.py
def f(a, x): hi = len(a) lo = 0 while lo < hi: mid = (lo + hi) // 2 if x < a[mid]: hi = mid else: lo = mid + 1 return lo - 1 assert f(list(range(10)), 4) == 4
benchmark_functions_edited/f694.py
def f(b,h): return .5*b*h assert f(0, 10) == 0
benchmark_functions_edited/f6978.py
def f(values): values = list(values) # In case this is a complex type, get a simple list. if not values: return None else: return min(values) assert f([2, 3]) == 2
benchmark_functions_edited/f2573.py
def f(strg): sum = 0 for i in strg[3:]: sum += int(i) if sum == 0: sum = 1 return sum assert f("345") == 1
benchmark_functions_edited/f9650.py
def f(n, m): assert n >= 0 and m >= 0 if n == 0 or m == 0: return 1 else: return f(n - 1, m) + f(n, m - 1) assert f(0, 10) == 1
benchmark_functions_edited/f4456.py
def f(a, x): for i in range(len(a)): if a[i] == x: return i return None assert f(range(5), 2) == 2
benchmark_functions_edited/f8894.py
def f(a1,a2,a3): a_mid_0 = a2[1]*a3[2] - a2[2]*a3[1] a_mid_1 = a2[2]*a3[0] - a2[0]*a3[2] a_mid_2 = a2[0]*a3[1] - a2[1]*a3[0] return abs(float(a1[0]*a_mid_0 + a1[1]*a_mid_1 + a1[2]*a_mid_2)) assert f( (1,0,0), (0,2,0), (0,0,1) ) == 2
benchmark_functions_edited/f1064.py
def f(a, b): return (a + b - 1) // b assert f(3, 1) == 3
benchmark_functions_edited/f10022.py
def f(N, P): if len(N)==0: return 0.0 n = int(round(P * len(N) + 0.5)) return N[n-1] assert f(range(10), 0.6) == 5
benchmark_functions_edited/f4651.py
def f(arr): lo, hi = 0, len(arr) while lo < hi: mid = lo + hi >> 1 if arr[mid]: hi = mid else: lo = mid + 1 return lo assert f([False, True, True]) == 1
benchmark_functions_edited/f7026.py
def f(n,k): if k > n-k: k = n-k # Use symmetry of Pascal's triangle accum = 1 for i in range(1,k+1): accum *= (n - (k - i)) accum /= i return accum assert f(3,2) == 3
benchmark_functions_edited/f8359.py
def f(list_in): mean = sum(list_in) / len(list_in) return(mean) assert f([1, 2, 3, 4, 5]) == 3