file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f8854.py
def f(total_candies): print("Splitting", total_candies, "candies") return total_candies % 3 assert f(91) == 1
benchmark_functions_edited/f10674.py
def f(data, index): result = data[index] if result > 127: result -= 256 return result assert f(list(range(256)), 1) == 1
benchmark_functions_edited/f9958.py
def f(s): ba = 1 n = len(s) i = 0 t = 4 while i < n: if t < ba: return -1 if s[i] == "W": t = t + ba ba = 1 else: t = t - ba ba = 2*ba i+=1 return t assert f( "WWWW" ) == 8
benchmark_functions_edited/f13117.py
def f(n, k, d={}): if k == 0: return 1 if n == 0: return 0 try: return d[n, k] except KeyError: res = f(n-1, k) + f(n-1, k-1) d[n, k] = res return res assert f(4, 4) == 1
benchmark_functions_edited/f5841.py
def f(data): maxdata = max(data) if maxdata < (1 << 8): return 1 if maxdata < (1 << 16): return 2 return 4 assert f(range(2)) == 1
benchmark_functions_edited/f3012.py
def f(arr): if len(arr) == 0: return 0 else: return arr[0] + f(arr[1:]) assert f([]) == 0
benchmark_functions_edited/f8922.py
def f(codon, seq): i = 0 # Scan sequenece until we hit a start codon or the end of sequence while seq[i:i+3] != codon and i < len(seq): i += 3 if i == len(seq): return -1 return i assert f('ATG', 'ATGATG') == 0
benchmark_functions_edited/f5304.py
def f(prev, curr): return ((curr - prev) / prev * 100.0 if prev != 0 else float("inf") * abs(curr) / curr if curr != 0 else 0.0) assert f(10.0, 10.0) == 0
benchmark_functions_edited/f4721.py
def f(x,y): for index, item in enumerate(y): if x == item: return index return -1 assert f(1, [1, 1, 1, 1]) == 0
benchmark_functions_edited/f10559.py
def f(name, obj): q = [] q.append(obj) while q: obj = q.pop(0) if hasattr(obj, '__iter__'): isdict = type(obj) is dict if isdict and name in obj: return obj[name] for k in obj: q.append(obj[k] if isdict else k) else: return None assert f(1, {1: 2, 3: 4}) == 2
benchmark_functions_edited/f8470.py
def f( msg, start = 0 ): index = -1 if start < 0 or start >= len(msg): return index for prefix in ( "http://", "https://", "ftp://", "ftps://" ): index = msg.find( prefix, start ) if index > -1: break return index assert f( "ftps://google.com/foo" ) == 0
benchmark_functions_edited/f4429.py
def f(n): if n == 0: return 0 if n == 1: return 1 else: return n + f(n-1) assert f(3) == 6
benchmark_functions_edited/f12113.py
def f(query, sample, window_size): return 1 if abs((query - sample) / window_size) < .5 else 0 assert f(1.0, 1.0, 4.0) == 1
benchmark_functions_edited/f645.py
def f(arg1, arg2): ans = arg1 + arg2 return ans assert f(1, 2) == 3
benchmark_functions_edited/f13551.py
def f(*args): return next(filter(lambda x: x is not None, args), None) assert f(None, 2, True) == 2
benchmark_functions_edited/f1544.py
def f(wl, step, min_wl): return int((wl - min_wl) / step) assert f(425, 10, 400) == 2
benchmark_functions_edited/f8749.py
def f(buff, start, head): pos = buff[start:].find(head) if -1 == pos: return pos return pos + start assert f('1234567123', 0, '2') == 1
benchmark_functions_edited/f8618.py
def f(bools): # not using loops for optimized speed at this size return 4 * bools[0] + 2 * bools[1] + 1 * bools[2] assert f( [False, True, False] ) == 2
benchmark_functions_edited/f442.py
def f(x, y): return (x > y) - (x < y) assert f(0.2, 0.2) == 0
benchmark_functions_edited/f6686.py
def f(n: int) -> int: if n < 1: return 0 elif n == 1: return 1 else: prev = f(n // 2) return prev * 2 assert f(9) == 8
benchmark_functions_edited/f7091.py
def f(texto): return len(texto.split(sep=" ")) assert f("Hola") == 1
benchmark_functions_edited/f3945.py
def f(pct): return (1 - pct / 100.0) / (pct / 100.0) assert f(50) == 1
benchmark_functions_edited/f444.py
def f(ls): assert len(ls) == 1 return ls[0] assert f(list(range(1))) == 0
benchmark_functions_edited/f4215.py
def f(x): return 1 / (x ** 2 + 1) assert f(0) == 1
benchmark_functions_edited/f12411.py
def f(state): bit_sum = 0 for bit in state: if int(bit) not in [0,1]: raise ValueError('state {} not allowed'.format(state)) bit_sum += int(bit) parity = bit_sum % 2 return parity assert f('0') == 0
benchmark_functions_edited/f11185.py
def f(batch_size: int, num_devices: int): per_device_batch_size, ragged = divmod(batch_size, num_devices) if ragged: msg = 'batch size must be divisible by num devices, got {} and {}.' raise ValueError(msg.format(per_device_batch_size, num_devices)) return per_device_batch_size assert f(10, 10) == 1
benchmark_functions_edited/f2486.py
def f(tan: float) -> float: return (1 + tan) * (1 - tan) / (tan ** 2 + 1) assert f(-1) == 0
benchmark_functions_edited/f3906.py
def f(t): total = 0 for item in t: total += sum(item) return total assert f( [[]] ) == 0
benchmark_functions_edited/f8003.py
def f(s): if s=='None': s = None if s is None: return None try: return int(s) except ValueError: raise ValueError('Could not convert "%s" to int' % s) assert f(0) == 0
benchmark_functions_edited/f14389.py
def f(seq): from fractions import Fraction # sanity check assert seq # initialize the value to be returned by working backwards from the last number retval = Fraction(1, seq.pop()) # keep going backwords till the start of the sequence while seq: retval = 1 / (seq.pop() + retval) return retval assert f([1]) == 1
benchmark_functions_edited/f3959.py
def f(n, r, q): total = n for i in range(1, r): total = (total * n) % q return total assert f(0, 0, 1) == 0
benchmark_functions_edited/f14384.py
def f(message :str) -> int: if not message: return 1 # get every single position as one possible. num = f(message[1:]) # the possible 2 char branch adds one possiblility if len(message) >= 2 and int(message[:2]) <= 26: num += f(message[2:]) return num assert f( '1') == 1
benchmark_functions_edited/f3778.py
def f(flags): return (flags & 24) >> 3 assert f(0x02) == 0
benchmark_functions_edited/f5068.py
def f(data): n = len(data) if n < 1: raise ValueError('mean requires at least one data point') return sum(data)/float(n) assert f([1,2,3]) == 2
benchmark_functions_edited/f7563.py
def f(s, default_value=None): try: return int(s) if s is not None else default_value except ValueError: return default_value assert f('1') == 1
benchmark_functions_edited/f4292.py
def f(code): num = 0 for i, v in enumerate(reversed(code), 1): num *= i num += v return num assert f(list()) == 0
benchmark_functions_edited/f14056.py
def f(x): if x > 135: x = 135 if x < -135: x = -135 # y=30(x/135)^3 {-135 <= x <= 135} return 30/10*(x/135)**3 assert f(0) == 0
benchmark_functions_edited/f12153.py
def f(start, length, bits): newStart = start % bits newEnd = newStart + length totalWords = (newEnd-1) / bits return int(totalWords + 1) assert f(0, 4, 32) == 1
benchmark_functions_edited/f6008.py
def f(reward, gamma, alpha, oldQ, nextQ): newQ = oldQ + alpha * (reward + ((gamma*nextQ) - oldQ)) return newQ assert f(1, 1, 1, 1, 1) == 2
benchmark_functions_edited/f13353.py
def f(value, boundary=-1): if value - int(value) >= 0.5: if boundary == -1 or (int(value)+1) <= boundary: return int(value)+1 else: return boundary else: return int(value) assert f(3.1) == 3
benchmark_functions_edited/f9603.py
def f(a, b, u): return a + int((b - a + 1) * u) assert f(1, 100, 0) == 1
benchmark_functions_edited/f9110.py
def f(item, denom): try: return item / denom # only handle the ZeroDivisionError. except ZeroDivisionError: return 0 assert f(2, 0) == 0
benchmark_functions_edited/f9863.py
def f(true_positive, true_negative, false_positive, false_negative): if true_positive + true_negative == 0: return 0 return float(true_positive + true_negative) / \ float(true_positive + true_negative + false_positive + false_negative) assert f(1000000, 1000000, 0, 0) == 1
benchmark_functions_edited/f3332.py
def f(d,sigma): if 1==d%2: return 0 else: return sigma**d/(d+1.) assert f(9,1) == 0
benchmark_functions_edited/f6956.py
def f(symbol): if not symbol: return 0 for s in symbol: if not s.isalnum() and s != '_': return 0 return 1 assert f('a.1') == 0
benchmark_functions_edited/f11125.py
def f(n: str) -> int: conv_table = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} c = [conv_table[x] for x in n] return sum(-x if i < len(n) - 1 and x < c[i + 1] else x for i, x in enumerate(c)) assert f("I") == 1
benchmark_functions_edited/f14516.py
def f( benchmarks, field, func ): results = [] for benchmark in benchmarks: results.append( benchmark[ field ] ) return func( results ) assert f( [ {"A":3, "B":2}, {"A":2, "B":4}, {"A":1, "B":2} ], "A", sum ) == 6
benchmark_functions_edited/f4659.py
def f(text): vowels = ['a', 'e', 'i', 'o', 'u'] count = 0 for i in vowels: count += text.lower().count(i) return count assert f(u"aaa") == 3
benchmark_functions_edited/f3321.py
def f(f, b, a): return f(a, b) assert f(lambda x, y: x * y, 1, 2) == 2
benchmark_functions_edited/f11686.py
def f(midiValue, oscRange, midiRange): minOSC = oscRange[0] maxOSC = oscRange[1] minMidi = midiRange[0] maxMidi = midiRange[1] percent = (midiValue - minMidi ) / (maxMidi-minMidi) * 100.0 oscVal = (maxOSC - minOSC) * percent / 100 + minOSC return oscVal assert f(127, [0, 100], [127, 0]) == 0
benchmark_functions_edited/f11235.py
def f(value): if len(value)>1: raise IOError('NOT gate has received in input ' + str(len(value)) + ' values instead of 1.') if value[0]==0: outcome = 1 else: outcome = 0 return outcome assert f([0]) == 1
benchmark_functions_edited/f13855.py
def f(a,feature): if feature==int(1): if a<0: return int(0) elif a>10: return int(2) else: return int(1) elif feature==int(0): if a<0: return int(0) elif a>5: return int(2) else: return int(1) assert f(0, 0) == 1
benchmark_functions_edited/f3981.py
def f(linear_vel, turn_rad): if turn_rad != 0: return linear_vel / turn_rad else: return 0 assert f(0, 10) == 0
benchmark_functions_edited/f6914.py
def f(x): # pylint: disable=unused-argument return 0 assert f([0]) == 0
benchmark_functions_edited/f12539.py
def f(msg, ip=None, output=None, suppress=False): import time message = f"[{time.strftime('%Y/%m/%d %H:%M:%S')}] :: %s{msg}\n" % ( f"({ip}) " if ip != None else "") # Write to a file if filename is provided. if output: with open(output, "a+") as f: f.write(message) # Output to stdout if not suppressed. if not suppress: print(message, end="") return 0 assert f(f"hello, world") == 0
benchmark_functions_edited/f13852.py
def f(y): prev = 0 clusters = 0 for val in y: if val == 1 and prev == 0: clusters += 1 prev = val return clusters assert f(list([0, 0, 0, 1])) == 1
benchmark_functions_edited/f3821.py
def f(virtualset): if hasattr(virtualset, "card"): return virtualset.f() return len(virtualset) assert f(range(3)) == 3
benchmark_functions_edited/f4956.py
def f(day, number): day -= number if day < 0: day += 7 return day assert f(3, 7) == 3
benchmark_functions_edited/f6597.py
def f(transaction): depth = 0 current = transaction while current: depth += 1 current = transaction.parent return depth assert f(None) == 0
benchmark_functions_edited/f4251.py
def f(y1, y2): return (y2 + 3) / 4 - (y1 + 3) / 4 assert f(2014, 2014) == 0
benchmark_functions_edited/f11012.py
def f(command, res, **options): aggregate = options.get('aggregate', True) if not aggregate: return res numpat = 0 for node, node_numpat in res.items(): numpat += node_numpat return numpat assert f(None, {'a': 2, 'b': 3}) == 5
benchmark_functions_edited/f9438.py
def f(data): if not isinstance(data, bytearray): data = bytearray(data) # pragma: no cover r = 0 for ch in data: if r & 1: r |= 0x10000 r = ((r >> 1) + ch) & 0xffff return r assert f(b'\0\0\2') == 2
benchmark_functions_edited/f305.py
def f(x, y, z): return (x * y) ** z assert f(0, 0, 0) == 1
benchmark_functions_edited/f13637.py
def f(stage, direction): if direction == 0: return stage elif direction == 1: return (-stage[1], stage[0], stage[2], stage[3]) elif direction == 2: return (-stage[0], -stage[1], stage[2], stage[3]) elif direction == 3: return (stage[1], -stage[0], stage[2], stage[3]) assert f(2, 0) == 2
benchmark_functions_edited/f8399.py
def f(p, xs): for found in (x for x in reversed(xs) if p(x)): return found assert f(lambda x: x >= 3, [1, 2, 3, 3, 2, 1]) == 3
benchmark_functions_edited/f7931.py
def totalSolubleSolids (percentage_of_fat, density): total_soluble_solids = (1.2 * percentage_of_fat) + 2.665 * ((100 * density) - 100) return total_soluble_solids assert f(0, 1) == 0
benchmark_functions_edited/f11470.py
def f(result): max_run = 0 current_run = 0 for i in range(1, len(result)): if result[i] == result[i - 1]: current_run += 1 if current_run > max_run: max_run = current_run else: current_run = 0 return max_run assert f(list('1234567890')) == 0
benchmark_functions_edited/f8583.py
def f(response): try: return response["Response"]["View"][0]["Result"][0]["Relevance"] except: return 0 assert f({}) == 0
benchmark_functions_edited/f13722.py
def f(base,exponent,modulus): binaryExponent = [] while exponent != 0: binaryExponent.append(exponent%2) exponent = exponent//2 result = 1 binaryExponent.reverse() for i in binaryExponent: if i == 0: result = (result*result) % modulus else: result = (result*result*base) % modulus return result assert f(10, 1000, 3) == 1
benchmark_functions_edited/f8038.py
def f(sorted_values, all_matching_indices): for key, value in all_matching_indices.items(): if len(value) == 1: sorted_values[key] = value[0] return value[0] assert f( ['a', 'b', 'c'], {0: [0], 1: [1], 2: [2]} ) == 0
benchmark_functions_edited/f9105.py
def f(stack, needle): count = 0 for i in range(len(stack) - len(needle) + 1): if stack[i: i + len(needle)] == needle: count += 1 return count assert f(list('aaaa'), 'b') == 0
benchmark_functions_edited/f14477.py
def f(iterable, default=False, pred=None): # f([a,b,c], x) --> a or b or c or x # f([a,b], x, f) --> a if f(a) else b if f(b) else x return next(filter(pred, iterable), default) assert f(range(5, 10)) == 5
benchmark_functions_edited/f11503.py
def f(profileDict): assert isinstance(profileDict, dict) return profileDict["info"]["number_of_processes"] assert f( {"info": {"number_of_processes": 1}} ) == 1
benchmark_functions_edited/f3184.py
def f(colour:str) -> int: if colour in {'brown','blue'}: return 2 return 3 assert f('orange') == 3
benchmark_functions_edited/f550.py
def f(x, y): if x == y: return 1 return 0 assert f(3, 5) == 0
benchmark_functions_edited/f8250.py
def f(x): if x == 'Male': return 1 else: return 0 assert f({}) == 0
benchmark_functions_edited/f7619.py
def f(raw_table, base_index): raw_value = raw_table[base_index] if raw_value == 0xFFFF: return None sign = 1 if raw_value & 0x8000: sign = -1 return sign * (raw_value & 0x7FFF) / 10 assert f(b'\x00\x00', 0) == 0
benchmark_functions_edited/f11359.py
def contar_letras (cadena: str, letras: str): cuenta = 0 for caracter in cadena: if caracter == letras: cuenta += 1 return cuenta assert f( "hola a todos", "e" ) == 0
benchmark_functions_edited/f670.py
def f(token: str, txt: str)-> int: return txt.f(token) assert f('aaaaa', 'aaaaa') == 1
benchmark_functions_edited/f843.py
def f(x, N, ft_compensated=False): return x*0+1 assert f(-9, 1000) == 1
benchmark_functions_edited/f6777.py
def f(i,j,k): list=[1,2,3,4] list.remove(i) list.remove(j) list.remove(k) return list[0] assert f(2,1,4) == 3
benchmark_functions_edited/f6241.py
def f(B) -> float: B = float(B) KB = float(1024) MB = float(KB ** 2) # 1,048,576 return float("{0:.5f}".format(B / MB)) assert f(1024 ** 2) == 1
benchmark_functions_edited/f9309.py
def f(str1, str2): # From http://code.activestate.com/recipes/499304-hamming-distance/ diffs = 0 for ch1, ch2 in zip(str1, str2): if ch1 != ch2: diffs += 1 return diffs assert f(u'', u'') == 0
benchmark_functions_edited/f7440.py
def f(x,y): import numpy as np return np.argmin(abs(x-y)) assert f(1,1.2) == 0
benchmark_functions_edited/f9364.py
def f(y_offset, x_offset): return 3 * y_offset + x_offset assert f(0, 0) == 0
benchmark_functions_edited/f8180.py
def f(n: int, k: int) -> int: if k >= n or k == 0: return 1 return f(n - 1, k - 1) + f(n - 1, k) assert f(4, 3) == 4
benchmark_functions_edited/f5910.py
def f(str1, str2): diffs = 0 for ch1, ch2 in zip(str1, str2): if ch1 != ch2: diffs += 1 return diffs assert f( '1001001', '1001001') == 0
benchmark_functions_edited/f10407.py
def f(val: str): if val == 'very poor': return 1 if val == 'poor': return 2 if val == 'fair': return 3 if val == 'good': return 4 if val == 'very good': return 5 else: return -1 assert f('fair') == 3
benchmark_functions_edited/f9716.py
def f(value, name): # type: (str, str) -> int if isinstance(value, int): return value value = value fvalue = float(value) if not fvalue.is_f(): raise RuntimeError('%s=%r is not an integer' % (name, fvalue)) return int(fvalue) assert f(1, 'foo') == 1
benchmark_functions_edited/f12898.py
def f(s): if type(s) in (int, float): return s if s is None: return 0 base = 10 if isinstance(s, str): if "x" in s: base = 16 elif "b" in s: base = 2 try: return int(s, base) except ValueError: return 0 assert f(0b1) == 1
benchmark_functions_edited/f7997.py
def f(pop_input, variables_input, treatment_method_input): return treatment_method_input(pop_input, variables_input) assert f(3, 3, lambda pop, var: pop + var) == 6
benchmark_functions_edited/f4561.py
def f(to_convert): if isinstance(to_convert, str): return int(to_convert, 0) return int(to_convert) assert f("6") == 6
benchmark_functions_edited/f6464.py
def f(f_central): return 1 / f_central * 1000 assert f(1000) == 1
benchmark_functions_edited/f14243.py
def f(i, j, generation): living_neighbors = 0 # count for living neighbors neighbors = [(i-1, j), (i+1, j), (i, j-1), (i, j+1), (i-1, j+1), (i-1, j-1), (i+1, j+1), (i+1, j-1)] for k, l in neighbors: if 0 <= k < len(generation) and 0 <= l < len(generation[0]): if generation[k][l] == 1: living_neighbors += 1 return living_neighbors assert f(2, 2, [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]) == 8
benchmark_functions_edited/f13382.py
def f(obj, *keys): for key in keys: try: obj = obj[key] except KeyError: return None return obj assert f({'a': 1}, 'a') == 1
benchmark_functions_edited/f8988.py
def f(val, bits): if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255 val = val - (1 << bits) # compute negative value return val # return positive value as is assert f(3, 3) == 3
benchmark_functions_edited/f1862.py
def f(arr): return arr.min() if arr is not None and len(arr) > 0 else 0 assert f([]) == 0
benchmark_functions_edited/f4390.py
def f(word): if word[0] == '\x1b': return len(word) - 11 # 7 for color, 4 for no-color return len(word) assert f(u'abc') == 3
benchmark_functions_edited/f4427.py
def f(number): if number == 1: return 1 else: return number * f(number-1) assert f(1) == 1
benchmark_functions_edited/f97.py
def f(l): return sum(l) / len(l) assert f([0]) == 0