file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f1154.py
def f(val): if val == -1.0: return '-' return val assert f(1) == 1
benchmark_functions_edited/f5794.py
def f(value, base=2): res = 0 for idx, val in enumerate(value): res += int(val) * base ** idx return res assert f( [False, False, False, True, False, False, False, False] ) == 8
benchmark_functions_edited/f10739.py
def f(active_player_index): if active_player_index: return 0 return 1 assert f(1) == 0
benchmark_functions_edited/f13647.py
def f(expr, chop=False): if isinstance(expr, list): try: return [x.evalf(chop=chop) for x in expr] except Exception: # pylint: disable=broad-except return expr try: return expr.evalf(chop=chop) except Exception: # pylint: disable=broad-except return expr assert f(0) == 0
benchmark_functions_edited/f12355.py
def f(strs, value): if value is None: return None strs = [s.lower() if isinstance(s, str) else s for s in strs] value = value.lower() tmp_dict = dict(zip(strs, list(range(len(strs))))) return tmp_dict[value] assert f(['apple', 'banana', 'cherry'], 'apple') == 0
benchmark_functions_edited/f1810.py
def f(x, y, z): return (x & y) ^ (x & z) ^ (y & z) assert f(1, 1, 0) == 1
benchmark_functions_edited/f13894.py
def f(items, data): if not isinstance(data, dict): raise KeyError item = items.pop(0) data = data[item] return f(items, data) if items else data assert f( ['a', 'b'], {'a': {'b': 2}} ) == 2
benchmark_functions_edited/f5703.py
def f(a, m): s, t, x2, x1, = a, m, 1, 0 while t > 0: q, r = divmod(s, t) x = x2 - q * x1 s, t, x2, x1 = t, r, x1, x return x2 if x2 > 0 else x2 + m assert f(8, 9) == 8
benchmark_functions_edited/f10288.py
def f(num_summarizers): return 2 * (0.5 ** num_summarizers) assert f(1) == 1
benchmark_functions_edited/f2688.py
def f(a : float, b: float=1, c: float=1) -> float: print(a * b * c) return a * b * c assert f(2, 2, 2) == 8
benchmark_functions_edited/f6329.py
def f(variables_d, popset): n_pop = len(popset) return len(variables_d) - (n_pop*(n_pop-1)/2) assert f(dict(), set()) == 0
benchmark_functions_edited/f8628.py
def f(cls): if not hasattr(cls, "_plugin_priority"): return 0 return cls._plugin_priority assert f(object) == 0
benchmark_functions_edited/f9291.py
def f(effect, field_name, fn, default): value = getattr(effect, field_name, None) if value is None: return default else: return fn(value) assert f(None, 'field', lambda x: 2*x, 0) == 0
benchmark_functions_edited/f11297.py
def f(data): valid = 0 for words in data: words = [''.join(sorted(word)) for word in words] unique = set(words) if len(words) == len(unique): valid += 1 return valid assert f([['abcde','xyz','ecdab']]) == 0
benchmark_functions_edited/f13512.py
def f(ff, x): res = 0.0 for i in ff: if not(-12 < (i[0] - x) < 12): continue li = 1.0 for j in ff: if not(-12 < (j[0] - x) < 12): continue if i[0] != j[0]: z = (i[0] - j[0]) li *= ((x - j[0]) / z) res += li * i[1] return res assert f( [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)], 3.0) == 9
benchmark_functions_edited/f7142.py
def f(value): if value >= 0: return value << 1 return (value << 1) ^ (~0) assert f(-1) == 1
benchmark_functions_edited/f6564.py
def f(year): # Return the specific year return int(year % 4) assert f(1994) == 2
benchmark_functions_edited/f11831.py
def f(el_1, el_2, n): a = el_1 d = el_2 - el_1 return (n-1) * d + a assert f(1, 4, 1) == 1
benchmark_functions_edited/f3244.py
def f(value, default): return value if value != None else default assert f(5, 3) == 5
benchmark_functions_edited/f5856.py
def f(array, default): try: return array.pop(0) except IndexError: return default assert f([1, 2, 3, 4, 5, 6, 7, 8], None) == 1
benchmark_functions_edited/f1388.py
def f(b): return 0 if b&1==0 else 1+f(b>>1) assert f(129) == 1
benchmark_functions_edited/f12457.py
def f(square): tot_sum = 0 # Calculate sum of all the pixels in 3 * 3 matrix for i in range(3): for j in range(3): tot_sum += square[i][j] return tot_sum // 9 # return the average of the sum of pixels assert f([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) == 1
benchmark_functions_edited/f10721.py
def f(xs, ys): return float(len(set(xs) & set(ys))) / len(set(xs) | set(ys)) assert f(set(), set(["a", "b", "c"])) == 0
benchmark_functions_edited/f2893.py
def f(s): f = float(s) if int(f) == f: return int(f) return f assert f(" 1 ") == 1
benchmark_functions_edited/f1765.py
def f(q): return (pow(sum(e*e for e in q), 0.5)) assert f( (0, 1, 0, 0) ) == 1
benchmark_functions_edited/f6290.py
def f(n): assert n > 0 a, b = 1, 1 for i in range(n-1): a, b = b, a+b return a assert f(2) == 1
benchmark_functions_edited/f11340.py
def count_failed_students (student_scores): count = 0 for element in student_scores: if element <= 40: count += 1 return count assert f([]) == 0
benchmark_functions_edited/f4994.py
def f(int_type: int, offset: int) -> int: mask = 1 << offset return int_type & mask assert f(5, 31) == 0
benchmark_functions_edited/f9433.py
def f(lines, bit_idx): count_bit = 0 for line in lines: if line[bit_idx] == 1: count_bit += 1 else: count_bit -= 1 most_bit = 1 if count_bit >= 0 else 0 return most_bit assert f( [ [0, 1, 0, 1, 0], [1, 1, 1, 1, 0], [1, 0, 1, 1, 0], [0, 0, 1, 0, 0], [1, 0, 1, 0, 1], ], 1, ) == 0
benchmark_functions_edited/f3941.py
def f(values): return sum(values) / len(values) assert f( [-2, 0, 2] ) == 0
benchmark_functions_edited/f828.py
def f(a, b): if a == 0: return b return f(b % a, a) assert f(10, 5) == 5
benchmark_functions_edited/f12336.py
def f(f,length, srate): # return int( f*(length//srate)+0.5) return int(round(f*length/srate)) assert f(0, 16000, 16000) == 0
benchmark_functions_edited/f12369.py
def f(int_num): return bin(int_num).count('1') assert f(1) == 1
benchmark_functions_edited/f9222.py
def f(timeseries): if not timeseries: return 0 for metric, points in timeseries.items(): return next((p['y'] for p in reversed(points) if p['y'] > 0), 0) assert f({'a': [{'y': 0}, {'y': 0}]}) == 0
benchmark_functions_edited/f8355.py
def f(array, val): for idx in range(len(array)): if val == array[idx]: return idx return None assert f([1, 4, 9, 16, 25], 25) == 4
benchmark_functions_edited/f3629.py
def f(dice): points = 0 if dice.count(dice[0]) == len(dice): points = 50 return points assert f([1, 2, 3, 4, 5]) == 0
benchmark_functions_edited/f3343.py
def f(cluster_spec): return len(cluster_spec.as_dict().get('ps', [])) if cluster_spec else 0 assert f(None) == 0
benchmark_functions_edited/f7068.py
def f(rackId): if rackId >= 0: return rackId else: raise ValueError( '{} is not a valid Rack Id, Rack Id must be >= 0'.format(rackId)) assert f(0) == 0
benchmark_functions_edited/f7663.py
def f(x, A, x0, C): return A*(x - x0)**2 + C assert f(10, -1, 10, 0) == 0
benchmark_functions_edited/f5121.py
def f(Dc: float, redshift: float) -> float: return Dc/(1 + redshift) assert f(0, 0) == 0
benchmark_functions_edited/f12813.py
def f(number): try: if number < 0 : return 'complex numbers not supported' elif number >= 0: return int(number**(1/2)) except: return 'data type not supported' assert f(1) == 1
benchmark_functions_edited/f7045.py
def f(speed): return (10-speed)*400 assert f(10) == 0
benchmark_functions_edited/f13875.py
def f(line_str: str) -> int: space_num: int = 0 for line_char in line_str: if line_char != ' ': break space_num += 1 line_indent_num: int = space_num // 4 return line_indent_num assert f(' '+'yield') == 0
benchmark_functions_edited/f10433.py
def f(n=100): return(n * (n + 1) * (n - 1) * (3 * n + 2) // 12) assert f(0) == 0
benchmark_functions_edited/f3053.py
def f(x): if x == 0 or x == 1: return 1 else: return f(x-1) + f(x-2) assert f(0) == 1
benchmark_functions_edited/f10713.py
def f(checkpoint_dir): checkpoint_name = checkpoint_dir.split('-')[-1] return int(checkpoint_name) assert f( "checkpoint-2") == 2
benchmark_functions_edited/f3803.py
def f(n): if n == 0: return 1 elif n == 1: return 0 else: # NaN case return n assert f(f(f(0))) == 1
benchmark_functions_edited/f2828.py
def f(int_type, offset): mask = 1 << offset return int_type & mask assert f(0, 2) == 0
benchmark_functions_edited/f10085.py
def f(orfSeq): numNs = 0 for i in orfSeq: if i == 'N': numNs+=1 return(numNs) assert f('') == 0
benchmark_functions_edited/f12247.py
def f(s1,s2): if len(s1) == len(s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) if len(s1) > len(s2): s1,s2 = s2,s1 excess = len(s2) - len(s1) return min( sum(c1 != c2 for c1, c2 in zip(s1, s2[start:start+len(s1)])) for start in range(excess+1)) assert f( 'karolin', 'kerstin' ) == 3
benchmark_functions_edited/f976.py
def f(x): #return x * (1 - x) return 1 assert f(0.1) == 1
benchmark_functions_edited/f795.py
def f(int_type, offset): return int_type | (1 << offset) assert f(0, 1) == 2
benchmark_functions_edited/f8380.py
def f(prices): max_so_far = 0 for i in range(0, len(prices) - 1): for j in range(i + 1, len(prices)): max_so_far = max(max_so_far, prices[j] - prices[i]) return max_so_far assert f( [7, 1, 5, 3, 6, 4]) == 5
benchmark_functions_edited/f4566.py
def f(p_str): l_int = 0 try: l_int = int(p_str, 16) except: l_int = 0 return l_int assert f(0x1234567) == 0
benchmark_functions_edited/f11393.py
def f(a, n): b = n if abs(b) == 0: return (1, 0, a) x1, x2, y1, y2 = 0, 1, 1, 0 while abs(b) > 0: q, r = divmod(a, b) x = x2 - q * x1 y = y2 - q * y1 a, b, x2, x1, y2, y1 = b, r, x1, x, y1, y return x2 % n assert f(2, 5) == 3
benchmark_functions_edited/f8223.py
def f(n): s = 0 while n: s += n % 10 n //= 10 return s assert f(100) == 1
benchmark_functions_edited/f9701.py
def f(new,old): return (abs(new-old)/abs(old))*100 assert f(-100, -100) == 0
benchmark_functions_edited/f4239.py
def f(pressure, n_total, k_const): return (n_total * k_const * pressure / (1 + k_const * pressure)) assert f(0, 1000, 50) == 0
benchmark_functions_edited/f8179.py
def f(i): i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 assert f(3) == 2
benchmark_functions_edited/f7074.py
def f(sequence, offset): new_sequence = sequence - offset if new_sequence < 0: new_sequence += 0x100000000 return new_sequence assert f(0x12345678, 0x12345678) == 0
benchmark_functions_edited/f6115.py
def f(alist, elem): try: return alist.index(elem) except ValueError: return len(alist) - 1 assert f(list('ababb'), 'a') == 0
benchmark_functions_edited/f487.py
def f(pack): return (pack) & 0xffff assert f(0x20000) == 0
benchmark_functions_edited/f998.py
def f(pyday): return (pyday + 1) % 7 + 1 assert f(2) == 4
benchmark_functions_edited/f14483.py
def f(table, targets): enemy_army_value = 0 for enemy in targets: table.setdefault(enemy.type_id, 1) enemy_army_value += table[enemy.type_id] return enemy_army_value assert f(dict(), []) == 0
benchmark_functions_edited/f11484.py
def f(val, dic): for d_key, d_val in dic.items(): if d_val == val: return d_key return None assert f(3, {0:3, 1:2, 2:1}) == 0
benchmark_functions_edited/f8738.py
def f(num_list): my_sum = 0 for num in num_list: my_sum += num # Example error in function implementation (using wrong operator) # my_sum *= num return my_sum assert f([1]) == 1
benchmark_functions_edited/f11090.py
def f(s): steps = 0 cursor = 0 maze = s[:] l = len(maze) while True: if cursor < 0 or cursor >= l: break instruction = maze[cursor] maze[cursor] += 1 cursor += instruction steps += 1 return steps assert f( [0, 3, 0, 1, -3]) == 5
benchmark_functions_edited/f12793.py
def f(d): if not isinstance(d, dict): return d keys = list(d.keys()) for k, v in d.items(): assert v._fields == d[keys[0]]._fields fields = d[keys[0]]._fields t = [] for i in range(len(fields)): t.append({key:d[key][i] for key in keys}) return d[keys[0]].__class__(*t) assert f(1) == 1
benchmark_functions_edited/f13386.py
def f(stack1, stack2): d = 0 for i in stack1.keys(): # check base pairs in stack 1 if i < stack1[i] and stack1[i] != stack2[i]: d += 1 # check base pairs in stack 2 for i in stack2.keys(): if i < stack2[i] and stack1[i] != stack2[i]: d += 1 return d assert f( {1: 2, 2: 1, 3: 4, 4: 5, 5: 6, 6: 7}, {1: 2, 2: 1, 3: 4, 4: 5, 5: 6, 6: 7}, ) == 0
benchmark_functions_edited/f10862.py
def f(string): try: return int(string) except ValueError: try: return float(string) except ValueError: return string assert f("3") == 3
benchmark_functions_edited/f6492.py
def f( vector, value ): inds = [i for i in range(len(vector)) if vector[i] > value] return inds[0] assert f( [1,2,3,4,5], 0 ) == 0
benchmark_functions_edited/f12297.py
def f(data, format): dec = 0 if format == 'RDEF': for power in range(len(data)-1, -1, -1): dec = dec + data[power]*(2**(8*power)) elif format == 'VDR' or format == 'SFDU': for power in range(0, len(data)): dec = dec + data[power]*2**(8*(len(data)-power-1.0)) dec = int(dec) return dec assert f(b'\x01', 'VDR') == 1
benchmark_functions_edited/f11885.py
def f(nrows: str): try: return int(nrows) except ValueError: return None assert f("3") == 3
benchmark_functions_edited/f3440.py
def f(Kp: int, C: int, num_params: int) -> int: return Kp // (num_params * C) assert f(12, 4, 2) == 1
benchmark_functions_edited/f1943.py
def f(num): result = 1 for i in range(2, num + 1): result *= i return result assert f(2) == 2
benchmark_functions_edited/f206.py
def f(a, b, x): return a + x * (b - a) assert f(0, 100, 0) == 0
benchmark_functions_edited/f7183.py
def f(n, machines): return sum([n//machine for machine in machines]) assert f(1, [1, 2]) == 1
benchmark_functions_edited/f2529.py
def f(second, func, *args, **kw): return func(*args, **kw) assert f(0.001, lambda: 0) == 0
benchmark_functions_edited/f11522.py
def f(_bytes): if (_bytes[0] & 0x0F) == 0x0E: # read subsequent byte(s) as the "length" field for i in range(1, len(_bytes)): if (_bytes[i] & 0x80) != 0: return i raise Exception("Problem while reading VarUInt!") return 0 assert f(b"\x20") == 0
benchmark_functions_edited/f2891.py
def f(taps): grp_delay = (len(taps)-1)//2 return grp_delay assert f(list(range(1, 14))) == 6
benchmark_functions_edited/f345.py
def f(tweet): return(len(tweet["text"])) assert f({"a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "text": ""}) == 0
benchmark_functions_edited/f11338.py
def f(new_value, old_value, time): time_1plus = time + 1 return (1. / time_1plus) * new_value + (time_1plus - 1.) / time_1plus * old_value assert f(1, 1, 0) == 1
benchmark_functions_edited/f4567.py
def f( redchan, nirchan ): redchan = 1.0*redchan nirchan = 1.0*nirchan result = ( nirchan - redchan ) return result assert f(4, 4) == 0
benchmark_functions_edited/f8317.py
def f(agent_num, self_id): agent_num = int(agent_num) if agent_num > self_id: return agent_num - 1 else: return agent_num assert f(2, 0) == 1
benchmark_functions_edited/f6288.py
def f(state): if len(state) == 0: return 0 else: return len(state[0]) assert f( (('A', 'B', 'C'), ('D', 'E', 'F'), ('G', 'H', 'I'), ('J', 'K', 'L'), ('M', 'N', 'O'), ('P', 'Q', 'R')) ) == 3
benchmark_functions_edited/f10305.py
def f(a, b, operator): if operator == "+": return int(b) + int(a) elif operator == "-": return int(b) - int(a) elif operator == "*": return int(b) * int(a) elif operator == "/": return int(b) // int(a) assert f(1, 3, "*") == 3
benchmark_functions_edited/f256.py
def f(k, n): return (((1 << k) - 1) & n) assert f(1, 0) == 0
benchmark_functions_edited/f1794.py
def f(x, y, z): return (int(x) << 3 | int(y)) << 3 | int(z) assert f(0, 0, 7) == 7
benchmark_functions_edited/f3432.py
def f(first_term,term_number,common_difference): return first_term+(common_difference*(term_number-1)) assert f(1,7,1) == 7
benchmark_functions_edited/f11233.py
def f(src, lineno): assert lineno >= 1 pos = -1 for _ in range(lineno): pos = src.find('\n', pos + 1) if pos == -1: return len(src) return pos assert f(*['aaa\nbb\ncc', 2]) == 6
benchmark_functions_edited/f8979.py
def f(x, y, n): if len(x) != len(y): raise ValueError("x and y must be the same length!") if not isinstance(n, int): raise ValueError("n must be an integer!") return sum([(x_i * y[i]) % n for i, x_i in enumerate(x)]) assert f([], [], 25) == 0
benchmark_functions_edited/f11643.py
def f(gold, pred): fps = 0 for p in pred: fp = True for word in p: for span in gold: if word in span: fp = False if fp is True: fps += 1 return fps assert f( [], [['a', 'b']]) == 1
benchmark_functions_edited/f9463.py
def f(value, _set): a = 0 element = _set[0] while(a<len(_set)): if((_set[a]-value)*(_set[a]-value)<(element-value)*(element-value)): element=_set[a] a = a + 1 return element assert f(0, [1, 3, 5, 8]) == 1
benchmark_functions_edited/f6562.py
def f(a, b): distance = 0 for char_a, char_b in zip(a, b): if char_a != char_b: distance += 1 return distance assert f('AA','BB') == 2
benchmark_functions_edited/f13359.py
def f(current_price, call_chain, put_chain): if len(call_chain) > len(put_chain): if abs(float(call_chain[0][0]) - current_price) > abs(float(put_chain[0][0]) - current_price): # if spread is greater for call -> watch for covered calls return 0 else: return 1 else: return 0 assert f(2, [(1, 0)], [(2, 0)]) == 0
benchmark_functions_edited/f3969.py
def f(block_hash: str) -> int: return int(str(block_hash)[:8], base=16) assert f(0x01) == 1
benchmark_functions_edited/f10961.py
def f(str_one, str_two): left, right = '', '' swap_count = 0 # iterate strings and find differences. store non-matching characters in left and right # evaluate, and count matching pairs that can be swapped return swap_count assert f( "abdc", "abcd" ) == 0
benchmark_functions_edited/f1647.py
def f(x1, x2, y1, y2): return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 assert f(3, 0, 4, 0) == 5
benchmark_functions_edited/f7648.py
def f(v): if v < 0 or v >= (1 << 32): return 1 else: return 0 assert f(1 << 32 - 12) == 0
benchmark_functions_edited/f10563.py
def f(data) -> int: if isinstance(data, (tuple, list)): item = data[0] if not isinstance(item, (float, int, str)): return len(item) return len(data) assert f((0, 0.0, 0.0)) == 3