file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f9196.py
def f(data: list, prec=3): return round(sum(data) / len(data), prec) assert f( [0, 0, 0, 0] ) == 0
benchmark_functions_edited/f3164.py
def f(x, x0, x1, y0, y1): return y0 + (y1 - y0) * (x - x0) / (x1 - x0) assert f(2, 1, 2, 1, 2) == 2
benchmark_functions_edited/f479.py
def f(a,b): if(b==0): return a else: return f(b,a%b) assert f(13,35) == 1
benchmark_functions_edited/f9590.py
def f(vertex1, vertex2, edges): if vertex1 == vertex2: return None for _tuple in edges: if vertex1 in _tuple and vertex2 in _tuple: return _tuple[2] return None assert f(0, 1, [(0, 1, 7), (1, 2, 8), (2, 4, 11), (3, 0, 2), (3, 5, 9), (4, 5, 4)]) == 7
benchmark_functions_edited/f5089.py
def f(t0, v0, t1, v1, tt): return v0 + (tt - t0) * (t1 - t0) / (v1 - v0) assert f(0, 1, 1, 2, 1) == 2
benchmark_functions_edited/f709.py
def f(i, j): return 1 if i == j else 0 assert f(2, 1) == 0
benchmark_functions_edited/f8528.py
def f(prior_number): number = -1 n = 1 while number < prior_number: number = n * (n + 1) /2 n += 1 return int(number) assert f(4) == 6
benchmark_functions_edited/f6047.py
def f(some_list): product = 1 for element in some_list: product *= element return product assert f( [1, 2, 3]) == 6
benchmark_functions_edited/f959.py
def f(obj): return obj.isoformat() if hasattr(obj, 'isoformat') else obj assert f(0) == 0
benchmark_functions_edited/f272.py
def f(responses): return responses[-1] assert f(range(5)) == 4
benchmark_functions_edited/f7774.py
def f(a, b, c): s = a + b return s % c assert f(1, 2, 3) == 0
benchmark_functions_edited/f11094.py
def f(ngrams1, ngrams2): return len(ngrams1 & ngrams2) assert f({1, 2, 3, 4}, {1, 2, 3, 4}) == 4
benchmark_functions_edited/f3964.py
def f(list_, func): matching = [i for i in list_ if func(i)] if len(matching) > 0: return matching[-1] return None assert f(range(10), lambda x: x%2 == 0) == 8
benchmark_functions_edited/f5053.py
def f(num1: int, num2: int) -> int: if all((num1 > 0, num2 >= 1,)): return num1 % num2 raise ValueError("Check number inputs. ") assert f(13, 6) == 1
benchmark_functions_edited/f6179.py
def f(raw): if raw == 0: return 0 elif not raw: return None else: return int(raw) assert f('1') == 1
benchmark_functions_edited/f8209.py
def f(x): return isinstance(x, (tuple, list)) assert f((1, 2, 3, 4)) == 1
benchmark_functions_edited/f8598.py
def f(func, x, none_safe): if func is not None: if not none_safe: x = func(x) else: if x is not None: x = func(x) return x assert f(None, 1, True) == 1
benchmark_functions_edited/f10580.py
def f(d, keys, default=None): key = keys.pop(0) item = d.get(key, default) if len(keys) == 0: return item if not item: return default return f(item, keys, default) assert f( {'a': 1, 'b': {'c': {'d': 2}}}, ['a'] ) == 1
benchmark_functions_edited/f8773.py
def f(iterable, function): for item in iterable: if function(item): return item return None assert f(range(10), lambda x: x > 5 and x < 8) == 6
benchmark_functions_edited/f7365.py
def f(num, denom): return 0.0 if denom == 0 else float(num) / denom assert f(5, 0) == 0
benchmark_functions_edited/f13261.py
def f(req, courses): by_semester = req["completed_by_semester"] num_courses = 0 if by_semester == None or by_semester > len(courses): by_semester = len(courses) for i in range(by_semester): num_courses += len(courses[i]) return num_courses assert f( { "completed_by_semester": 1 }, [ ["Course A"], ["Course B"], ["Course C"], ["Course D"], ["Course E"], ["Course F"], ["Course G"], ["Course H"], ] ) == 1
benchmark_functions_edited/f14181.py
def f(nums): nums = map(lambda x: bin(x)[2:].zfill(32), nums) to_return = 0 for i in range(32): zero_count, one_count = 0, 0 for num in nums: if num[i] == '0': zero_count += 1 else: one_count += 1 to_return += zero_count*one_count return to_return assert f( [1, 1] ) == 0
benchmark_functions_edited/f14333.py
def f(img, float_range=(0, 1), orig_range=(0, 255)): f_r = float_range[1] - float_range[0] o_r = orig_range[1] - orig_range[0] return (o_r * (img - float_range[0]) / f_r) + orig_range[0] assert f(0, (0, 1), (0, 255)) == 0
benchmark_functions_edited/f12468.py
def f(device_name, event_code): return { 'a403': [28, 2, 106, 57, 103, 3, 108, 17, 105, 30, 31, 32], 'a496': [108, 17, 103, 57, 105, 28, 106, 32, 2, 31, 3, 30], }[device_name].index(event_code) assert f( 'a403', 57 ) == 3
benchmark_functions_edited/f812.py
def f(ntp: int) -> int: return ((ntp >> 10) * 1000) >> 22 assert f(0x0000000000000000) == 0
benchmark_functions_edited/f3311.py
def f(b) -> int: return int.from_bytes(b, 'little') assert f(b"\x01") == 1
benchmark_functions_edited/f9828.py
def f(base: int, exponent: int) -> float: return base * f(base, (exponent - 1)) if exponent else 1 assert f(7, 0) == 1
benchmark_functions_edited/f10347.py
def f(n, k): if k < 0 or k > n: return 0 if k == 0 or k == n: return 1 total_ways = 1 for i in range(min(k, n - k)): total_ways = total_ways * (n - i) // (i + 1) return total_ways assert f(3, 3) == 1
benchmark_functions_edited/f4930.py
def f(i1, i2, T, t0): if abs(T[i1]-t0) <= abs(T[i2]-t0): return i1 else: return i2 assert f(1, 2, [0,1,2], 0.4) == 1
benchmark_functions_edited/f14451.py
def f(fd, inheritable): from fcntl import ioctl if inheritable: from termios import FIONCLEX return ioctl(fd, FIONCLEX) else: from termios import FIOCLEX return ioctl(fd, FIOCLEX) assert f(2, False) == 0
benchmark_functions_edited/f5452.py
def f(grid, blank): for i, row in enumerate(grid[::-1]): if blank in row: return i + 1 assert f( [['o','','',''], [' ','', 'o',''], ['o','', 'o',''], [' ','','','']], 'o' ) == 2
benchmark_functions_edited/f3819.py
def f(seq): return min(enumerate(seq), key=lambda s: s[1])[0] assert f(range(100)) == 0
benchmark_functions_edited/f7018.py
def f(index: int) -> int: return index if index <= 1 else f(index - 1) + f(index - 2) assert f(0) == 0
benchmark_functions_edited/f1333.py
def f(class_label_colormap,c): return class_label_colormap.index(c) assert f( ['a','b','c'], 'b' ) == 1
benchmark_functions_edited/f5902.py
def f(x): return 1 - (x % 2 == 0) * 2 assert f(1) == 1
benchmark_functions_edited/f1553.py
def f(col): answer = col / 100 return(answer) assert f(0) == 0
benchmark_functions_edited/f9333.py
def f(inputArray): minValueReturn = min(inputArray) return minValueReturn assert f(range(5)) == 0
benchmark_functions_edited/f1032.py
def f(u): return (u[0]**2 + u[1]**2 + u[2]**2)**0.5 assert f( [0,0,1] ) == 1
benchmark_functions_edited/f4060.py
def f(env_var): try: return int(env_var) except (ValueError, TypeError): return False assert f(0) == 0
benchmark_functions_edited/f8229.py
def f(returns, durations, one_year=365.): return (1. + returns) ** (1. / (durations / one_year)) - 1. assert f(0, 10) == 0
benchmark_functions_edited/f8186.py
def f( pitch1: int, pitch2: int, ) -> int: diff_mod_12 = abs(pitch1 - pitch2) % 12 if diff_mod_12 > 6: diff_mod_12 = 12 - diff_mod_12 return diff_mod_12 assert f(4, 6) == 2
benchmark_functions_edited/f13568.py
def f(test): for i in range(1000): if test(i): return i for i in range(1000, -1000, -1): if test(i): return i assert f(lambda x: x % 17 == 0 and x % 19 == 0 and x % 23 == 0 and x % 29 == 0) == 0
benchmark_functions_edited/f6855.py
def f(string, sub_string): return string.count(sub_string) assert f( "ABAB", "AB", ) == 2
benchmark_functions_edited/f5645.py
def f(_dict): if isinstance(_dict, dict): return 1 + (min(map(get_dict_depth, _dict.values())) if _dict else 0) return 0 assert f(dict()) == 1
benchmark_functions_edited/f5869.py
def f(m: list) -> int: count = 0 for r in m: for c in r: if c == '#': count += 1 return count assert f( [ ['L', 'L', 'L', 'L', 'L'], ['L', 'L', 'L', 'L', 'L'], ['L', 'L', 'L', 'L', 'L'], ['L', 'L', 'L', 'L', 'L'], ['L', 'L', 'L', 'L', 'L'], ] ) == 0
benchmark_functions_edited/f2351.py
def f(d, key, default=None): if key in d: return d[key] return default assert f( {'a': 1}, 'b', 0) == 0
benchmark_functions_edited/f12664.py
def f(lst, predicate): for v in lst: if predicate(v): return v return None assert f( [1, 2, 3], lambda v: v % 2 == 0 ) == 2
benchmark_functions_edited/f6427.py
def f(a1: float, a2: float) -> float: phi = abs(a2 - a1) % 360; distance = 360 - phi if phi > 180 else phi; return distance; assert f(5, 5) == 0
benchmark_functions_edited/f10287.py
def f(element, value, score): if element > value: return score assert f(1, 0, 1) == 1
benchmark_functions_edited/f3250.py
def f(value): if isinstance(value, float): return int(round(value)) return int(value) assert f(2.1) == 2
benchmark_functions_edited/f13213.py
def f(stream): count = 0 for c in stream: if c == '!': # escape, skip the next char next(stream) elif c == '>': return count else: count += 1 assert f(iter('>')) == 0
benchmark_functions_edited/f8624.py
def f(v): if v <= 0: return 0 if v >= 1: return 1 return v assert f(1.0) == 1
benchmark_functions_edited/f9806.py
def f(a: int, x: int, n: int) -> int: if x == 0: return 1 elif x == 1: return a % n elif x % 2 == 1: return (a * f(a, x - 1, n)) % n else: return (f(a, x >> 1, n) ** 2) % n assert f(2, 5, 2) == 0
benchmark_functions_edited/f7664.py
def f(x1: float, x2: float, y1: float, y2: float, x: float): return ((y2 - y1) * x + x2 * y1 - x1 * y2) / (x2 - x1) if (x2-x1)>0 else y1 #print(val) #print("---") #return val assert f(0, 1, 0, 0, 1.5) == 0
benchmark_functions_edited/f783.py
def f(x, y): while y: x, y = y, x % y return x assert f(3, 2) == 1
benchmark_functions_edited/f911.py
def f(n: int) -> int: if n <= 1: return 1 return n * f(n - 1) assert f(0) == 1
benchmark_functions_edited/f3481.py
def f(room): for i, pod in enumerate(room): if pod: return i return len(room) assert f(tuple([1])) == 0
benchmark_functions_edited/f2415.py
def f(id_, dim): row = id_ // (dim ** 3) col = (id_ % (dim ** 2)) // dim return row * dim + col assert f(8, 3) == 2
benchmark_functions_edited/f5126.py
def f(array, number): count = 0 for entry in array: if entry == number: count += 1 return count assert f(list(range(10)), -1) == 0
benchmark_functions_edited/f5052.py
def f(a: int, b: int) -> int: while b: a, b = b, a % b return a assert f(-5, 3) == 1
benchmark_functions_edited/f7836.py
def f(time): # offset = time & 0xFFF cycle1 = (time >> 12) & 0x1FFF cycle2 = (time >> 25) & 0x7F seconds = cycle2 + cycle1 / 8000. return seconds assert f(0x0000000000000000) == 0
benchmark_functions_edited/f4194.py
def f(wave_spectral_density, gravity, density): return wave_spectral_density * gravity * density assert f(2, 1, 1) == 2
benchmark_functions_edited/f4370.py
def f(word, values): return sum([values[x] for x in word]) assert f( 'aaaaa', {'a': 1} ) == 5
benchmark_functions_edited/f5877.py
def f(filename="", text=""): with open(filename, "a", encoding="utf-8") as f: return f.write(text) assert f("test1.txt", "abc") == 3
benchmark_functions_edited/f8212.py
def f(a, b, c): diff1 = abs(a - b) diff2 = abs(b - c) diff3 = abs(a - c) return min(diff1, diff2, diff3) assert f(0, 0, 0) == 0
benchmark_functions_edited/f11444.py
def f(digit1, digit2): e24_digit2 = digit2 if (digit1 == 2 and digit2 == 6 or digit1 == 3 or digit1 == 4): e24_digit2 += 1 elif digit1 == 8: e24_digit2 -= 1 return e24_digit2 assert f(1, 2) == 2
benchmark_functions_edited/f9111.py
def f(s1, s2, ch): # f('Yellow', 'Blue', 'u') return (s1 + s2).count(ch) assert f(*('red', 'blue', 'u')) == 1
benchmark_functions_edited/f8975.py
def f(obj, name, converter, default=None): try: result = converter(obj[name]) except Exception: return default if result <= 0: return default return result assert f( {"a": "value", "b": "value"}, "a", lambda x: len(x), ) == 5
benchmark_functions_edited/f9892.py
def f(min_v, max_v, value): return min_v if value < min_v else max_v if value > max_v else value assert f(-100, 100, 0) == 0
benchmark_functions_edited/f10432.py
def f(a, b): # pragma: no cover if a is None and b is None: return 0 elif a is None: return -1 elif b is None: return 1 return (a > b) - (a < b) assert f([1], []) == 1
benchmark_functions_edited/f11373.py
def f(value): integer = int(value) if integer < 0: raise ValueError("'%s' is not a positive integer" % value) return integer assert f(5) == 5
benchmark_functions_edited/f14282.py
def f(x: int, y: int) -> int: assert x != 0 and y != 0 and type(x) == int and type(y) == int, "Non-zero integers only." if x < 0: x *= -1 if y < 0: y *= -1 # Euclid's algorithm # assign the larger number to x, so can do larger % smaller if y > x: x, y = y, x remainder = x % y if not remainder: return y return f(y, remainder) assert f(-10, -3) == 1
benchmark_functions_edited/f1262.py
def f(a, prime): return pow(a, prime - 2, prime) assert f(15, 17) == 8
benchmark_functions_edited/f11401.py
def f(guess, computer, turns): if (guess > computer): print("Thinking lower number") return turns - 1 elif (guess < computer): print("Thinking higher number") return turns - 1 else: print("You got the correct number") assert f(2, 3, 2) == 1
benchmark_functions_edited/f2850.py
def f(n): i = 0 j = 1 n = n - 1 while n >= 0: i, j = j, i + j n = n - 1 return i assert f(0) == 0
benchmark_functions_edited/f1569.py
def f(data): sizes = [len(seq) for seq in data] return max(sizes) assert f([['a', 'a', 'a'], ['b', 'b', 'b', 'b']]) == 4
benchmark_functions_edited/f9017.py
def f(palos): palo_carta_1 = palos[0] # Primer palo for palo in palos: if palo_carta_1 != palo: return 0 return 1 assert f( ['Spades', 'Clubs', 'Spades', 'Spades', 'Spades']) == 0
benchmark_functions_edited/f931.py
def f(X, Y): return ((X)+(2.0*Y)-7.0)**2+((2.0*X)+(Y)-5.0)**2 assert f(1.0, 3.0) == 0
benchmark_functions_edited/f8821.py
def f(a, b, c): if a >= b: if b >= c: return b elif c >= a: return a else: return c elif a > c: return a elif b > c: return c else: return b assert f(4, 5, 3) == 4
benchmark_functions_edited/f7255.py
def f(input_value, num_bits=8): mask = 2**(num_bits - 1) return ((input_value & mask) - (input_value & ~mask)) & ((2 ** num_bits) - 1) assert f(0, 8) == 0
benchmark_functions_edited/f10386.py
def f(energy_gev, k0, index, E0=1.0): return k0 * (energy_gev/E0)**(-index) assert f(1, 1, -1) == 1
benchmark_functions_edited/f240.py
def f(it): return next(iter(it)) assert f([1, 2, 3]) == 1
benchmark_functions_edited/f13661.py
def f(x): if x < 0: raise ValueError("Cannot be a negative integer") if x == 0: return 0 bcdstring = '' while x > 0: nibble = x % 16 bcdstring = str(nibble) + bcdstring x >>= 4 return int(bcdstring) assert f(1) == 1
benchmark_functions_edited/f7993.py
def f(modifier: int, number: int) -> int: return number + int(modifier) assert f(-1, 9) == 8
benchmark_functions_edited/f13680.py
def f(right_word, guess_word): if len(right_word) > len(guess_word): smaller = guess_word else: smaller = right_word ratio = 0 for i in range(len(smaller)): if right_word[i] == guess_word[i]: ratio = ratio + 1 diff = abs(len(right_word) - len(guess_word)) ratio = (ratio - diff) / len(right_word) return ratio assert f( 'hello', 'hello') == 1
benchmark_functions_edited/f2863.py
def f(p0, p1, p2, t): return p1 + (1-t)**2*(p0-p1) + t**2*(p2-p1) assert f(1, 2, 3, 0.5) == 2
benchmark_functions_edited/f287.py
def f(i): return (i + 1) % 3 assert f(1) == 2
benchmark_functions_edited/f14524.py
def f(fn, *args, **kwargs): try: result = fn(*args, **kwargs) # Keyboard interrupts should stop server except KeyboardInterrupt: raise # Notify user that error occurred except Exception as err: logging.error(f'{err}\n{"".join(traceback.format_stack()[:-1])}') print(f'Function {fn.__name__}: {err.__class__} - {err}') result = None return result assert f(lambda x: x, 1) == 1
benchmark_functions_edited/f8070.py
def f(n: int, base_multiplier: int = 16) -> int: remainder = n % base_multiplier if remainder == 0: return n else: return n + base_multiplier - remainder assert f(7, 4) == 8
benchmark_functions_edited/f10163.py
def f(vals, delta_val=False): fastep = (1.47906994e-3 * vals + 3.5723322e-8 * vals**2 + -1.08492544e-12 * vals**3 + 3.9803832e-17 * vals**4 + 5.29336e-21 * vals**5 + 1.020064e-25 * vals**6) return fastep assert f(0) == 0
benchmark_functions_edited/f10360.py
def f(n): "*** YOUR CODE HERE ***" if n is 1: return 1 elif n is 0: return 0 else: return f(n - 1) + f(n - 2) assert f(2) == 1
benchmark_functions_edited/f4453.py
def f(ent, attr_dict, dataset): if ent not in attr_dict: return 0 return len(attr_dict[ent]) assert f( 'b', {'a': {'b', 'c', 'd'}, 'b': {'d'}}, 'dataset') == 1
benchmark_functions_edited/f7612.py
def f(mu, rho): nu = mu / rho return nu assert f(1, 1) == 1
benchmark_functions_edited/f2560.py
def f(x): n = 0 while x > 0: x >>= 1 n += 1 return n assert f(0b00010000) == 5
benchmark_functions_edited/f2308.py
def f(ua,ub,uc): uavg = (ua + ub + uc)/3 return (max(ua,ub,uc) - min(ua,ub,uc))/uavg assert f(1, 1, 1) == 0
benchmark_functions_edited/f3804.py
def f(rows): return (rows - rows % -20) / 20 assert f(105) == 6
benchmark_functions_edited/f3701.py
def f(n: int) -> int: return f"{n:b}".count("1") assert f(6) == 2
benchmark_functions_edited/f4780.py
def f(value): # pragma: no cover for i in range(0, 64): if value == 0: return i value >>= 1 assert f(2) == 2
benchmark_functions_edited/f4949.py
def f(value): return value + 6 * (value // 10) assert f(5) == 5
benchmark_functions_edited/f3402.py
def f(_value, _error): if _value not in [None, '']: return _value else: raise Exception(_error) assert f(1, 'error') == 1