file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f11055.py
def f(value, key): values = [r.get(key, 0) if hasattr(r, 'get') else getattr(r, key, 0) for r in value] return sum(values) assert f( [{'foo': 1, 'bar': 1}, {'foo': 2, 'bar': 2}, {'foo': 3, 'bar': 3}], 'foo' ) == 6
benchmark_functions_edited/f6030.py
def f(course, courses): for tri in courses: for _course in courses[tri]: if course == _course: return tri assert f(4, {0: [1, 2, 3], 1: [2, 3, 4]}) == 1
benchmark_functions_edited/f719.py
def f(v1, v2): return v1[0] * v2[1] - v1[1] * v2[0] assert f( (1, 0), (0, 1) ) == 1
benchmark_functions_edited/f13773.py
def f(n): try: has_non_numeric_message_keys = any(not ( connection_n.find('source_key').isdigit() and connection_n.find('sink_key').isdigit() ) for connection_n in n.find('flow_graph').findall('connection')) if has_non_numeric_message_keys: return 1 except: pass return 0 assert f('<flow_graph><connection source_key="1" sink_key="1"/></flow_graph>') == 0
benchmark_functions_edited/f9951.py
def intersect (sequence_a, sequence_b): try: for item in sequence_a: if item in sequence_b: return 1 except TypeError: return 0 return 0 assert f([1,2], [2,3]) == 1
benchmark_functions_edited/f12750.py
def f(series1, series2): assert len(series1) == len(series2) mse = 0.0 max_v = max(max(series1), max(series2)) s1 = tuple((value/max_v for value in series1)) s2 = tuple((value/max_v for value in series2)) for index, data1 in enumerate(s1): diff = (data1 - s2[index]) mse += diff * diff mse /= len(series1) return mse assert f( [0, 1, 2], [0, 1, 2] ) == 0
benchmark_functions_edited/f9985.py
def f(data, shift): return (data >> shift) & 1 assert f(0x00000001, 0) == 1
benchmark_functions_edited/f8402.py
def f(nums): nums = list(map(int, nums)) # Convert to a list of ints return sum(nums) assert f({1, 2, 3}) == 6
benchmark_functions_edited/f7504.py
def f(coord1, coord2): xd2 = (coord1[0]-coord2[0]) ** 2 yd2 = (coord1[1]-coord2[1]) ** 2 zd2 = (coord1[2]-coord2[2]) ** 2 return (xd2 + yd2 + zd2)**0.5 assert f( (0, 0, 0), (0, 0, 0) ) == 0
benchmark_functions_edited/f5123.py
def f(v: float) -> int: assert v % 1.0 == 0.0, f'expected int, got {v!r}' return int(v) assert f(5.0) == 5
benchmark_functions_edited/f8026.py
def f(is_match): if 45.0 <= is_match <= 55.0: return 1 elif 250.0 <= is_match <= 255.0: return 0 assert f(45.0) == 1
benchmark_functions_edited/f3363.py
def f(border, size): i = 1 while size - border // i <= border // i: i *= 2 return border // i assert f(1, 5) == 1
benchmark_functions_edited/f5748.py
def f(val, in_min, in_max, out_min, out_max): return out_min + (val - in_min) * ((out_max - out_min) / (in_max - in_min)) assert f(1, 0, 10, 0, 10) == 1
benchmark_functions_edited/f13817.py
def f(result): total = 0 for res in result: if all([bit == 1 for bit in res]): total += 1 return total / len(result) assert f([[1,0,0], [0,1,0], [1,0,0], [0,1,0], [1,0,0], [0,1,0], [1,0,0], [0,1,0]]) == 0
benchmark_functions_edited/f10392.py
def f(arg, v=False): if v: print("running") out = arg ** 2 return out assert f(-3) == 9
benchmark_functions_edited/f9886.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(1, 2, 3) == 2
benchmark_functions_edited/f6730.py
def f(boxId): if boxId >= 0: return boxId else: raise ValueError( '{} is not a valid Box Id, Box Id must be >= 0'.format(boxId)) assert f(0) == 0
benchmark_functions_edited/f14139.py
def f(class_predictions, LIST_c): false_positive_count = 0 for item in range(len(class_predictions)): if item in LIST_c: false_positive_count += class_predictions[item] # Return the false positive count return false_positive_count assert f( [0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0], [] ) == 0
benchmark_functions_edited/f2645.py
def f(x, y): while x % y != 0: x %= y (x, y) = (y, x) return y assert f(39, 12) == 3
benchmark_functions_edited/f1439.py
def f(num): return int(str(num)[::-1]) assert f(0) == 0
benchmark_functions_edited/f3832.py
def f(x): return x ** 2 assert f(3) == 9
benchmark_functions_edited/f4897.py
def f(x, a, b): cc = 0 return cc assert f( [1000, 1000, 1000, 1000, 1000, 1000], 1, 0) == 0
benchmark_functions_edited/f737.py
def f(p, r): return 2*p*r / (p+r) assert f(1, 1) == 1
benchmark_functions_edited/f9572.py
def f(lengths, fraction): lengths = sorted(lengths, reverse=True) tot_length = sum(lengths) cum_length = 0 for length in lengths: cum_length += length if cum_length >= fraction*tot_length: return length assert f([1, 2, 3], 0.2) == 3
benchmark_functions_edited/f12902.py
def f(poly, id): if id==len(poly)-1: return 1 elif id== len(poly)-2: return 0 else: return id+1 assert f( [(0,0),(1,1),(0,1)], 0) == 1
benchmark_functions_edited/f3975.py
def f(task): return task.count("(") - task.count(")") assert f(r'((()))') == 0
benchmark_functions_edited/f2987.py
def f(base): n = base return (2*n**3 + 3*n**2 + n)/6 assert f(0) == 0
benchmark_functions_edited/f4554.py
def f(val, default=None): return val if val is not None else default assert f(1, 1) == 1
benchmark_functions_edited/f11103.py
def f(d): #winter add to get automation flag "flag_green" if isinstance(d['makers'], list): if 'flag-green' in d['makers']: return 2 return 1 assert f( { 'name': 'topic1', 'makers': ['flag-green', 'flag-blue'] } ) == 2
benchmark_functions_edited/f11605.py
def f(a): result = 0 for number in a: result = result ^ number return result assert f([1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 9]) == 1
benchmark_functions_edited/f10766.py
def f(profit_loss): profit_loss_copy = profit_loss[:] average_ch = (profit_loss_copy[-1] - profit_loss_copy[0])/(len(profit_loss_copy)-1) return round(average_ch, 2) assert f([1, 3, 5, 7, 9]) == 2
benchmark_functions_edited/f215.py
def f(x): return 2*(x % 1 < .5) -1 assert f(1.1) == 1
benchmark_functions_edited/f2949.py
def f(secs): if secs: return float(secs) / 86400 else: return 0 assert f(None) == 0
benchmark_functions_edited/f8424.py
def f(bin_str: str): return int(bin_str, 2) assert f(bin(1)) == 1
benchmark_functions_edited/f8137.py
def f(num, length): sum_digits = sum([ int(digit) * (length + 1 - i) for i, digit in enumerate(str(num).zfill(length))]) checksum = (11 - (sum_digits % 11)) % 11 return checksum if checksum != 10 else None assert f(1, 9) == 9
benchmark_functions_edited/f6737.py
def f(iterable, *default): return next(iter(iterable), *default) assert f(iter(range(1))) == 0
benchmark_functions_edited/f1093.py
def f(a: int, n: int) -> int: return (n - a) % n assert f(2, 2) == 0
benchmark_functions_edited/f3872.py
def f(a : int, b : int, c : int, d : int, x : int) -> int: return (((((a*x + b) * x) + c) * x) + d) assert f(0, 0, 0, 1, 1) == 1
benchmark_functions_edited/f1612.py
def f(chunk_size): return chunk_size or 5 * 1024 * 1024 assert f(2) == 2
benchmark_functions_edited/f5676.py
def f(a, b): if len(a) == len(b): return 0 elif len(a) < len(b): return 1 else: return -1 assert f( 'dog', 'apple' ) == 1
benchmark_functions_edited/f6146.py
def f(i, n): return ((1 + i) ** n - 1) / i assert f(1, 1) == 1
benchmark_functions_edited/f12407.py
def f(F1, F2): a = F1 * F2 b = (1 - F1) / 3 c = (1 - F2) / 3 return (a + b * c) / (a + F1 * c + F2 * b + 5 * b * c) assert f(1, 0) == 0
benchmark_functions_edited/f4273.py
def f(x1, y1, z1, x2, y2, z2): return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2) assert f(1, 2, 3, 1, 2, 3) == 0
benchmark_functions_edited/f10278.py
def f(X, Y): size = len(X) total = 0 for i in range(size): total += X[i] * Y[i] #print X[i], Y[i] #print total return total assert f( (1, 2, 3), (0, 0, 0) ) == 0
benchmark_functions_edited/f7368.py
def f(list_of_nums): total = 0 ### Set a breakpoint here! ### for num in list_of_nums: total += num average = total / len(list_of_nums) return average assert f( [1, 2, 3, 4, 5]) == 3
benchmark_functions_edited/f7575.py
def f(pixel_volume, resolution_lateral_um, resolution_axial_um): return pixel_volume * (resolution_lateral_um ** 2) * resolution_axial_um assert f(0, 0.3, 0.3) == 0
benchmark_functions_edited/f1557.py
def f(edge): if edge[2] < len(edge[4]): return True return False assert f( ("A", "B", 5, [1,1,1,1,1,1,1,1,1,1,1], [], [1,1,1,1,1,1,1,1,1,1,1]) ) == 0
benchmark_functions_edited/f608.py
def f(List, i): i = i / 3 return List[int(i)] assert f(range(0, 20), 6) == 2
benchmark_functions_edited/f6656.py
def f(dictionary: dict) -> int: indexes = list(dictionary) return indexes[-1] if indexes else -1 assert f({0: 1, 1: 2, 2: 3}) == 2
benchmark_functions_edited/f12523.py
def f(nucleotide1, nucleotide2, phyche_index): temp_sum = 0.0 phyche_index_values = list(phyche_index.values()) len_phyche_index = len(phyche_index_values[0]) for u in range(len_phyche_index): temp_sum += pow(float(phyche_index[nucleotide1][u]) - float(phyche_index[nucleotide2][u]), 2) return temp_sum / len_phyche_index assert f(0, 0, {0: [1, 2, 3], 1: [1, 2, 3]}) == 0
benchmark_functions_edited/f10274.py
def f(q, dist): min_node = None for node in q: if min_node == None: min_node = node elif dist[node] < dist[min_node]: min_node = node return min_node assert f({1: 1}, {1: 0}) == 1
benchmark_functions_edited/f1116.py
def f(n): l = 0 while n > 1: n = n >> 1 l = l + 1 return l assert f(32) == 5
benchmark_functions_edited/f11534.py
def f(x, y, max_iters): c = complex(x, y) z = 0.0j for i in range(max_iters): z = z*z + c if (z.real*z.real + z.imag*z.imag) >= 4: return i return max_iters assert f(-2, 0, 10) == 0
benchmark_functions_edited/f4271.py
def f(x, y): ret = 0 while x or y: ret += (x & 1) * (y & 1) x >>= 1 y >>= 1 return bool(ret % 2) assert f(2, 5) == 0
benchmark_functions_edited/f10394.py
def f(d_age): if -1 < d_age < 7: return 6 elif d_age < 14: return 12 elif d_age < 21: return 18 elif d_age < 25: return 24 else: return 24 assert f(4) == 6
benchmark_functions_edited/f1426.py
def f(value, inMin, inMax): return min(inMax, max(inMin, value)) assert f(8, 1, 10) == 8
benchmark_functions_edited/f9881.py
def f(f, x0, t0, t1): # time step delta_t = t1 - t0 # slope s1 = f(t0, x0) # next step x1 = x0 + s1 * delta_t return x1 assert f(lambda t, x: 0, 0, 1, 2) == 0
benchmark_functions_edited/f14136.py
def f(data): crc = 0 for byte in data: crc ^= (ord(byte) << 8) for _ in range(8): if crc & 0x8000: crc ^= (0x1070 << 3) crc <<= 1 return crc >> 8 assert f(b'') == 0
benchmark_functions_edited/f388.py
def f(string): return int(string, 2) assert f(bin(6)) == 6
benchmark_functions_edited/f9821.py
def f(order_list, period): indices = [i for i, order in enumerate(order_list) if order.sent] sum = 0 for i in indices: if period - (i + order_list[i].lead_time + 1) == 0: sum += order_list[i].quantity return sum assert f( [], 1) == 0
benchmark_functions_edited/f2976.py
def f(nums) -> int: # print(list(set(nums))) return len(set(nums)) assert f(list()) == 0
benchmark_functions_edited/f10326.py
def f(public_key): subject_number = 7 value = 1 loop_size = 0 while value != public_key: value *= subject_number value %= 20201227 loop_size += 1 return loop_size assert f(5764801) == 8
benchmark_functions_edited/f543.py
def f(v): return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] assert f( (-1, -1, -1) ) == 3
benchmark_functions_edited/f10790.py
def f(t1: int, t2: int, time_max: int): if not (isinstance(t1, int) and isinstance(t1, int)): raise TypeError(f"t1={t1} and t2={t2} must be ints") i = (t1 - t2) % time_max j = (t2 - t1) % time_max if j > i: return -i return j assert f(0, 0, 5) == 0
benchmark_functions_edited/f4985.py
def f(area: float, mm_per_pixel: float): return area * (mm_per_pixel ** 2) assert f(1, 1) == 1
benchmark_functions_edited/f9946.py
def f(n): r = 0 if not n >= 0: raise ValueError("array_size must be >= 0") while n >= 64: r |= n & 1 n >>= 1 return n + r assert f(2) == 2
benchmark_functions_edited/f2940.py
def f(int_type, offset): mask = ~(1 << offset) return int_type & mask assert f(1, 3) == 1
benchmark_functions_edited/f3419.py
def f(base, deft): if base == 0.0: return base return base or deft assert f(1, 0) == 1
benchmark_functions_edited/f14150.py
def f(value, name, values=None): if value not in values: raise ValueError('%s, %r must be in %s' % (name, value, values)) return value assert f(2, 'enum', (1, 2, 3)) == 2
benchmark_functions_edited/f5909.py
def f(chemin, distance): s = 0 nb = len(chemin) for i in range(0, nb): s += distance(chemin[i], chemin[(i + 1) % nb]) return s assert f( [("a", "b"), ("b", "c"), ("c", "a")], lambda a, b: 1, ) == 3
benchmark_functions_edited/f3296.py
def f(one, two, three): pays = (one,two, three,) return max(pays) - min(pays) assert f(10, 1, 1) == 9
benchmark_functions_edited/f14060.py
def f(data): if len(data) == 0: return None data = sorted(data) return float((data[len(data) // 2] + data[(len(data) - 1) // 2]) / 2.) assert f(sorted([1, 3, 5, 7, 9])) == 5
benchmark_functions_edited/f2344.py
def f(T, pmax, wm): if wm <= pmax / T: return T return pmax / wm assert f(1000, 1000, 1000) == 1
benchmark_functions_edited/f13102.py
def f(t, v): _valid_type = ['int', 'float', 'long', 'complex', 'str'] if t not in _valid_type: raise RuntimeError( '[-] unsupported type: ' f'must be one of: {",".join([i for i in _valid_type])}') try: return type(eval("{}()".format(t)))(v) # nosec except ValueError: raise ValueError(f'type={t}, value="{v}"') assert f('int', '7') == 7
benchmark_functions_edited/f13693.py
def f(fs_info): if not fs_info: return 0 blk_cnt = int(fs_info['block count']) free_blk_cnt = int(fs_info['free blocks']) blk_size = int(fs_info['block size']) return (blk_cnt - free_blk_cnt) * blk_size assert f({'block count': 1, 'free blocks': 0, 'block size': 1}) == 1
benchmark_functions_edited/f3134.py
def f(obj, name): if isinstance(obj, dict): return obj.get(name) return getattr(obj, name, obj) assert f({'1': 1}, '1') == 1
benchmark_functions_edited/f87.py
def f(num): return int((num / 640) * 9) assert f(100) == 1
benchmark_functions_edited/f13020.py
def f(color_dict, colors): for i, color in enumerate(colors): for data in color: equal = True for k, v in data.items(): if k not in color_dict or v != color_dict[k]: equal = False break if equal: return i return -1 assert f(dict(), [(dict(), 0), (dict(), 1), (dict(), 2), (dict(), 3), (dict(), 4)]) == 0
benchmark_functions_edited/f2576.py
def f(ti, tiplus, riprime, ri, riplus): return (tiplus - ti) * riprime - (riplus - ri) assert f(0, 1, 0, 0, 0) == 0
benchmark_functions_edited/f12124.py
def f(index: int, boundary: int) -> int: if index < 0: index += boundary elif index >= boundary: index -= boundary return index assert f(6, 10) == 6
benchmark_functions_edited/f4140.py
def f(instance, args=()): try: code = instance(*args) except Exception: code = None return code assert f(lambda: 3) == 3
benchmark_functions_edited/f621.py
def f(a, b): return a*b - b*a assert f(-1, 0) == 0
benchmark_functions_edited/f2974.py
def f(iterable, pred=bool): return sum(1 for item in iterable if pred(item)) assert f(range(4), lambda x: x % 2 == 0) == 2
benchmark_functions_edited/f12449.py
def f(n,k): if n < k: raise Exception("n cannot be less than k") if k < 0: raise Exception("k must be nonnegative") # Calculate the numerator and denominator seperately in order to avoid loss # of precision for large numbers. N = 1 D = 1 for i in range(1,k+1): N *= (n+1-i) D *= i return N//D assert f(4,1) == 4
benchmark_functions_edited/f14078.py
def f(str_lengths:list): try: return int(round(sum(str_lengths)/len(str_lengths))) except Exception as ex: template = "An exception of type {0} occurred in [ContentSupport.CalculateMeanValue]. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) print(message) assert f( [5, 6, 8, 10]) == 7
benchmark_functions_edited/f7445.py
def f(adict, off): algn = 1 for ii in range(0, 5): mask = 1 << ii if off & mask: break algn *= 2 if algn in adict: adict[algn] += 1 else: adict[algn] = 1 return algn assert f(dict(), 4) == 4
benchmark_functions_edited/f2031.py
def f(a, b): return abs(a[0] - b[0]) + abs(a[1] - b[1]) assert f( (1, 1), (0, 0) ) == 2
benchmark_functions_edited/f11135.py
def f(string): count = 0 for char in string: if char == '0' or char == '1' or char == '2' or char == '3' or char == '4' or \ char == '5' or char == '6' or char == '7' or char == '8' or char == '9': count += 1 return count assert f( '9' ) == 1
benchmark_functions_edited/f3799.py
def f(*args): args = [x for x in args if x > -1] if args: return min(args) else: return -1 assert f(0) == 0
benchmark_functions_edited/f2120.py
def f(a, b) : return (a + b + abs(a - b)) / 2 assert f(-1, 2) == 2
benchmark_functions_edited/f311.py
def f(n): return int(str(n) + str(n)[::-1]) assert f(0) == 0
benchmark_functions_edited/f7478.py
def f(target): if target.startswith("http"): return int(requests.get(target, stream=True) .headers["Content-Length"]) else: return 0 assert f("a-file") == 0
benchmark_functions_edited/f2325.py
def f(price, face_value, years_to_maturity, coupon=0): return (face_value / price) ** (1 / years_to_maturity) - 1 assert f(100, 100, -5, 10) == 0
benchmark_functions_edited/f7354.py
def f(a): if not isinstance(a, list): raise TypeError('Function f() takes a list, not a %s' % a.__class__) if len(a) > 0: return float(sum(a) / len(a)) else: return 0.0 assert f([0, 0, 0]) == 0
benchmark_functions_edited/f7851.py
def f(x): from random import random return random() * x assert f(0.0) == 0
benchmark_functions_edited/f1774.py
def f(file_name: str) -> int: return int(file_name[5:]) assert f('shard9') == 9
benchmark_functions_edited/f2287.py
def f(data): return min(data[0][0], data[1][0], data[2][0], data[3][0]) assert f([(0, 0), (3, 0), (3, 1), (0, 1)]) == 0
benchmark_functions_edited/f5627.py
def f(num): if num == 0: return 1 return num * f(num - 1) assert f(2) == 2
benchmark_functions_edited/f14024.py
def f(value: str) -> int: length = len(value) if length not in (2, 3, 4, 7): raise ValueError("Value can only be identified if it's length is 2, 3, 4 or 7") elif length == 2: return 1 elif length == 3: return 7 elif length == 4: return 4 else: return 8 assert f('ab') == 1
benchmark_functions_edited/f2890.py
def f(x, z, limit): if x != 0: return min(z / x, limit) else: return limit assert f(100, 0, 100) == 0