file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f1748.py
def f(a, b): return sum([ai*bi for (ai,bi) in zip(a,b)]) assert f( [1,0], [1,1] ) == 1
benchmark_functions_edited/f13524.py
def f(b1, b2): assert(len(b1) == len(b2)) hamming = 0 for i in range(len(b1)): if b1[i] != b2[i]: # differences at more significant (leftward) bits # are more important if i > 0: hamming += 1 + 1.0/i # This weighting is completely a...
benchmark_functions_edited/f5290.py
def f(x, s): for i, elem in enumerate(x): if elem.startswith(s): return i return -1 assert f(('foo',), 'foo') == 0
benchmark_functions_edited/f11510.py
def f(value): if not isinstance(value, (int, float)): raise TypeError("Kerning value must be a int or a float, not %s." % type(value).__name__) return value assert f(0.0) == 0
benchmark_functions_edited/f4779.py
def f(a,b): shortest = min(len(a), len(b)) return sum(a[i] != b[i] for i in range(shortest)) assert f("123456789", "123456789") == 0
benchmark_functions_edited/f3001.py
def f(x, r): return r * x - x / (1 + x**2) assert f(0, 2) == 0
benchmark_functions_edited/f3127.py
def f(signal, reference): return (signal - reference)/(signal + reference) assert f(0.5, 0.5) == 0
benchmark_functions_edited/f390.py
def f(a, b): return sum(abs(a1 - b1) for a1, b1 in zip(a, b)) assert f([1, 0], [0, 1]) == 2
benchmark_functions_edited/f10345.py
def f(tradeflow): if isinstance(tradeflow, str): if 'export' in tradeflow.lower(): tradeflow = 2 elif 'import' in tradeflow.lower(): tradeflow = 1 return tradeflow assert f('ImportS') == 1
benchmark_functions_edited/f13019.py
def f(meta_ext, meta_file, key): assert meta_file is not None if meta_ext is not None: ret = meta_ext.get(key, None) if ret is None: ret = meta_file.get(key) else: ret = meta_file.get(key, None) return ret assert f({'b': 2}, {'a': 3}, 'a') == 3
benchmark_functions_edited/f6163.py
def f(tree) -> int: if tree is None: return 1 return sum(f(subtree) for subtree in tree.subregions) assert f(None) == 1
benchmark_functions_edited/f13475.py
def f(x, *p): return p[0] + p[1]*x assert f(0, *([1, 2])) == 1
benchmark_functions_edited/f1230.py
def f(n): p= 1 for i in range(2, n+1): p *= i return p assert f(0) == 1
benchmark_functions_edited/f8174.py
def f(path, data): with open(path, 'ab') as handle: return handle.write(data) assert f('test', b'') == 0
benchmark_functions_edited/f9982.py
def f(i, j, k): test_set = set((i, j, k)) if not (test_set <= set((1, 2, 3)) or test_set <= set((0, 1, 2))): raise Exception("Unexpected input", i, j, k) return (i - j) * (j - k) * (k - i) / 2 assert f(3, 3, 3) == 0
benchmark_functions_edited/f9826.py
def f(items, m): cost = 0 weight = 0 for key, is_selected in items.items(): if is_selected: weight += key[1] cost += key[0] res = cost if weight <= m else 0 return res assert f(dict(), 2) == 0
benchmark_functions_edited/f8859.py
def f(val): if val is None: raise RuntimeError('Unexpected null value') return val assert f(1) == 1
benchmark_functions_edited/f12343.py
def f(first, second): matches = 0 for key in first: if key not in second: continue if first[key] == second[key]: matches += 1 return matches assert f( { 'a': 1, 'b': 2, 'c': 3 }, { 'a': 1, 'b': 3 } ) == 1
benchmark_functions_edited/f8438.py
def f(header_dict): for d in (header_dict["ObjectInfo"]["DataChain"]): if "Run Control" in d: return (d["Run Control"]["RunNumber"]) raise ValueError("No run number found in header!") assert f( { "ObjectInfo": { "DataChain": [ { "R...
benchmark_functions_edited/f5259.py
def f(str): delim=['-','_','?','=','&'] count=0 for i in str: for j in delim: if i==j: count+=1 return count assert f("foo&") == 1
benchmark_functions_edited/f12141.py
def f(n): res = n n_ = n # 2 if n_ & 1 == 0: res >>= 1 n_ >>= 1 while n_ & 1 == 0: n_ >>= 1 p = 3 while p <= n_: if n_ % p == 0: res = res * (p-1) / p n_ %= p while n_ and n_ % p == 0: n_ %= p p += 2 re...
benchmark_functions_edited/f13182.py
def f(data): # We're using this instead of zlib.adler32() because it's easier to confirm # that this matches the JavaScript version of the same function below. Also, # zlib.adler32() returns a signed result, and we want an unsigned result. a, b = 1, 0 for ch in map(ord, data): a = (a + ch) % 0xfff1 b...
benchmark_functions_edited/f3391.py
def f(l, m): return l ** 2 + (l + m) assert f(0, 1) == 1
benchmark_functions_edited/f1981.py
def f(x, a, b): return a * x + b assert f(1, 1, 1) == 2
benchmark_functions_edited/f2244.py
def f(dic, key): if key in dic: return dic[key] + 1 return 1 assert f({"a": 1}, "b") == 1
benchmark_functions_edited/f5288.py
def f(DeviceType, Function, Method, Access): return (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) assert f(0, 0, 0, 0) == 0
benchmark_functions_edited/f10660.py
def f(result): amount = 0 for k, values in result.items(): amount += len(values) return amount assert f({'key': ['val1', 'val2']}) == 2
benchmark_functions_edited/f6365.py
def f(i): if i == 0: return 0 if i == 1: return 1 return f(i - 1) + f(i - 2) assert f(5) == 5
benchmark_functions_edited/f9707.py
def f(filename): _, class_dir, _ = filename.split("/") return int(class_dir.split(".")[0]) assert f( "images/002.Laysan_Albatross/Laysan_Albatross_0004_2950165039.jpg") == 2
benchmark_functions_edited/f5774.py
def f(coord, coord_limit, m): coord = max(coord, m) coord = min(coord, coord_limit + m - 1) return coord assert f(2, 3, 2) == 2
benchmark_functions_edited/f788.py
def f(x, y): x = x + 1 y = y + 1 return y assert f(*[1, 2]) == 3
benchmark_functions_edited/f11288.py
def f(arr, key): n = len(arr) left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) if (arr[mid] <= key): count = mid + 1 left = mid + 1 else: right = mid - 1 return count assert f(sorted([1, 2, 2, 3, ...
benchmark_functions_edited/f12680.py
def f(temperature_in_f): temperature_in_c = 5/9*(temperature_in_f-32) print(temperature_in_c) return temperature_in_c assert f(32) == 0
benchmark_functions_edited/f6880.py
def f(noun): return (1 + noun) if isinstance(noun, int) else noun assert f(1) == 2
benchmark_functions_edited/f5917.py
def f(s : str) -> int: nb : int = 0 c : str for c in s: if c >= '0' and c <= '9': nb = nb + 1 return nb assert f( "345678901" ) == 9
benchmark_functions_edited/f10456.py
def f(n_workers: int, len_iterable: int, factor: int = 4): chunksize, extra = divmod(len_iterable, n_workers * factor) if extra: chunksize += 1 return chunksize assert f(2, 0) == 0
benchmark_functions_edited/f11244.py
def f(cand_d, ref_ds): count = 0 for m in list(cand_d.keys()): m_w = cand_d[m] m_max = 0 for ref in ref_ds: if m in ref: m_max = max(m_max, ref[m]) m_w = min(m_w, m_max) count += m_w return count assert f( {'f': 2, 'o': 2, 'x': 2, ...
benchmark_functions_edited/f12050.py
def f(outstanding_balance: float, interest_rate: float) -> float: return outstanding_balance * interest_rate / 12 assert f(200000, 0) == 0
benchmark_functions_edited/f13428.py
def f(value): if not value: return None # Apart from numbers also accept values that end with px if isinstance(value, str): value = value.strip(' px') try: return int(value) except (TypeError, ValueError): return None assert f(1.6) == 1
benchmark_functions_edited/f2810.py
def f(x1, y1, z1, x2, y2, z2): return (abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2)) // 2 assert f(-1, 0, 1, 0, 0, 0) == 1
benchmark_functions_edited/f11928.py
def f(array): #INEFFICIENT max_val = None max_index = None for i in range(len(array)): if array[i] == None: max_index=i return max_index else: if (max_val == None) or (array[i]>max_val): max_val = array[i] max_index...
benchmark_functions_edited/f12625.py
def f(value, polarity): return value if polarity != 0 else -value assert f(1, 2) == 1
benchmark_functions_edited/f13843.py
def f(xbarj,Nj,xbarm,Nm): xbarjp1 = (Nj*xbarj + Nm*xbarm)/(Nj+Nm) return xbarjp1 assert f(0,1,0,1) == 0
benchmark_functions_edited/f9407.py
def f(a): if isinstance(a, (int, float)): return a try: return int(a) except (ValueError, TypeError): try: return float(a) except (ValueError, TypeError): return float('nan') assert f(5) == 5
benchmark_functions_edited/f6479.py
def f(lines, lineix): while lineix < len(lines): if lines[lineix].strip().endswith('*/'): return lineix lineix += 1 return len(lines) assert f( [ ' /*', ' */', ' int x;', ], 1) == 1
benchmark_functions_edited/f10271.py
def f(parser, arg, minimum=0, maximum=100): if arg < minimum: parser.error("%s < %s", arg, minimum) else: if arg > maximum: parser.error("%s > %s", arg, maximum) return arg assert f(None, 0) == 0
benchmark_functions_edited/f1576.py
def f(line): return int(line[line.find('=') + 1:line.find(')')]) assert f(r'<tag1=1>') == 1
benchmark_functions_edited/f10946.py
def f(start_year, end_year, this_year, next_year, alpha): return ((1 - (0.5 ** ((next_year - start_year)/alpha))) - (1 - (0.5 ** ( (this_year - start_year)/alpha))))/(1 - (0.5 ** ( (end_year - start_year)/alpha))) assert f(2020, 2050, 2020, 2050, 5) == 1
benchmark_functions_edited/f14420.py
def f(annualPercent,currentBalance): annualPercent = float(annualPercent) #convert argument to float currentBalance = float(currentBalance) #convert argument to float annualPercent = annualPercent / 100 interestPaid = annualPercent / 12 * currentBalance return interestPaid assert f(0.0, 1000) == 0
benchmark_functions_edited/f12542.py
def f(n): # Edge case. if n == 1: return 1 n_odds = sum([i for i in range(1, n + 1)]) - n idx = 1 odd = 1 lst = [] while idx != n_odds: odd += 2 idx += 1 for j in range(1, n + 1): odd += 2 lst.append(odd) return sum(lst) assert f(2) == 8
benchmark_functions_edited/f2370.py
def f(bits): result = 0 for bit in bits: result = (result << 1) | bit return result assert f([]) == 0
benchmark_functions_edited/f9288.py
def f(cycle: int, days: int) -> int: if cycle >= days: return 1 if cycle == 0: return f(8, days - 1) + f(6, days - 1) return f(cycle - 1, days - 1) assert f(6, 4) == 1
benchmark_functions_edited/f14401.py
def f(item_list): print(f"List: {item_list}") count = 0 for item in item_list: if isinstance(item, list): print("Encountered sublist") count += f(item) else: print(f"Counted leaf item \"{item}\"") count += 1 print(f"-> Returning count {c...
benchmark_functions_edited/f6377.py
def f(times): return max(times) - min(times) assert f([1, 2, 3]) == 2
benchmark_functions_edited/f7376.py
def f(x0, x1, y0, y1): return (x1 - x0) ** 2 + (y1 - y0) ** 2 assert f(1, 1, 1, 1) == 0
benchmark_functions_edited/f8692.py
def f(value, bound1, bound2): if bound1 > bound2: return min(max(value, bound2), bound1) else: return min(max(value, bound1), bound2) assert f(3, 1, 2) == 2
benchmark_functions_edited/f4850.py
def f(m_e, hv, mfield): r = ((2 * m_e * hv) / mfield ** 2) ** 0.5 return r assert f(1, 0, 1) == 0
benchmark_functions_edited/f2057.py
def f(x): rev = 0 while x: rev <<= 1 rev += x & 1 x >>= 1 return rev assert f(0) == 0
benchmark_functions_edited/f4454.py
def f(a, b): if a is None: return b if b is None: return a return a + b assert f(0, 5) == 5
benchmark_functions_edited/f13792.py
def f(pixels): r = [p[0] for p in pixels] g = [p[1] for p in pixels] b = [p[2] for p in pixels] r_range = max(r) - min(r) g_range = max(g) - min(g) b_range = max(b) - min(b) ranges = [r_range, g_range, b_range] max_range = max(ranges) for i, m_range in enumerate(ranges): if m...
benchmark_functions_edited/f9672.py
def f(value): if value: return ((46.7 + value) / 28.7) else: return 0 assert f(0) == 0
benchmark_functions_edited/f13425.py
def f(p): denominator = 9 - 24 * max(p - 0.5, 0) if p < 0.5: return 15 * p / denominator else: return (6 + 3 * (1 - p) - (14 + 4 * (1 - p)) * max(p - 0.5, 0)) / denominator assert f(0) == 0
benchmark_functions_edited/f13864.py
def f(input_letter, num_teams): if len(input_letter) != 1 or type(input_letter) != str: raise ValueError('Try Again! Make sure to enter a one letter alphanumeric character') value = ord(input_letter) - ord('a') if value < 0 or value > num_teams - 1: raise ValueError('Try Again! Please enter ...
benchmark_functions_edited/f2622.py
def f(start, length, split): return start + split() * length assert f(1, 1, lambda: 1) == 2
benchmark_functions_edited/f1191.py
def f(byte): return round(((byte / 1000) / 1000),4) assert f(1000000) == 1
benchmark_functions_edited/f5098.py
def f(n: int) -> int: a = 0 b = 1 for _ in range(n): a, b = b, a + b return a assert f(0) == 0
benchmark_functions_edited/f10362.py
def f(underlying, strike, gearing=1.0): return gearing * max(underlying - strike, 0) assert f(100.0, 100.0, 1.0) == 0
benchmark_functions_edited/f1896.py
def f(i,j): if i==j: q = 1 else: q = 0 return q assert f(1,-1) == 0
benchmark_functions_edited/f77.py
def f(x, m, b): return m*x + b assert f(0, 1, 0) == 0
benchmark_functions_edited/f8883.py
def f(cost_of_living, affordability): if cost_of_living == affordability: return cost_of_living else: return ((cost_of_living - affordability) * 0.33) + affordability assert f(4, 4) == 4
benchmark_functions_edited/f10680.py
def f(components): return sum([component.molar_mass * component.volume_percentage * 0.01 for component in components]) assert f([]) == 0
benchmark_functions_edited/f13165.py
def f(image): gain = 1.0 # default # check if there's a header if hasattr(image,'meta'): if image.meta is not None: # Try all versions of gain for f in ['gain','egain','gaina']: hgain = image.meta.get(f) if hgain is not None: ...
benchmark_functions_edited/f1876.py
def f(lon): return (lon+180)%360-180 assert f(-360) == 0
benchmark_functions_edited/f11939.py
def f(tokens) -> int: # base case if type(tokens) == int: return tokens val = f(tokens[0]) op = "" for i, tok in enumerate(tokens[1:], 1): if i % 2: op = tok else: other = f(tok) val = eval(f"{val}{op}{other}") return val assert ...
benchmark_functions_edited/f1496.py
def f(paths): return sum(len(p)-1 for p in paths) assert f([[(20, 20), (100, 20), (20, 100)]]) == 2
benchmark_functions_edited/f1843.py
def f(lst): return lst.pop(lst.index(min(lst))) assert f( [2, 3, 1] ) == 1
benchmark_functions_edited/f1511.py
def f(depths): return sum([1 for x, y in zip(depths, depths[1:]) if y > x]) assert f([]) == 0
benchmark_functions_edited/f6937.py
def f(list1, list2): intersection = len(list(set(list1).intersection(list2))) union = (len(list1) + len(list2)) - intersection return float(intersection) / union assert f(set([1, 2, 3]), set([1, 2, 3])) == 1
benchmark_functions_edited/f10137.py
def f(J, s): assert len(J)==(len(s)*(len(s)-1)//2) e = 0 k = 0 for i in range(len(s)-1): for j in range(i+1,len(s)): if s[i]==s[j]: e += J[k] k += 1 return e assert f( [1,2,3], '010' ) == 2
benchmark_functions_edited/f11735.py
def f(gold, pred): fns = 0 for p in gold: fn = True for word in p: for span in pred: if word in span: fn = False if fn is True: fns += 1 return fns assert f( [['a', 'b']], [['a', 'b']] ) == 0
benchmark_functions_edited/f14095.py
def f(data): set_length = int(len(data) / 2) # All of the set values are inside square. r_square = 128 * 128 circle_surface = 0 for i in range(set_length): if ((data[i*2] - 128) ** 2 + (data[i*2+1] - 128) ** 2) <= r_square: circle_surface += 1 return 4 * circle_surface / set_le...
benchmark_functions_edited/f11308.py
def f(x: float, lmb: float) -> float: if x < lmb: return x + lmb elif x > lmb: return x - lmb else: return 0.0 assert f(1, 1) == 0
benchmark_functions_edited/f7831.py
def f(n, k): if 0 <= k <= n: ntok = 1 ktok = 1 for t in range(1, min(k, n - k) + 1): ntok *= n ktok *= t n -= 1 return ntok // ktok else: return 0 assert f(3, 2) == 3
benchmark_functions_edited/f12378.py
def f(a, b): def split_version(v): if '.' in v: return v.split('.', 1) if '_' in v: return v.split('_', 1) return (v, '0') a_maj, a_min = split_version(a) b_maj, b_min = split_version(b) if a_maj == b_maj: return f(a_min, b_min) return int(a_maj) > int(b_maj) assert f(u'1_2', u'1_...
benchmark_functions_edited/f10970.py
def f(x, a0, a1, a2, a3, a4, a5, a6, a7, a8): return ( a0 + a1 * x + a2 * (x ** 2) + a3 * (x ** 3) + a4 * (x ** 4) + a5 * (x ** 5) + a6 * (x ** 6) + a7 * (x ** 7) + a8 * (x ** 8) ) assert f(0, 0, 0, 0, 0...
benchmark_functions_edited/f11554.py
def f(im_name, parse_type='id'): assert parse_type in ('id', 'cam') if parse_type == 'id': parsed = -1 if im_name.startswith('-1') else int(im_name[:4]) else: parsed = int(im_name[4]) if im_name.startswith('-1') \ else int(im_name[6]) return parsed assert f( '0001_c1s1_0...
benchmark_functions_edited/f3.py
def f(x): return x*x*x assert f(2) == 8
benchmark_functions_edited/f7760.py
def f(text,separator=' '): return len(text.split(separator)) assert f(u'hi there! hi again!') == 4
benchmark_functions_edited/f5761.py
def f(character): if(character == ' '): return 0 elif(character == '+'): return 1 elif(character == '#'): return 2 assert f('#') == 2
benchmark_functions_edited/f4603.py
def f(value): try: value = int(value) return value except (ValueError, TypeError): return None assert f(0.9) == 0
benchmark_functions_edited/f14337.py
def f(W, vs, ws): value, weight = 0, 0 for i in range(1, pow(2, len(vs))): v, w = 0, 0 j, k = i, 0 while j: if j % 2: v += vs[k] w += ws[k] k += 1 j //= 2 if w > W: break if valu...
benchmark_functions_edited/f2627.py
def f(a, x, y): return (1 - a) * x + a * y assert f(1, 0, 1) == 1
benchmark_functions_edited/f13163.py
def f(s): if not s: return 0 # DP Solution dp = [0]*(len(s)+1) dp[0] = 1 dp[1] = 0 if s[0] == "0" else 1 for i in range(2, len(s) + 1): if 0 < int(s[i-1:i]) <= 9: dp[i] += dp[i - 1] if 10 <= int(s[i-2:i]) <= 26: dp[i] +=...
benchmark_functions_edited/f2182.py
def f(p1,p2): x1, y1 = p1 x2, y2 = p2 return (((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)))**0.5 assert f( (0,0), (-1,0) ) == 1
benchmark_functions_edited/f12568.py
def f(f, x, h=1e-10): f_prime = (f(x+h) - f(x)) / h return f_prime assert f(lambda x: x, 0) == 1
benchmark_functions_edited/f9550.py
def f(value, precisionBits): return value / (1 << precisionBits) assert f(0, 0) == 0
benchmark_functions_edited/f4838.py
def f(power_utilities): return sum([i.production for i in power_utilities]) / 1000 assert f([]) == 0
benchmark_functions_edited/f6249.py
def f(a, b): if not a or not b: return None return a + b assert f(1, 2) == 3
benchmark_functions_edited/f12071.py
def f(constant, iterations): n = 0 z = 0 for i in range(iterations): if abs(z) > 4: break z = z**2 + constant n += 1 return n assert f(0 - 2j, 100) == 2
benchmark_functions_edited/f9729.py
def f(v, divisor=8, min_value=None): min_value = min_value or divisor new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) # Make sure that round down does not go down by more than 10%. if new_v < 0.9 * v: new_v += divisor return new_v assert f(3, 3) == 3