file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f6397.py
def f(n, func, args=None): m = 0 for i in range(n): v = func(*args) if args else func() if v > m: m = v return m assert f(10, min, [1, 2, 3]) == 1
benchmark_functions_edited/f12683.py
def f(frm, to, value): if frm > to: raise ValueError("frm cannot be bigger than to in clamp") if value > to: return to if value < frm: return frm return value assert f(-1, 0, 0) == 0
benchmark_functions_edited/f191.py
def f(A, B): return abs(A - B) assert f(-1, 1) == 2
benchmark_functions_edited/f12146.py
def f(annotations): tids = set(a['track_id'] for a in annotations) tid2nat = {tid: i for i, tid in enumerate(sorted(tids))} for a in annotations: a['track_id'] = tid2nat[a['track_id']] return max(tid2nat.values()) assert f( [{'track_id': 0}, {'track_id': 0}, {'track_id': 1}, {'track_id': 1}, {'track_id': 1}, {'track_id': 1}, {'track_id': 1}] ) == 1
benchmark_functions_edited/f6964.py
def f(p1, p2): return abs( p1[0] - p2[0]) + abs(p1[1] - p2[1] ) assert f( (2,2), (0,0) ) == 4
benchmark_functions_edited/f11639.py
def f(s_list, step): if isinstance(s_list, list): period = len(s_list) index = abs(- period + 1 + step % period) return s_list[index] else: return 0 assert f(None, None) == 0
benchmark_functions_edited/f4681.py
def f(source, start, charset): while start<len(source) and source[start] in charset: start+=1 return start assert f(b"3 + 2", 5, b"+-0123456789") == 5
benchmark_functions_edited/f7621.py
def f(new_value, list_len, old_cma): return (new_value + list_len * old_cma) / (list_len + 1) assert f(2, 1, 0) == 1
benchmark_functions_edited/f3765.py
def f(x, alpha=1, c=0): return alpha*x + c assert f(5, 1) == 5
benchmark_functions_edited/f4418.py
def f(count): return (1, 2, 5)[count] if count < 3 else 5 * count - 5 assert f(2) == 5
benchmark_functions_edited/f4640.py
def f(value): return value[0] if isinstance(value, list) else value assert f([1]) == 1
benchmark_functions_edited/f2738.py
def f(a: bytes, b: bytes) -> int: return int.from_bytes(a, 'big') ^ int.from_bytes(b, 'big') assert f(bytes.fromhex('000000'), bytes.fromhex('000001')) == 1
benchmark_functions_edited/f10251.py
def f(p, L, pc, nu): return (p - pc) * L**(1 / nu) assert f(0.01, 100, 0, 1) == 1
benchmark_functions_edited/f10426.py
def f(leaf_to_root): num_roots = 0 for l, r in leaf_to_root.items(): if r is None: num_roots += 1 return num_roots assert f({"a": None, "b": None}) == 2
benchmark_functions_edited/f3566.py
def f(a, b): if b == 0: return a return f(b, a % b) assert f(12, 2) == 2
benchmark_functions_edited/f9504.py
def f(length, height, width): return length * height * width assert f(1, 1, 1) == 1
benchmark_functions_edited/f11027.py
def square (intValue): squaredInt = intValue ** 2 return squaredInt assert f(0) == 0
benchmark_functions_edited/f3562.py
def f(x): m = max(x) return x.index(m) assert f([10, 11, 12]) == 2
benchmark_functions_edited/f267.py
def f(a,b): return abs(a[0]+b[0]) + abs(a[1]+b[1]) assert f( (3,4), (0,0) ) == 7
benchmark_functions_edited/f8591.py
def f(*it): return sum([i is not None for i in it]) assert f(1, 1, 1, 1) == 4
benchmark_functions_edited/f9082.py
def f(nums): max_num = nums[0] for x in nums: if x > max_num: max_num = x return max_num assert f([1, 2, 3]) == 3
benchmark_functions_edited/f13777.py
def f(rating1, rating2, r): distance = 0 commonRatings = False for key in rating1: if key in rating2: distance += pow(abs(rating1[key] - rating2[key]), r) commonRatings = True if commonRatings: return pow(distance, 1/r) else: return 0 assert f( {'The Strokes': 3.0, 'Slightly Stoopid': 2.5}, {'The Strokes': 3.0, 'Slightly Stoopid': 2.5}, 1) == 0
benchmark_functions_edited/f11566.py
def f(lis, elem_set) -> int: count = 0 for idx, elem2 in reversed(list(enumerate(lis))): if elem2 in elem_set: count += 1 if count == 2: return idx return 0 assert f( [1, 2, 1, 2, 2, 2], set([])) == 0
benchmark_functions_edited/f964.py
def f( data=[]): i = 0 for d in data: i += 1 return i assert f( ['a', 'b', 'c'] ) == 3
benchmark_functions_edited/f9713.py
def f(a, b): # pylint: disable=invalid-name if a == b: return 0 if (a < b and (b - a) < (2**31 - 1)) or (a > b and (a - b) > (2**31 - 1)): return -1 return 1 assert f(0x20000001, 0x20000000) == 1
benchmark_functions_edited/f9141.py
def f(state): differences = 0 for i in range(0, len(state) - 1): if state[i] != state[i+1]: differences += 1 return differences assert f("") == 0
benchmark_functions_edited/f12506.py
def f(value, default): if value: return value return default assert f(None, 1) == 1
benchmark_functions_edited/f870.py
def f(x,a,b,c): return a*(x-b)**2 + c assert f(3,0,0,0) == 0
benchmark_functions_edited/f8474.py
def f(n, k): "*** YOUR CODE HERE ***" prod = 1 while k > 0: prod *= n k -= 1 n -= 1 return prod assert f(6, 0) == 1
benchmark_functions_edited/f3852.py
def f(p, t): return (1-t)**3*p[0] + 3*(1-t)**2*t*p[1] + 3*(1-t)*t**2*p[2] + t**3*p[3] assert f( [0, 0, 0, 0], 1) == 0
benchmark_functions_edited/f11449.py
def f(up, left, right): return 0 if up and left and not right else \ 1 if up and not left and right else \ 2 if up and not left and not right else \ 3 if not up and left and not right else \ 4 if not up and not left and right else 5 assert f(True, True, False) == 0
benchmark_functions_edited/f4704.py
def f(value): if value is None or value == '': return '-' else: return value assert f(3) == 3
benchmark_functions_edited/f2032.py
def f(number,start,end): return max(start, min(number, end)) assert f(2.5, 0, 1) == 1
benchmark_functions_edited/f9089.py
def f(tn: int, fp: int) -> float: try: return tn / (tn + fp) except ZeroDivisionError: return 0.0 assert f(3, 0) == 1
benchmark_functions_edited/f9155.py
def f(f, xs): return min(xs, key=f) assert f(lambda x: x, set([1, 2, 3])) == 1
benchmark_functions_edited/f7033.py
def f(range_index, range_len, angle_increment): lidar_angle = (range_index - (range_len / 2)) * angle_increment steering_angle = lidar_angle / 2 return steering_angle assert f(1, 2, 3) == 0
benchmark_functions_edited/f8544.py
def f(array): if len(array) > 0: # map runs len() against each member of the array return max(map(len, array)) else: return 0 assert f( [[], []] ) == 0
benchmark_functions_edited/f9521.py
def f(power_tuple, index): if index >= len(power_tuple): return 0 else: return power_tuple[index] assert f((0, 1), 0) == 0
benchmark_functions_edited/f10096.py
def f(array, val): sorted_array = sorted(array) i = 0 j = len(array) - 1 while i <= j: mid = (i + j) // 2 if sorted_array[mid] == val: return mid if sorted_array[mid] < val: i = mid + 1 else: j = mid - 1 assert f( [0, 2, 3, 4, 7, 8, 9], 3 ) == 2
benchmark_functions_edited/f14435.py
def f(frame_grouping, kernel): if len(frame_grouping) != 5: raise Exception("Unexpected number of frames in frame grouping") for i in range(5): # 1-5 kernel_value = kernel[i] frame_grouping[i] = frame_grouping[i] * kernel_value return sum(frame_grouping) assert f( [0, 1, 0, 0, 0], [1, 1, 1, 1, 1]) == 1
benchmark_functions_edited/f8637.py
def f(window_length, overlap_ratio): return round(window_length * (1 - overlap_ratio)) assert f(3, 0.5) == 2
benchmark_functions_edited/f5280.py
def f(value, mag: float) ->float: norm = 0 if mag > 0: avalue = abs(value) rnorm = avalue * avalue / mag norm = rnorm return norm assert f(1, -1) == 0
benchmark_functions_edited/f12234.py
def f(length): if length < 0: raise ValueError("The length of side must be >= 0.") area_output = length**2 return area_output assert f(0) == 0
benchmark_functions_edited/f9119.py
def f(obj, *fields): try: for f in fields: obj = obj[f] return obj except: return None assert f([1, 2, 3], 0) == 1
benchmark_functions_edited/f12482.py
def f(a, b): if b >= a or b == 0: return a # b=0 is special case. for test in range(b, 0, -1): if a % test == 0: return test assert(False), "Should never get here - a %% 1 == 0 always! (a=%s, b=%s)" % (str(a), str(b)) assert f(5, 4) == 1
benchmark_functions_edited/f1854.py
def f(h1,h2,joint_h): return h1 + h2 - joint_h assert f(1,0,0) == 1
benchmark_functions_edited/f11101.py
def f(tword,codetree): pos = 0 while True: s = tword[pos] if s not in codetree: return 0 elif pos==len(tword)-1: return codetree[s][0] else: pos += 1 codetree = codetree[s][1] assert f( "z", {'a': [1,{}], 'b': [2,{}], 'c': [3,{}]} ) == 0
benchmark_functions_edited/f1361.py
def f(f): return f.__code__.co_argcount assert f(lambda x, y, z: x) == 3
benchmark_functions_edited/f7907.py
def f(i:int): return int(i / 1) assert f(0) == 0
benchmark_functions_edited/f5275.py
def area (length , width): results = length * width return results assert f(3, 2) == 6
benchmark_functions_edited/f4595.py
def f(x, y): def bit_parity(i): n = bin(i).count("1") return int(n % 2) return bit_parity(x & y) assert f(0, 1) == 0
benchmark_functions_edited/f1593.py
def f(l): t = 1 for i in l: t *= int(i) return t assert f(['1', '2']) == 2
benchmark_functions_edited/f2383.py
def f(x, error=0): try: return int(x) except (ValueError, TypeError): return error assert f(1.0) == 1
benchmark_functions_edited/f3965.py
def f(listy): if listy != []: return (min(listy)) assert f(list(range(1, 10))) == 1
benchmark_functions_edited/f9179.py
def f(x, i): a = x[i] return sum(int(b < a or (b == a and j < i)) for j, b in enumerate(x)) assert f(range(3), 0) == 0
benchmark_functions_edited/f11048.py
def f(source, *keys): d = source for k in keys: if type(d) is list: d = d[int(k)] elif k not in d: d[k] = {} else: d = d[k] return d assert f([0, 1], "1") == 1
benchmark_functions_edited/f7048.py
def f(dx: int, dy: int) -> int: if dx > 0: if dy > 0: return 1 return 4 elif dy > 0: return 2 return 3 assert f(1, 1) == 1
benchmark_functions_edited/f10080.py
def f(element, value, score): if element < value: return score assert f(1.0, 1.2, 0) == 0
benchmark_functions_edited/f12926.py
def f(a, b): diff = 0 if a>b: diff = a-b elif b>a: diff = b-a else: diff = 0 return diff assert f(-5, -5) == 0
benchmark_functions_edited/f5482.py
def f(x, indifference): if x <= indifference: return 1 return 0 assert f(1, 0.244) == 0
benchmark_functions_edited/f11467.py
def f(bytes, to, bsize=1024): a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 } r = float(bytes) for i in range(a[to]): r = r / bsize return(r) assert f(1024**2, "m") == 1
benchmark_functions_edited/f167.py
def f(x): return x**2 + x + 3 assert f(2) == 9
benchmark_functions_edited/f4484.py
def f(a1, a2): if(a2 == 0): raise Exception("Cannot divide by 0! (duh)") return float(a1) / float(a2) assert f(0, 6) == 0
benchmark_functions_edited/f10200.py
def f(n, k): total, stop = 1, n - k while n > stop: total, n = total * n, n - 1 return total assert f(4, 1) == 4
benchmark_functions_edited/f1644.py
def f(v1, v2): return v1[0]*v2[1] - v1[1]*v2[0] assert f( (0,0), (1,1) ) == 0
benchmark_functions_edited/f10419.py
def f(guess, answer, turns): if guess > answer: print("Too high.") return turns - 1 elif guess < answer: print("Too low.") return turns - 1 else: print(f"You got it! The answer was {answer}.") assert f(3, 2, 3) == 2
benchmark_functions_edited/f8511.py
def f(a, b): # GCD(a, b) = GCD(b, a mod b). while (b != 0): # Calculate the remainder. remainder = a % b # Calculate GCD(b, remainder). a = b b = remainder # GCD(a, 0) is a. return a assert f(4, 3) == 1
benchmark_functions_edited/f11280.py
def f(x, y): return (x / y) assert f(8, 4) == 2
benchmark_functions_edited/f1385.py
def f(k, l): assert 0 < k and 0 <= l <= k return pow(2, k-l) - 1*(l<k) assert f(5, 5) == 1
benchmark_functions_edited/f13145.py
def f(x: int, width: int = 0) -> int: if not width: width = x.bit_length() rev = 0 for i in range(width): bit = x & (1 << i) if bit: rev |= (1 << (width - i - 1)) return rev assert f(0, 0) == 0
benchmark_functions_edited/f12648.py
def f(action): return int(action - 1) assert f(2) == 1
benchmark_functions_edited/f9532.py
def f(o, b, a, T, O): prob = 0.0 for s in b: for sp in b: trans_prob = T.probability(sp, s, a) obsrv_prob = O.probability(o, sp, a) prob += obsrv_prob * trans_prob * b[s] return prob assert f(None, {}, None, None, None) == 0
benchmark_functions_edited/f4439.py
def f(nodes): if len(nodes) >= 1: return nodes[0] else: return None assert f([1, 2, 3]) == 1
benchmark_functions_edited/f13329.py
def f(total, sizeperc): if sizeperc > 1: raise ValueError('sizeperc must be between 0 and 1') if sizeperc < 0: raise ValueError('sizeperc must be between 0 and 1') b_size = max(int(total * sizeperc), 1) return max(int(total/b_size), 1) assert f(10, 1) == 1
benchmark_functions_edited/f6646.py
def f(n): i = 0 # Define i j = 1 # Define j n = n - 1 # Define n while n >= 0: # while n is greater than or equal to 0 i, j = j, i + j n = n - 1 return i assert f(0) == 0
benchmark_functions_edited/f264.py
def f(x, a, b): return max(a, min(b, x)) assert f(2, 0, 3) == 2
benchmark_functions_edited/f8819.py
def f(word): for i in range(len(word)): if word[len(word)-1-i].isalpha() or word[len(word)-1-i].isdigit(): return len(word) - 1 - i return -1 assert f('a1-') == 1
benchmark_functions_edited/f14042.py
def f(tensor): if hasattr(tensor, "detach"): # pytorch tensor with attached gradient tensor = tensor.detach() if hasattr(tensor, "numpy"): # pytorch tensor tensor = tensor.numpy() return tensor assert f(1) == 1
benchmark_functions_edited/f1795.py
def f(pos, scale=100): return pos * 40.85 * 100 / 2048 / scale + 1 assert f(0) == 1
benchmark_functions_edited/f13341.py
def f(seq: str, char: str) -> int: assert len(char) == 1 longest = 0 current_streak = 0 for c in seq: if c == char: current_streak += 1 else: current_streak = 0 if current_streak > longest: longest = current_streak return longest assert f( 'aaabb', 'a' ) == 3
benchmark_functions_edited/f11904.py
def f(val, num_list): return min(num_list, key=lambda x: abs(x-val)) assert f(1, [3, 5, 8, 7, 10, 11]) == 3
benchmark_functions_edited/f3425.py
def f(file, lines): with open(file, 'w') as f: bytes_ = f.f('\n'.join(lines[0:]) + '\n') return bytes_ assert f('test.txt', ['']) == 1
benchmark_functions_edited/f11081.py
def f(value): q, rem = divmod(value.bit_length(), 7) if rem or not q: # (the not q is in case value is 0, we can't have 0 bytes) q += 1 return q assert f(140737488355329) == 7
benchmark_functions_edited/f158.py
def f(x, a, b): return max(a, min(x, b)) assert f(1, 2, 4) == 2
benchmark_functions_edited/f1723.py
def f(a, b): return len(a & b) assert f(set(), set([1, 2, 3, 4])) == 0
benchmark_functions_edited/f195.py
def f(num): return int(num/2**20) assert f(2**20 * 3) == 3
benchmark_functions_edited/f4274.py
def f(float): integer = int(float) if int(float) != float: integer = int(float + 1) return integer assert f(3.5) == 4
benchmark_functions_edited/f2776.py
def f(x, p0, p1, p2, p3, p4): return p0 * x + p1 * x ** 2 + p2 * x ** 3 + p3 * x ** 4 + p4 * x ** 5 assert f(2, 2, 0, 0, 0, 0) == 4
benchmark_functions_edited/f14432.py
def f(psi, v): vpsi = v * psi return vpsi assert f(1, 2) == 2
benchmark_functions_edited/f4205.py
def f(lst): n=0 c=lst while c is not None : n=n+1 c=c.suivante return n assert f(None) == 0
benchmark_functions_edited/f5960.py
def f(c): if c in [".", "-", "_", " "]: return 0 if c.isdigit(): return 1 else: return 2 assert f( ".") == 0
benchmark_functions_edited/f4870.py
def f(x): # global numFibCalls # numFibCalls += 1 if x == 0 or x == 1: # NB: we need to base cases return 1 else: return f(x-1) + f(x-2) assert f(4) == 5
benchmark_functions_edited/f6295.py
def f(size): return size * 1024 * 1024 assert f(0) == 0
benchmark_functions_edited/f1883.py
def f(square: str) -> int: return int(square[1]) - 1 assert f('a8') == 7
benchmark_functions_edited/f5626.py
def f(seqs): seq = seqs[0] n = len(seq) assert all(len(s) == n for s in seqs) return n assert f(list("ABC")) == 1
benchmark_functions_edited/f13733.py
def f(color_component: float, minimum: float=0, maximum: float=255) -> float: color_component_out = max(color_component, minimum) return min(color_component_out, maximum) assert f(-1.1) == 0
benchmark_functions_edited/f7850.py
def f(value): # An exception will be raised if value is not an int number = int(value) if number < 0: raise ValueError(f"invalid value: '{value}'") return number assert f(1) == 1
benchmark_functions_edited/f10972.py
def f(module_weights, name): for w, w_name in module_weights: if name == w_name: return w return None assert f([(1, 'a'), (2, 'b'), (3, 'a')], 'a') == 1
benchmark_functions_edited/f11127.py
def f(seq, pred=lambda x: x): ret = 0 for x in seq: if pred(x): ret += 1 return ret assert f(range(0, 10), lambda x: x < 0) == 0
benchmark_functions_edited/f4752.py
def f(n): if n == 0: return 0 elif n == 1: return 1 else: return f(n-2) + f(n-1) assert f(0) == 0