file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f8519.py
def f(obj, index): if not isinstance(obj, (tuple, list)): raise TypeError(f"Should not get item from a object that not sequence type, obj: {obj}") # Not check index out of range by self. return obj[index] assert f((0, 1), 1) == 1
benchmark_functions_edited/f6281.py
def f(pp): p, a = pp if p == 2 and a > 2: return 2 ** (a - 2) else: return (p - 1) * (p ** (a - 1)) assert f( (2, 2) ) == 2
benchmark_functions_edited/f13317.py
def f(x, p0=0.5, r=0.1): if max(0, p0 - r) < x < min(1, p0 + r): return 1 else: return 0 assert f(0.875, 0.35, 0.15) == 0
benchmark_functions_edited/f5294.py
def f(disks): nr = 0 for disk in disks: if disks[disk]['partitions']: nr += 1 return nr assert f({1: {'partitions': [{'mount': '/', 'type': 'ext4'}]}}) == 1
benchmark_functions_edited/f418.py
def f(iterator): return sum(1 for i in iterator) assert f(filter(lambda x: x, [1, 2, 3])) == 3
benchmark_functions_edited/f5469.py
def f(x, scale, x_o, gamma_o): y = ( scale * ((gamma_o / x_o) ** 2) / ((x / x_o - x_o / x) ** 2 + (gamma_o / x_o) ** 2) ) return y assert f(10, 0, 5, 0) == 0
benchmark_functions_edited/f3085.py
def f(bit_string): return 2**sum(bit_string) assert f( [0, 1, 0, 1] ) == 4
benchmark_functions_edited/f3769.py
def f(x): if x-1 >= 0: return x-1 return 0 assert f(10) == 9
benchmark_functions_edited/f13278.py
def f(a,b): result = 1 while b != 0: if b & 1: result *= a b >>= 1 a *= a return result assert f(2, 2) == 4
benchmark_functions_edited/f5539.py
def f(args): # args[0] is function, args[1] is positional args, and args[2] is kwargs return args[0](*(args[1]), **(args[2])) assert f( (lambda x, **y: x+sum(y.values()), (1,), {'y':2}) ) == 3
benchmark_functions_edited/f6576.py
def f(current_x, current_y, goal_x, goal_y): return max(abs(current_x - goal_x), abs(current_y - goal_y)) assert f(1, 1, 2, 2) == 1
benchmark_functions_edited/f7.py
def f(x): return pow(x, 1/2) assert f(25) == 5
benchmark_functions_edited/f5470.py
def f(num: int): try: return num.f() # Python 3.10 (~6 times faster) except AttributeError: return bin(num).count("1") assert f(15) == 4
benchmark_functions_edited/f12368.py
def f(m: int, n: int): result = 0 for a in range(0,(m+n)): for b in range (0, (m+n)): if a+b == m and a^b == n: result += 1 return result assert f(2, 1) == 0
benchmark_functions_edited/f5847.py
def f(number: int or float, low: int or float, high: int or float) -> int or float: if number < low: return low if number > high: return high return number assert f(10, 1, 5) == 5
benchmark_functions_edited/f1268.py
def f(num1, num2): result = num1 * num2 return result assert f(2, 4) == 8
benchmark_functions_edited/f7037.py
def f(payload): return payload['identity'] assert f( {'identity': 1, 'exp': 0.0} ) == 1
benchmark_functions_edited/f955.py
def f(individual): return sum(x**2 for x in individual) assert f((0, 0)) == 0
benchmark_functions_edited/f1790.py
def f(reference, array): return ((array - reference) / reference) * 100 assert f(-1, -1) == 0
benchmark_functions_edited/f7136.py
def f(*args): if any(x is not None for x in args): return max(x for x in args if x is not None) return None assert f(3, None, 1) == 3
benchmark_functions_edited/f8196.py
def f(start, end, sweep_direction): return (sweep_direction * (end - start)) % 360 assert f(45, 50, 1) == 5
benchmark_functions_edited/f12319.py
def f(n): if n < 2: return n prev_number = 1 current_number = 1 # f(2) result = 1 for idx in range(3, n+1): result = current_number + prev_number prev_number = current_number current_number = result return result assert f(5) == 5
benchmark_functions_edited/f10888.py
def f(mbars): return (mbars - 1013.25) / 101.41830484045322 assert f(1013.25) == 0
benchmark_functions_edited/f5029.py
def f(samp1, samp2): nmatch = 0 for cname in samp2: if cname in samp1: nmatch += 1 return nmatch assert f( {'a': 1, 'b': 2, 'c': 3}, {'c': 3, 'b': 2, 'd': 4} ) == 2
benchmark_functions_edited/f5092.py
def f(relation): return relation.id if type(relation).__name__ == 'Relation' else relation assert f(1) == 1
benchmark_functions_edited/f9436.py
def f(i): bn = 1 while True: i >>= 7 if i == 1: # negative sign bit return bn + 1 elif i == 0: return bn i >>= 1 bn += 1 assert f(1024) == 2
benchmark_functions_edited/f11381.py
def f(matrix, tactics): max_len = 0 for tactic in tactics: if matrix.get(tactic['x_mitre_shortname']): if len(matrix[tactic['x_mitre_shortname']]) > max_len: max_len = len(matrix[tactic['x_mitre_shortname']]) return max_len assert f( {'foo': ['bar']}, [{'x_mitre_shortname': 'foo'}] ) == 1
benchmark_functions_edited/f12925.py
def f(x, m, M=None): if M is None: M = m[1] m = m[0] # bound x between min (m) and Max (M) return min(max(x, m), M) assert f(-1, 1, 3) == 1
benchmark_functions_edited/f13973.py
def f(seq1, seq2): _sum_ = _max_ = _pos_ = float("-inf") for pos, ij in enumerate(zip(seq1, seq2)): _sum_ = sum(ij) if _sum_ > _max_: _max_ = _sum_ _pos_ = pos return _pos_ assert f((1, 2, 3), (1, 0, 1)) == 2
benchmark_functions_edited/f3632.py
def f(value): if not value > 0: raise ValueError("expected positive integer") return value assert f(1) == 1
benchmark_functions_edited/f10293.py
def f(nums): res = min(nums) while res > 0: ok = 0 for n in nums: if n % res != 0: break else: ok += 1 if ok == len(nums): break res -= 1 return res if res > 0 else 1 assert f(set(range(1, 8))) == 1
benchmark_functions_edited/f2986.py
def f(iterable): n = 0 for item in iterable: n += 1 return n assert f({1: 'a', 2: 'b', 3: 'c'}) == 3
benchmark_functions_edited/f7604.py
def f(aseq, bseq): assert len(aseq) == len(bseq) return sum(a == b for a, b in zip(aseq, bseq) if not (a in '-.' and b in '-.')) assert f('0987654321', '1234567890') == 0
benchmark_functions_edited/f9036.py
def f(n: int) -> int: reversed_n = [] while n != 0: i = n % 10 reversed_n.append(i) n = (n - i) // 10 return int(''.join(map(str, reversed_n))) assert f(1) == 1
benchmark_functions_edited/f6469.py
def f(arg): if not arg: return None arg = int(arg) if arg < 1 or arg > 65535: raise ValueError("invalid port value!") return arg assert f(1) == 1
benchmark_functions_edited/f218.py
def f(x): return int(x**0.5) assert f(17) == 4
benchmark_functions_edited/f284.py
def f(x, a, b, c): return a*x**2 + b*x + c assert f(1, 1, 2, 1) == 4
benchmark_functions_edited/f12157.py
def f(fitness: float, size: int, p_coeff: float) -> float: return fitness - p_coeff * size assert f(1, 1, 1) == 0
benchmark_functions_edited/f4327.py
def f(number): # replace letters by their ASCII number return sum(int(x) if x.isdigit() else ord(x) for x in number) % 9 assert f('{123456}') == 8
benchmark_functions_edited/f4875.py
def f(data): count = 0 for ticker in data: if ticker == 0: count += 1 return count assert f([1, 0, 1]) == 1
benchmark_functions_edited/f3907.py
def absolute_value (num): if num >=0: return num else: return -num assert f(-3) == 3
benchmark_functions_edited/f4278.py
def f(cost): f1=f2=0 for x in reversed(cost): f1,f2=x+min(f1,f2),f1 return min(f1,f2) assert f( [1,100,1,1,1,100,1,1,100,1] ) == 6
benchmark_functions_edited/f9815.py
def f(x, ys: list, remove=False): res = None if x in ys: res = x if remove: ys.remove(x) return res assert f(3, [2, 3, 4]) == 3
benchmark_functions_edited/f13822.py
def f(dist, sekpkwh=.85, kmpkwh=100): return sekpkwh * dist / kmpkwh assert f(0) == 0
benchmark_functions_edited/f8257.py
def f(privacy): if privacy == 'public-contact-data': return 0 if privacy == 'redacted-contact-data': return 1 if privacy == 'private-contact-data': return 2 assert f('public-contact-data') == 0
benchmark_functions_edited/f5812.py
def f(a, b): while b != 0: a, b = b, a % b return a assert f(15, 10) == 5
benchmark_functions_edited/f2446.py
def f(binarybits): # helps during list access decimal = int(binarybits, 2) return decimal assert f(b"00000") == 0
benchmark_functions_edited/f7165.py
def f(dekYear): weekDay = ((1 + 5*((dekYear) % 4) + 4*((dekYear) % 100) + 6*((dekYear) % 400)) % 7) + 1 return weekDay assert f(26) == 6
benchmark_functions_edited/f2226.py
def f(value): if value is not None: value = int(value) return value assert f(1.5) == 1
benchmark_functions_edited/f13300.py
def f(content, weights, alphabet): ordinal = 0 for i, c in enumerate(content): ordinal += weights[i] * alphabet.index(c) + 1 return ordinal assert f(u'', (), u'') == 0
benchmark_functions_edited/f13204.py
def f(index, length): index = int(index) if 0 <= index < length: return index elif -length <= index < 0: return index + length else: raise IndexError("index out of range: {}".format(index)) assert f(-2, 10) == 8
benchmark_functions_edited/f5359.py
def f(l): m = float("inf") index = -1 for i in range(len(l)): if l[i] < m: index = i m = l[i] return index assert f(list(range(4))) == 0
benchmark_functions_edited/f6446.py
def f(num: int) -> int: return sum(map(int, str(abs(num)))) assert f(-5) == 5
benchmark_functions_edited/f10212.py
def f(i): count = i num = 0 ans = 0 iterator = 1 while iterator <= count: if num % 2 == 0: ans = ans + num iterator = iterator + 1 num = num + 1 else: num = num + 1 return ans assert f(1) == 0
benchmark_functions_edited/f3094.py
def f(x, ndim): return (x if ndim == 0 else f(x[0], ndim - 1)) assert f([[[1, 2, 3], [4, 5, 6]]], 3) == 1
benchmark_functions_edited/f8529.py
def f(_func, *_args, **_kwds): if _func is not None: return _func(*_args, **_kwds) assert f(lambda x: x + 1, 3) == 4
benchmark_functions_edited/f2068.py
def f(t, b, c, d): t /= d t -= 1 return c * (t * t * t + 1) + b assert f(0, 0, 10, 10) == 0
benchmark_functions_edited/f11723.py
def f(point1, point2): import math if not len(point1) == len(point2): print("Wrong dimensions!") return None dist = 0 for x in range(len(point1)): dist += pow((point1[x] - point2[x]), 2) return math.sqrt(dist) assert f( (0, 0, 0), (3, 4, 0) ) == 5
benchmark_functions_edited/f12706.py
def f(n): "*** YOUR CODE HERE ***" t = 1 for i in range(2,n-1): if n % i == 0: t = i return t assert f(13) == 1
benchmark_functions_edited/f3867.py
def f(minutes: int) -> int: return int(minutes / 60) assert f(0) == 0
benchmark_functions_edited/f13486.py
def f(session_attributes, counter): counter_value = session_attributes.get(counter, '0') if counter_value: count = int(counter_value) + 1 else: count = 1 session_attributes[counter] = count return count assert f({"counter": "0"}, "counter") == 1
benchmark_functions_edited/f12818.py
def f(lane): x_pos_list = [] for pt in lane: x_pos_list.append(pt.x) x_mean = 0 if len(x_pos_list) == 1: x_mean = x_pos_list[0] elif len(x_pos_list) > 1: x_mean = (x_pos_list[0] + x_pos_list[-1]) / 2 return x_mean assert f([]) == 0
benchmark_functions_edited/f14193.py
def f(as_bytes): as_bytes = bytearray(as_bytes) if len(as_bytes) < 4: pad_len = 4 - len(as_bytes) as_bytes = bytearray(pad_len * [0]) + as_bytes as_int = (((as_bytes[-4] & 0x7f) << 3*8) + (as_bytes[-3] << 2*8) + (as_bytes[-2] << 1*8) + (as_bytes[-1] << 0*8)) return as_int assert f(b'\x00\x00') == 0
benchmark_functions_edited/f2960.py
def f(n): return bin(n).count("1") assert f(0b00000001) == 1
benchmark_functions_edited/f6093.py
def f(subject, result_if_one, result_if_zero): # type: (int, int, int) -> int return (~(subject - 1) & result_if_one) | ((subject - 1) & result_if_zero) assert f(1, 1, 0) == 1
benchmark_functions_edited/f12691.py
def f(arr, urls, idx): if idx == -1: return -1 for pron_info in arr: [cur_url, url_text] = urls[idx] if url_text.endswith(pron_info['pronunciation']): pron_info['url'] = cur_url idx += 1 if idx >= len(urls): return -1 return idx assert f( [{'pronunciation': 'abc'}, {'pronunciation': 'def'}], [('a', 'abc'), ('b', 'def'), ('c', 'ghi')], 2, ) == 2
benchmark_functions_edited/f13782.py
def f(bit_list): bit_string = ''.join([('0','1')[b] for b in bit_list]) base_ten_representation = int(bit_string, 2) return base_ten_representation assert f(list([0,0,0,0])) == 0
benchmark_functions_edited/f8779.py
def f(tree, big_tree): if tree is not None: if big_tree is None: return tree else: return big_tree.merge(tree) else: return big_tree assert f(None, 1) == 1
benchmark_functions_edited/f1536.py
def f(bvalue): return int("".join(bvalue), 2) assert f(list("011")) == 3
benchmark_functions_edited/f6233.py
def f(a,b): if len(a)!=len(b): raise RuntimeError('Vector dimensions not equal') sum=0 for i in range(len(a)): sum = sum + (a[i]-b[i])*(a[i]-b[i]) return sum assert f( (-1, -1), (-1, -1) ) == 0
benchmark_functions_edited/f677.py
def f(num: int): return len(str(num)) assert f(99) == 2
benchmark_functions_edited/f11382.py
def f(dx, dy, ddx, ddy): return (dx * ddy - dy * ddx) / (dx ** 2 + dy ** 2) ** (3 / 2) assert f(0, 1, 0, 2) == 0
benchmark_functions_edited/f2611.py
def f(value: float): return 1 if value > 0 else 0 assert f(0.0) == 0
benchmark_functions_edited/f9224.py
def f(rgb): return (rgb[0]*.3 + rgb[1]*.59 + rgb[2]*.11) assert f( (0, 0, 0) ) == 0
benchmark_functions_edited/f7483.py
def f(func, kwargs): return func(**kwargs) assert f(lambda a, b: a + b, {"a": 1, "b": 1}) == 2
benchmark_functions_edited/f4771.py
def f(inp,x_min,x_max,y_min,y_max): return (inp-x_min) / (x_max-x_min) * (y_max-y_min) + y_min assert f(0, 0, 10, 0, 10) == 0
benchmark_functions_edited/f2598.py
def f(line): return (len(line) - len(line.lstrip())) / 4 assert f(' ') == 2
benchmark_functions_edited/f11706.py
def f(value): return (value & 0xffffffffffffffff) assert f(2**64+1) == 1
benchmark_functions_edited/f10884.py
def f(axis, num_dims): axis = int(axis) if axis < 0: axis = axis + num_dims if axis < 0 or axis >= num_dims: raise ValueError( "axis {} is out of bounds for array of dimension {}".format( axis, num_dims)) return axis assert f(-2, 2) == 0
benchmark_functions_edited/f12814.py
def f(word, lyrics): found = 0 for w in lyrics: if word in w: found = found + 1 return found assert f( 'I', ['I', 'I', 'I', 'I', 'I'] ) == 5
benchmark_functions_edited/f7231.py
def f(x, m): return int((x + m + m // 2) % m) - int(m // 2) assert f(0, 10) == 0
benchmark_functions_edited/f335.py
def f(G, Gmax, V, E): return G * Gmax * (V - E) assert f(10, 10, 10, 10) == 0
benchmark_functions_edited/f8673.py
def f(a1, a2, a3): x = 1 if x > 2: return 1 else: return 2 assert f(10, 2, True) == 2
benchmark_functions_edited/f8926.py
def f(list1, list2): set1 = set(list1) set2 = set(list2) # set3 contains all items comon to set1 and set2 set3 = set1.intersection(set2) # return number of matching items return len(set3) assert f( ['a', 'b', 'c', 'd'], ['e', 'f', 'g']) == 0
benchmark_functions_edited/f1069.py
def f(bytes: int) -> float: return bytes * (1 / 1024 ** 2) assert f(1048576) == 1
benchmark_functions_edited/f5698.py
def f(azimuth): if azimuth <= -180: return azimuth + 360 elif azimuth > 180: return azimuth - 360 else: return azimuth assert f(360) == 0
benchmark_functions_edited/f12025.py
def f(list1, list2): for item in list1: for part in list2: if item == part: return item return None assert f( [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ) == 1
benchmark_functions_edited/f11778.py
def f(p, q): pa = p.split(":") qa = q.split(":") if len(pa) != len(qa): if p > q: return 1 else: return -1 for i in range(len(pa)): n = int(pa[i], 0x10) - int(qa[i], 0x10) if n > 0: return 1 elif n < 0: return -1 return 0 assert f( "00:11:22:33:44:55", "00:11:22:33:44:55" ) == 0
benchmark_functions_edited/f7298.py
def f(timespan): if timespan in ('', 'NOT_IMPLEMENTED', None): return None return sum(60 ** x[0] * int(x[1]) for x in enumerate( reversed(timespan.split(':')))) assert f( '0:00:00:00') == 0
benchmark_functions_edited/f313.py
def f(x): return ((4*x+3)*x+2)*x+1 assert f(0) == 1
benchmark_functions_edited/f12805.py
def f(version, index): try: return int(version[index]) except IndexError: return -1 assert f(["1", "0", "0"], 2) == 0
benchmark_functions_edited/f181.py
def f(src_feat, dst_feat, edge_feat): return src_feat["h"] assert f( {"h": 3}, {"h": 4}, "foo", ) == 3
benchmark_functions_edited/f11967.py
def f(cnt=14, msgobj=None): if cnt > 0: remain = f(cnt-1) if msgobj is not None: msgobj("recalled {}".format(cnt)) else: remain = 0 return remain assert f(22) == 0
benchmark_functions_edited/f8300.py
def f(doc): return sum(item[1] for item in doc) assert f([]) == 0
benchmark_functions_edited/f6782.py
def f(name, bases, default=None): for base in bases: if hasattr(base, name): return getattr(base, name) return default assert f( 'attribute_a', [ type('A', (object,), {'attribute_a': 1}), type('B', (object,), {'attribute_a': 2}), type('C', (object,), {'attribute_a': 3}), ], 4 ) == 1
benchmark_functions_edited/f460.py
def f(u, dfs_data): return dfs_data['ordering_lookup'][u] assert f(2, { 'ordering_lookup': {1: 1, 2: 2}, 'parent_lookup': {1: 1, 2: 2}, }) == 2
benchmark_functions_edited/f6466.py
def f(N2, Omega, k, l, m, u, f): # K2 = k**2 + l**2 + m**2 cgx = ((k * m**2 * (N2 - f**2))/((k**2 + l**2 + m**2)**2 * Omega)) + u return cgx assert f(1, 1, 1, 1, 1, 1, 1) == 1
benchmark_functions_edited/f12501.py
def f(fn): if fn.endswith('.h'): return 5 if fn.endswith('.s') or fn.endswith('.S'): return 2 if fn.endswith('.lib') or fn.endswith('.a'): return 4 if fn.endswith('.cpp') or fn.endswith('.cxx'): return 8 if fn.endswith('.c') or fn.endswith('.C'): return 1 return 5 assert f('1234567890') == 5
benchmark_functions_edited/f8571.py
def f(r:int, g:int, b:int) -> float: # Counting the perceptive luminance - human eye favors green color... return (0.299 * r + 0.587 * g + 0.114 * b) / 255 assert f(0, 0, 0) == 0
benchmark_functions_edited/f14375.py
def f(data): expected = {'byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid'} fields, valid = set(), 0 for line in data.splitlines(): if line: # non-empty line fields.update(field[:3] for field in line.split()) else: # blank line: check passport and start new one valid += expected <= fields fields = set() return valid + (expected <= fields) assert f(r) == 2